From 8077f3d41b6152a86b07d4263aaca3ef6b0cd15d Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Mon, 23 Feb 2026 15:09:08 -0500 Subject: [PATCH] Fix source linking for tagged docs (#11187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --------- Co-authored-by: Kai Mühlbauer --- doc/conf.py | 13 ++++++------- doc/whats-new.rst | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 7199299b12c..c80b4e458b6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -338,6 +338,11 @@ "xarray-lmfit": ("https://xarray-lmfit.readthedocs.io/stable", None), } +# Resolve the git ref once at import time, not per-object. +tag = subprocess.getoutput("git describe --tags --exact-match HEAD") +source_ref = tag if tag.startswith("v") else "main" + + # based on numpy doc/source/conf.py def linkcode_resolve(domain, info): """ @@ -379,13 +384,7 @@ def linkcode_resolve(domain, info): fn = os.path.relpath(fn, start=os.path.dirname(xarray.__file__)) - if "+" in xarray.__version__: - return f"https://github.com/pydata/xarray/blob/main/xarray/{fn}{linespec}" - else: - return ( - f"https://github.com/pydata/xarray/blob/" - f"v{xarray.__version__}/xarray/{fn}{linespec}" - ) + return f"https://github.com/pydata/xarray/blob/{source_ref}/xarray/{fn}{linespec}" def html_page_context(app, pagename, templatename, context, doctree): diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 8108163e958..2a754dade21 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,6 +35,8 @@ Deprecations Bug Fixes ~~~~~~~~~ +- Fix ``Source`` link in api docs (:pull:`11187`) + By `Ian Hunt-Isaak `_ - Coerce masked dask arrays to filled (:issue:`9374` :pull:`11157`). By `Julia Signell `_