diff --git a/setup.cfg b/setup.cfg old mode 100644 new mode 100755 index bd1e94f..0733f52 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,5 @@ [metadata] name = pEp -#TODO: automate version pull from hg/git -version = 2.2.0-RC1 url = https://pep.foundation download_url = ext_package = pEp @@ -33,11 +31,14 @@ python_requires = >= 3.6 test_suite = tests setup_requires = setuptools >=38.3.0 -install_requires = - setuptools >=38.3.0 -tests_require = + # To automatically write the version from a SCM. + # Note: It fails with tags named as `Release_2.2.0-RC0`, because it is + # not conforming to semantic versioning, but it succeed with tags as + # `2.2.0-rc0`. + setuptools_scm +[options.extras_require] +# To install these dependencies, run pip install .[test] +test = pytest tox - -[options.extras_require] doc = sphinx diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 1d563c5..7884d27 --- a/setup.py +++ b/setup.py @@ -223,4 +223,7 @@ setup( cmdclass={ 'build_ext': BuildExtCommand, }, + # While not using a pyproject.toml, support setuptools_scm setup.cfg usage, + # see https://github.com/pypa/setuptools_scm/#setupcfg-usage + use_scm_version=True, ) diff --git a/src/pEp/__init__.py b/src/pEp/__init__.py old mode 100644 new mode 100755 index 0bc2c9e..ab29698 --- a/src/pEp/__init__.py +++ b/src/pEp/__init__.py @@ -2,7 +2,7 @@ # This file is being exectued upon 'import pEp' # # __all__ could be used to limit the symbols exported when using from import * - +from pkg_resources import DistributionNotFound, get_distribution # Import all symbols EXCEPT the ones beginning with underscore into the current namespace from native_pEp import * @@ -11,6 +11,10 @@ from native_pEp import * # import the module import native_pEp +try: + __version__ = get_distribution(__name__).version +except DistributionNotFound: + print("Package is not installed.") # Executed on module import def init(): diff --git a/tests/test_pep.py b/tests/test_pep.py new file mode 100755 index 0000000..3e63973 --- /dev/null +++ b/tests/test_pep.py @@ -0,0 +1,11 @@ +"""Unit test for pEp package, not for subpackages or modules.""" + +from pEp import __version__ + + +def test_pep_version(): + """ Test that __version__ is not None or empty and is not 0.0.0.""" + # We could also test that match the regex, but that is already a test in + # setuptools_scm itself. + assert __version__ + assert __version__ != "0.0.0"