Skip to content

Commit

Permalink
ADD: Add version switcher to navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrover1 committed Jan 4, 2024
1 parent 2d4eb10 commit b444857
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
11 changes: 5 additions & 6 deletions cmweather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/source/_static/pst-versions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"version": "dev",
"url": "https://cmweather.readthedocs.io/en/"
"url": "https://cmweather.readthedocs.io/en/dev"
},
{
"version": "latest",
Expand Down
20 changes: 14 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import datetime
import os
import re
import sys

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -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<full>(?P<base>\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.
Expand Down Expand Up @@ -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 = []
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@
zip_safe=False,
use_scm_version={
'version_scheme': 'post-release',
'local_scheme': 'dirty-tag',
},
)

0 comments on commit b444857

Please sign in to comment.