Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96fa195

Browse files
committed
Fix links to doc sources
Instead of figuring out a regex ourselves, just use `packaging` to determine the version. And point to `master` branch if not on an actual tag. Fixes #21230
1 parent d1a4a11 commit 96fa195

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

doc/conf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ def setup(app):
582582
# You can add build old with link_github = False
583583

584584
if link_github:
585-
import re
586585
import inspect
586+
from packaging.version import parse
587587

588588
extensions.append('sphinx.ext.linkcode')
589589

@@ -634,10 +634,9 @@ def linkcode_resolve(domain, info):
634634
if not fn.startswith(('matplotlib/', 'mpl_toolkits/')):
635635
return None
636636

637-
m = re.match(r'^.*post[0-9]+\+\w([a-z0-9]+).\w+$',
638-
matplotlib.__version__)
639-
version = m.group(1) if m else f'v{matplotlib.__version__}'
637+
version = parse(matplotlib.__version__)
638+
tag = 'master' if version.is_devrelease else f'v{version.base_version}'
640639
return ("https://github.com/matplotlib/matplotlib/blob"
641-
f"/{version}/lib/{fn}{linespec}")
640+
f"/{tag}/lib/{fn}{linespec}")
642641
else:
643642
extensions.append('sphinx.ext.viewcode')

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies:
2727
- ipython
2828
- ipywidgets
2929
- numpydoc>=0.8
30+
- packaging
3031
- pydata-sphinx-theme
3132
- scipy
3233
- sphinx>=1.8.1,!=2.0.0

requirements/doc/doc-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ colorspacious
1212
ipython
1313
ipywidgets
1414
numpydoc>=0.8
15+
packaging>=20
1516
pydata-sphinx-theme>=0.6.0
1617
sphinxcontrib-svg2pdfconverter>=1.1.0
1718
# sphinx-gallery>=0.7

0 commit comments

Comments
 (0)