From 8ec462e16eb0a98855f103c28fb9027c6689afb8 Mon Sep 17 00:00:00 2001 From: mgrover1 Date: Thu, 4 Jan 2024 14:38:08 -0600 Subject: [PATCH 1/3] ADD: Add version switcher file --- docs/source/_static/pst-versions.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docs/source/_static/pst-versions.json diff --git a/docs/source/_static/pst-versions.json b/docs/source/_static/pst-versions.json new file mode 100644 index 0000000..69def11 --- /dev/null +++ b/docs/source/_static/pst-versions.json @@ -0,0 +1,11 @@ +[ + { + "version": "dev", + "url": "https://cmweather.readthedocs.io/en/" + }, + { + "version": "latest", + "url": "https://cmweather.readthedocs.io/en/latest/", + "is_latest": true + } +] From 8e8d1e3373da3ac76bd9fd1a75539d91f05a8a2a Mon Sep 17 00:00:00 2001 From: mgrover1 Date: Thu, 4 Jan 2024 15:17:39 -0600 Subject: [PATCH 2/3] ADD: add version switcher --- docs/source/conf.py | 11 ++++++++++- setup.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index bc27f2a..b922983 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -96,6 +96,9 @@ # The full version, including alpha/beta/rc tags. release = cmweather.__version__ +if '+' in version: + version += 'dev' + # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # language = None @@ -143,7 +146,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 = { + '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}', + } +} +print('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..ed63443 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, From b44485799bd9edbe09fc74fbec8fea3ed5ca87fa Mon Sep 17 00:00:00 2001 From: mgrover1 Date: Thu, 4 Jan 2024 15:29:13 -0600 Subject: [PATCH 3/3] ADD: Add version switcher to navbar --- cmweather/__init__.py | 11 +++++------ docs/source/_static/pst-versions.json | 2 +- docs/source/conf.py | 20 ++++++++++++++------ setup.py | 1 - 4 files changed, 20 insertions(+), 14 deletions(-) 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 index 69def11..74b3a4b 100644 --- a/docs/source/_static/pst-versions.json +++ b/docs/source/_static/pst-versions.json @@ -1,7 +1,7 @@ [ { "version": "dev", - "url": "https://cmweather.readthedocs.io/en/" + "url": "https://cmweather.readthedocs.io/en/dev" }, { "version": "latest", diff --git a/docs/source/conf.py b/docs/source/conf.py index b922983..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,12 +93,19 @@ # built documents. # # The short X.Y version. -version = cmweather.__version__.split('+')[0] -# The full version, including alpha/beta/rc tags. -release = cmweather.__version__ +# 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() -if '+' in version: +# The short X.Y version. +version = parsed_version['base'] +if '+' in verinfo: version += 'dev' +# The full version, including alpha/beta/rc tags. +release = parsed_version['full'] # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -147,12 +155,12 @@ # further. For a list of options available for each theme, see the # documentation. 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}', - } + }, } -print('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 ed63443..1248efb 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,5 @@ zip_safe=False, use_scm_version={ 'version_scheme': 'post-release', - 'local_scheme': 'dirty-tag', }, )