Skip to content

Commit

Permalink
Merge pull request #60 from cisagov/resolve_manual_check_disables
Browse files Browse the repository at this point in the history
Remove or Explain Manual Testing Check Disables
  • Loading branch information
mcdonnnj authored Nov 18, 2020
2 parents a8bdbe5 + 0747d20 commit b32bb9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 19 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"""

# Standard Python Libraries
import codecs
from glob import glob
from os.path import basename, splitext
from os.path import abspath, basename, dirname, join, splitext

# Third-Party Libraries
from setuptools import find_packages, setup
Expand All @@ -22,18 +23,28 @@ def readme():
return f.read()


def package_vars(version_file):
"""Read in and return the variables defined by the version_file."""
pkg_vars = {}
with open(version_file) as f:
exec(f.read(), pkg_vars) # nosec
return pkg_vars
# Below two methods were pulled from:
# https://packaging.python.org/guides/single-sourcing-package-version/
def read(rel_path):
"""Open a file for reading from a given relative path."""
here = abspath(dirname(__file__))
with codecs.open(join(here, rel_path), "r") as fp:
return fp.read()


def get_version(version_file):
"""Extract a version number from the given file path."""
for line in read(version_file).splitlines():
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
raise RuntimeError("Unable to find version string.")


setup(
name="example",
# Versions should comply with PEP440
version=package_vars("src/example/_version.py")["__version__"],
version=get_version("src/example/_version.py"),
description="Example python library",
long_description=readme(),
long_description_content_type="text/markdown",
Expand Down
4 changes: 4 additions & 0 deletions src/example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""The example library."""
# We disable a Flake8 check for "Module imported but unused (F401)" here because
# although this import is not directly used, it populates the value
# package_name.__version__, which is used to get version information about this
# Python package.
from ._version import __version__ # noqa: F401
from .example import example_div

Expand Down

0 comments on commit b32bb9a

Please sign in to comment.