Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Deprecations
Bug Fixes
~~~~~~~~~

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

Expand Down