Skip to content

Commit 45aab42

Browse files
authored
fix Edit on GitHub (#4460)
* try to point sphinx_rtd_theme to the correct url * register the jinja filter using the setup function * fix the template * use scanpydoc instead of a copy * fix the use of scanpydoc * escape underscores in github urls * don't override conf_py_path, RTD correctly detects that
1 parent 333e8db commit 45aab42

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

ci/requirements/doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ dependencies:
2828
- zarr>=2.4
2929
- pip
3030
- pip:
31+
- scanpydoc
3132
# relative to this file. Needs to be editable to be accepted.
3233
- -e ../..

doc/_templates/autosummary/base.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:github_url: {{ fullname | github_url | escape_underscores }}
2+
3+
{% extends "!autosummary/base.rst" %}

doc/conf.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
import datetime
1616
import os
17+
import pathlib
1718
import subprocess
1819
import sys
1920
from contextlib import suppress
2021

2122
import sphinx_autosummary_accessors
23+
from jinja2.defaults import DEFAULT_FILTERS
2224

2325
import xarray
2426

@@ -78,6 +80,7 @@
7880
"IPython.sphinxext.ipython_console_highlighting",
7981
"nbsphinx",
8082
"sphinx_autosummary_accessors",
83+
"scanpydoc.rtd_github_links",
8184
]
8285

8386
extlinks = {
@@ -97,6 +100,15 @@
97100
"""
98101

99102
autosummary_generate = True
103+
104+
# for scanpydoc's jinja filter
105+
project_dir = pathlib.Path(__file__).parent.parent
106+
html_context = {
107+
"github_user": "pydata",
108+
"github_repo": "xarray",
109+
"github_version": "master",
110+
}
111+
100112
autodoc_typehints = "none"
101113

102114
napoleon_use_param = False
@@ -404,3 +416,11 @@
404416
"dask": ("https://docs.dask.org/en/latest", None),
405417
"cftime": ("https://unidata.github.io/cftime", None),
406418
}
419+
420+
421+
def escape_underscores(string):
422+
return string.replace("_", r"\_")
423+
424+
425+
def setup(app):
426+
DEFAULT_FILTERS["escape_underscores"] = escape_underscores

0 commit comments

Comments
 (0)