Skip to content

Commit 8077f3d

Browse files
ianhikmuehlbauer
andauthored
Fix source linking for tagged docs (#11187)
* fix source linking for tagged docs * add a whatsnew * fix whatsnew * move source ref detection outside of function * Update doc/whats-new.rst Co-authored-by: Kai Mühlbauer <kmuehlbauer@wradlib.org> --------- Co-authored-by: Kai Mühlbauer <kmuehlbauer@wradlib.org>
1 parent d20fdb0 commit 8077f3d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

doc/conf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@
338338
"xarray-lmfit": ("https://xarray-lmfit.readthedocs.io/stable", None),
339339
}
340340

341+
# Resolve the git ref once at import time, not per-object.
342+
tag = subprocess.getoutput("git describe --tags --exact-match HEAD")
343+
source_ref = tag if tag.startswith("v") else "main"
344+
345+
341346
# based on numpy doc/source/conf.py
342347
def linkcode_resolve(domain, info):
343348
"""
@@ -379,13 +384,7 @@ def linkcode_resolve(domain, info):
379384

380385
fn = os.path.relpath(fn, start=os.path.dirname(xarray.__file__))
381386

382-
if "+" in xarray.__version__:
383-
return f"https://github.com/pydata/xarray/blob/main/xarray/{fn}{linespec}"
384-
else:
385-
return (
386-
f"https://github.com/pydata/xarray/blob/"
387-
f"v{xarray.__version__}/xarray/{fn}{linespec}"
388-
)
387+
return f"https://github.com/pydata/xarray/blob/{source_ref}/xarray/{fn}{linespec}"
389388

390389

391390
def html_page_context(app, pagename, templatename, context, doctree):

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Deprecations
3535
Bug Fixes
3636
~~~~~~~~~
3737

38+
- Fix ``Source`` link in api docs (:pull:`11187`)
39+
By `Ian Hunt-Isaak <https://github.com/ianhi>`_
3840
- Coerce masked dask arrays to filled (:issue:`9374` :pull:`11157`).
3941
By `Julia Signell <https://github.com/jsignell>`_
4042

0 commit comments

Comments
 (0)