-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add version switcher to discretize docs #371
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ | ||
{ | ||
"version": "main", | ||
"url": "https://discretize.simpeg.xyz/en/main/" | ||
}, | ||
{ | ||
"name": "0.10.0 (latest)", | ||
"version": "v0.10.0", | ||
"url": "https://discretize.simpeg.xyz/en/v0.10.0/", | ||
"preferred": true | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ | |||||
import sys | ||||||
from pathlib import Path | ||||||
from datetime import datetime | ||||||
from packaging.version import parse | ||||||
import discretize | ||||||
from sphinx_gallery.sorting import FileNameSortKey | ||||||
import shutil | ||||||
|
@@ -94,8 +95,16 @@ | |||||
# | ||||||
# The full version, including alpha/beta/rc tags. | ||||||
release = version("discretize") | ||||||
discretize_version = parse(release) | ||||||
|
||||||
# The short X.Y version. | ||||||
version = discretize_version.public | ||||||
if discretize_version.is_devrelease: | ||||||
branch = "main" | ||||||
else: | ||||||
branch = f"v{version}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also remove the leading
Suggested change
|
||||||
# The short X.Y version. | ||||||
version = ".".join(release.split(".")[:2]) | ||||||
# version = ".".join(release.split(".")[:2]) | ||||||
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation | ||||||
# for a list of supported languages. | ||||||
|
@@ -144,7 +153,6 @@ | |||||
|
||||||
if link_github: | ||||||
import inspect | ||||||
from packaging.version import parse | ||||||
|
||||||
extensions.append("sphinx.ext.linkcode") | ||||||
|
||||||
|
@@ -197,16 +205,7 @@ def linkcode_resolve(domain, info): | |||||
fn = os.path.relpath(fn, start=os.path.dirname(discretize.__file__)) | ||||||
except ValueError: | ||||||
return None | ||||||
|
||||||
discretize_version = parse(discretize.__version__) | ||||||
tag = ( | ||||||
"main" | ||||||
if discretize_version.is_devrelease | ||||||
else f"v{discretize_version.public}" | ||||||
) | ||||||
return ( | ||||||
f"https://github.com/simpeg/discretize/blob/{tag}/discretize/{fn}{linespec}" | ||||||
) | ||||||
return f"https://github.com/simpeg/discretize/blob/{branch}/discretize/{fn}{linespec}" | ||||||
|
||||||
else: | ||||||
extensions.append("sphinx.ext.viewcode") | ||||||
|
@@ -246,6 +245,7 @@ def linkcode_resolve(domain, info): | |||||
dict(name="Contact", url="https://mattermost.softwareunderground.org/simpeg"), | ||||||
] | ||||||
|
||||||
|
||||||
# Use Pydata Sphinx theme | ||||||
html_theme = "pydata_sphinx_theme" | ||||||
|
||||||
|
@@ -279,7 +279,13 @@ def linkcode_resolve(domain, info): | |||||
"use_edit_page_button": False, | ||||||
"collapse_navigation": True, | ||||||
"navbar_align": "left", # make elements closer to logo on the left | ||||||
"navbar_end": ["theme-switcher", "navbar-icon-links"], | ||||||
"navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"], | ||||||
# Configure version switcher (remember to add it to the "navbar_end") | ||||||
"switcher": { | ||||||
"version_match": branch, | ||||||
"json_url": "https://discretize.simpeg.xyz/en/latest/_static/versions.json", | ||||||
}, | ||||||
"show_version_warning_banner": True, | ||||||
} | ||||||
|
||||||
html_logo = "images/discretize-logo.png" | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the
version
field should not have the leadingv
because these versions should be parsable by the compare-versions node module (https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/announcements.html#version-warning-banners).This way, the warning version banners can behave properly. If we have the
v
, any previous version is recognized as a development version, so the banner shows the wrong text.We can still use the leading
v
in the url though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compare_versions
ignores any leadingv
https://www.npmjs.com/package/compare-versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually experienced a misbehaviour in the version banner in simpeg before I changed the versions to not have a leading
v
. But yes, you're right that they seem to support it...Ignore this then and we'll see if it works well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the pydata sphinx theme uses the leading
v
in their's for matching, https://github.com/pydata/pydata-sphinx-theme/blob/main/docs/_static/switcher.jsonThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe there was something else that was failing back then... Well, I'm glad we don't have to fix it.