From bf8d79aa083efa2f6662c471c7e8ef971e5ac69c Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Fri, 20 Feb 2026 11:28:57 -0500 Subject: [PATCH 1/5] fix source linking for tagged docs --- doc/conf.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 7199299b12c..ba8b48d1241 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -382,10 +382,9 @@ def linkcode_resolve(domain, info): 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}" - ) + tag = subprocess.getoutput("git describe --tags --exact-match HEAD") + ref = tag if tag.startswith("v") else f"v{xarray.__version__}" + return f"https://github.com/pydata/xarray/blob/{ref}/xarray/{fn}{linespec}" def html_page_context(app, pagename, templatename, context, doctree): From f64f07202c485b58c8ad88dd4c01e8370e6acf05 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Fri, 20 Feb 2026 11:42:50 -0500 Subject: [PATCH 2/5] add a whatsnew --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index f4d9819588e..72a1e927070 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 `_ From b6050459c3c750bb49001e058dc307c3b3374ef1 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Mon, 23 Feb 2026 11:52:58 -0500 Subject: [PATCH 3/5] fix whatsnew --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 72a1e927070..e97ad0fb147 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -36,7 +36,7 @@ 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 `_ From 70240a9862e5d861c199b2af4660d90213c58ed2 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Mon, 23 Feb 2026 11:56:47 -0500 Subject: [PATCH 4/5] move source ref detection outside of function --- doc/conf.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index ba8b48d1241..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,12 +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: - tag = subprocess.getoutput("git describe --tags --exact-match HEAD") - ref = tag if tag.startswith("v") else f"v{xarray.__version__}" - return f"https://github.com/pydata/xarray/blob/{ref}/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): From 7f54d1827a9a4ad346242aca27e174b924622243 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Mon, 23 Feb 2026 12:41:46 -0500 Subject: [PATCH 5/5] Update doc/whats-new.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kai Mühlbauer --- doc/whats-new.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index f1453cd7927..2a754dade21 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -35,7 +35,7 @@ Deprecations Bug Fixes ~~~~~~~~~ -- Fix ``Source`` link in api docs (:pull:`11187`)` +- 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 `_