Skip to content

Commit 066e0fd

Browse files
authored
Try to fix code links in docs xarray-contrib/datatree#183
* try to fix code links in docs * add currentmodule datatree command to get links to api docs working * add some intersphinx links to xarray API * whatsnew
1 parent d715f12 commit 066e0fd

11 files changed

+36
-7
lines changed

ci/doc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dependencies:
1111
- sphinx-panels
1212
- sphinx-autosummary-accessors
1313
- sphinx-book-theme >= 0.0.38
14+
- nbsphinx
15+
- sphinxcontrib-srclinks
1416
- pydata-sphinx-theme>=0.4.3
1517
- numpydoc
1618
- ipython

docs/source/conf.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# All configuration values have a default; values that are commented out
1414
# serve to show the default.
1515

16+
import inspect
1617
import os
1718
import sys
1819

@@ -41,6 +42,7 @@
4142
"numpydoc",
4243
"sphinx.ext.autodoc",
4344
"sphinx.ext.viewcode",
45+
"sphinx.ext.linkcode",
4446
"sphinx.ext.autosummary",
4547
"sphinx.ext.intersphinx",
4648
"sphinx.ext.extlinks",
@@ -50,6 +52,8 @@
5052
"sphinx_autosummary_accessors",
5153
"IPython.sphinxext.ipython_console_highlighting",
5254
"IPython.sphinxext.ipython_directive",
55+
"nbsphinx",
56+
"sphinxcontrib.srclinks",
5357
]
5458

5559
extlinks = {
@@ -76,6 +80,11 @@
7680
copyright = "2021 onwards, Tom Nicholas and its Contributors"
7781
author = "Tom Nicholas"
7882

83+
html_show_sourcelink = True
84+
srclink_project = "https://github.com/xarray-contrib/datatree"
85+
srclink_branch = "main"
86+
srclink_src_path = "docs/source"
87+
7988
# The version info for the project you're documenting, acts as replacement for
8089
# |version| and |release|, also used in various other places throughout the
8190
# built documents.
@@ -127,6 +136,7 @@
127136

128137
intersphinx_mapping = {
129138
"python": ("https://docs.python.org/3.8/", None),
139+
"numpy": ("https://numpy.org/doc/stable", None),
130140
"xarray": ("https://xarray.pydata.org/en/stable/", None),
131141
}
132142

@@ -142,7 +152,7 @@
142152
html_theme_options = {
143153
"repository_url": "https://github.com/xarray-contrib/datatree",
144154
"repository_branch": "main",
145-
"path_to_docs": "doc",
155+
"path_to_docs": "docs/source",
146156
"use_repository_button": True,
147157
"use_issues_button": True,
148158
"use_edit_page_button": True,
@@ -334,12 +344,12 @@ def linkcode_resolve(domain, info):
334344
else:
335345
linespec = ""
336346

337-
fn = os.path.relpath(fn, start=os.path.dirname(xarray.__file__))
347+
fn = os.path.relpath(fn, start=os.path.dirname(datatree.__file__))
338348

339-
if "+" in xarray.__version__:
349+
if "+" in datatree.__version__:
340350
return f"https://github.com/xarray-contrib/datatree/blob/main/datatree/{fn}{linespec}"
341351
else:
342352
return (
343353
f"https://github.com/xarray-contrib/datatree/blob/"
344-
f"v{datatree.__version__}/xarray/{fn}{linespec}"
354+
f"v{datatree.__version__}/datatree/{fn}{linespec}"
345355
)

docs/source/data-structures.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
.. _data structures:
24

35
Data Structures

docs/source/hierarchical-data.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
.. _hierarchical-data:
24

35
Working With Hierarchical Data
@@ -31,7 +33,7 @@ Examples of data which one might want organise in a grouped or hierarchical mann
3133

3234
or even any combination of the above.
3335

34-
Often datasets like this cannot easily fit into a single ``xarray.Dataset`` object,
36+
Often datasets like this cannot easily fit into a single :py:class:`xarray.Dataset` object,
3537
or are more usefully thought of as groups of related ``xarray.Dataset`` objects.
3638
For this purpose we provide the :py:class:`DataTree` class.
3739

docs/source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
Datatree
24
========
35

docs/source/installation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
============
24
Installation
35
============

docs/source/io.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
.. _io:
24

35
Reading and Writing Files

docs/source/quick-overview.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
.. currentmodule:: datatree
2+
13
##############
24
Quick overview
35
##############
46

57
DataTrees
68
---------
79

8-
:py:class:`DataTree` is a tree-like container of ``DataArray`` objects, organised into multiple mutually alignable groups.
9-
You can think of it like a (recursive) ``dict`` of ``Dataset`` objects.
10+
:py:class:`DataTree` is a tree-like container of :py:class:`xarray.DataArray` objects, organised into multiple mutually alignable groups.
11+
You can think of it like a (recursive) ``dict`` of :py:class:`xarray.Dataset` objects.
1012

1113
Let's first make some example xarray datasets (following on from xarray's
1214
`quick overview <https://docs.xarray.dev/en/stable/getting-started-guide/quick-overview.html>`_ page):

docs/source/terminology.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. currentmodule:: datatree
2+
23
.. _terminology:
34

45
This page extends `xarray's page on terminology <https://docs.xarray.dev/en/stable/user-guide/terminology.html>`_.

docs/source/tutorial.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: datatree
2+
13
========
24
Tutorial
35
========

docs/source/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Bug fixes
5252

5353
- Fix bug with :py:meth:`DataTree.relative_to` method (:issue:`133`, :pull:`160`).
5454
By `Tom Nicholas <https://github.com/TomNicholas>`_.
55+
- Fix links to API docs in all documentation (:pull:`183`).
56+
By `Tom Nicholas <https://github.com/TomNicholas>`_.
5557

5658
Documentation
5759
~~~~~~~~~~~~~

0 commit comments

Comments
 (0)