diff --git a/cmweather/__init__.py b/cmweather/__init__.py index 992601d..02d6b09 100644 --- a/cmweather/__init__.py +++ b/cmweather/__init__.py @@ -59,12 +59,11 @@ * plasmidis """ -from pkg_resources import DistributionNotFound, get_distribution - +from importlib.metadata import version, PackageNotFoundError from . import cm, cm_colorblind # noqa -# Get the version try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover - __version__ = '0.0.0' # pragma: no cover + __version__ = version('cmweather') +except PackageNotFoundError: + # package is not installed + pass diff --git a/docs/source/_static/pst-versions.json b/docs/source/_static/pst-versions.json new file mode 100644 index 0000000..74b3a4b --- /dev/null +++ b/docs/source/_static/pst-versions.json @@ -0,0 +1,11 @@ +[ + { + "version": "dev", + "url": "https://cmweather.readthedocs.io/en/dev" + }, + { + "version": "latest", + "url": "https://cmweather.readthedocs.io/en/latest/", + "is_latest": true + } +] diff --git a/docs/source/conf.py b/docs/source/conf.py index bc27f2a..bdf3ef7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -12,6 +12,7 @@ import datetime import os +import re import sys # If extensions (or modules to document with autodoc) are in another directory, @@ -92,9 +93,19 @@ # built documents. # # The short X.Y version. -version = cmweather.__version__.split('+')[0] +# 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. +# +verinfo = cmweather.__version__ +parsed_version = re.search(r'(?P(?P\d+\.\d+)\.?\w*)', verinfo).groupdict() + +# The short X.Y version. +version = parsed_version['base'] +if '+' in verinfo: + version += 'dev' # The full version, including alpha/beta/rc tags. -release = cmweather.__version__ +release = parsed_version['full'] # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -143,7 +154,13 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -# html_theme_options = {} +html_theme_options = { + 'navbar_start': ['navbar-logo', 'version-switcher'], + 'switcher': { + 'json_url': 'https://raw.githubusercontent.com/mgrover1/cmweather/add-version-switcher/docs/source/_static/pst-versions.json', + 'version_match': 'dev' if 'dev' in version else f'v{version}', + }, +} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] diff --git a/setup.py b/setup.py index 01b2047..1248efb 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ ], description='A library of useful colormaps when visualizing weather and climate data, with numerous color vision deficiency friendly options', install_requires=requirements, - setup_requires='setuptools_scm', + setup_requires=['setuptools', 'wheel', 'setuptools_scm'], license='MIT license', long_description=long_description, include_package_data=True, @@ -44,6 +44,5 @@ zip_safe=False, use_scm_version={ 'version_scheme': 'post-release', - 'local_scheme': 'dirty-tag', }, )