Skip to content

Commit

Permalink
Use setuptools' pkg_resources for extracting setuptools_scm version info
Browse files Browse the repository at this point in the history
As works both in pkg's init.py and in Sphinx config.
  • Loading branch information
willfurnass committed Mar 18, 2020
1 parent 5fd9eac commit 275c1c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))


Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions mumot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 275c1c4

Please sign in to comment.