From 275c1c4af05e4f2dd422c0530b608940fd7e4e3d Mon Sep 17 00:00:00 2001 From: Will Furnass Date: Wed, 18 Mar 2020 13:00:17 +0000 Subject: [PATCH] Use setuptools' pkg_resources for extracting setuptools_scm version info As works both in pkg's init.py and in Sphinx config. --- docs/source/conf.py | 11 +++++------ mumot/__init__.py | 8 ++++---- setup.cfg | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 30584f7..a76a788 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,7 +19,7 @@ # import os import sys -sys.path.insert(0, os.path.abspath('../..')) +#sys.path.insert(0, os.path.abspath('../..')) #sys.path.insert(0, os.path.abspath('../../mumot')) @@ -65,12 +65,11 @@ # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. -# -# The short X.Y version. import mumot -version = mumot.__version__ -# The full version, including alpha/beta/rc tags. -release = mumot.__version__ +from pkg_resources import get_distribution +release = get_distribution('mumot').version +# for example take major/minor +version = '.'.join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/mumot/__init__.py b/mumot/__init__.py index 5dd8749..7dbadb8 100644 --- a/mumot/__init__.py +++ b/mumot/__init__.py @@ -33,11 +33,11 @@ # Set package version. # NB with Python 3.8 we could use importlib.metadata (in std lib) instead. -from importlib_metadata import version, PackageNotFoundError +from pkg_resources import get_distribution, DistributionNotFound try: - __version__ = version(__name__) -except PackageNotFoundError: - # package is not installed + __version__ = get_distribution(__name__).version +except DistributionNotFound: + # package is not installed pass # Import the functions and classes we wish to export i.e. the public API diff --git a/setup.cfg b/setup.cfg index d888b86..df25219 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,7 @@ packages = find: install_requires = antlr4-python3-runtime >=4.7,<4.8 graphviz - importlib_metadata # needed with Python <3.8 for finding pkg version at runtime (with 3.8 can use importlib.metadata) + setuptools # used with Python <3.8 for finding pkg version at runtime (with 3.8 could use importlib.metadata) ipykernel <4.7 # needed so no duplicate figures when wiggle ipywidgets ipython ipywidgets