Skip to content

Commit 98d7cb9

Browse files
authored
Update docs for first release (#120)
* exclude doctree from actual docs * Update docs for first release
1 parent 019c416 commit 98d7cb9

File tree

6 files changed

+154
-8
lines changed

6 files changed

+154
-8
lines changed

README.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ C++, making it ideal for high-performance production environments.
2828
2929
For details, tutorials, and examples, please have a look at our `documentation`_.
3030

31-
.. _`documentation`: https://lab-cosmo.github.io/torch-pme/latest
31+
.. _`documentation`: https://lab-cosmo.github.io/torch-pme
3232

3333
.. marker-installation
3434
@@ -39,18 +39,16 @@ You can install *torch-pme* using pip with
3939

4040
.. code-block:: bash
4141
42-
git clone https://github.com/lab-cosmo/torch-pme
43-
cd torch-pme
44-
pip install .
42+
pip install torch-pme
4543
46-
You can then ``import torchpme`` and use it in your projects!
44+
and ``import torchpme`` to use it in your projects!
4745

48-
We also provide bindings to `metatensor <https://docs.metatensor.org/latest/>`_ which
46+
We also provide bindings to `metatensor <https://docs.metatensor.org>`_ which
4947
can optionally be installed together and used as ``torchpme.metatensor`` via
5048

5149
.. code-block:: bash
5250
53-
pip install .[metatensor]
51+
pip install torch-pme[metatensor]
5452
5553
.. marker-issues
5654

docs/extensions/versions_list.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import docutils
2+
from packaging.version import parse as version_parse
3+
from sphinx.util.docutils import SphinxDirective
4+
5+
6+
DOC_ROOT = "https://lab-cosmo.github.io/torch-pme"
7+
8+
9+
class VersionList(SphinxDirective):
10+
"""
11+
Directive for a list of previous versions of the documentation.
12+
13+
This is rendered by manually generating ReST using sphinx-design directives.
14+
"""
15+
16+
has_content = True
17+
required_arguments = 0
18+
optional_arguments = 0
19+
option_spec = {
20+
"tag-prefix": str,
21+
"url-suffix": str,
22+
}
23+
24+
def run(self):
25+
# group together versions with the same major & minor components
26+
grouped_versions = {}
27+
content = self.parse_content_to_nodes()
28+
for node in content:
29+
if not isinstance(node, VersionNode):
30+
raise ValueError(
31+
"only `.. version::` is allowed inside `.. version-list::`"
32+
)
33+
34+
version = version_parse(node.version)
35+
group = (version.major, version.minor)
36+
if group not in grouped_versions:
37+
grouped_versions[group] = []
38+
39+
grouped_versions[group].append(node)
40+
41+
# generate ReST with the desired markup
42+
generated_content = """
43+
.. grid::
44+
:margin: 0 0 0 0\n"""
45+
46+
for group_i, (version_short, group) in enumerate(grouped_versions.items()):
47+
48+
if group_i < 3:
49+
generated_content += f"""
50+
.. grid-item::
51+
:columns: 12 6 3 3
52+
:class: sd-p-1
53+
54+
.. dropdown:: Version {version_short[0]}.{version_short[1]}
55+
:class-body: sd-mb-0 sd-pb-0
56+
:class-title: font-size-small\n"""
57+
elif group_i == 3:
58+
generated_content += """
59+
.. grid-item::
60+
:columns: 12 6 3 3
61+
:class: sd-p-1
62+
63+
.. dropdown:: Older versions
64+
:class-body: sd-mb-0 sd-pb-0
65+
:class-title: font-size-small\n"""
66+
67+
for node in group:
68+
version = node.version
69+
tag_prefix = self.options["tag-prefix"]
70+
71+
url_suffix = (
72+
node.url_suffix
73+
if node.url_suffix is not None
74+
else self.options["url-suffix"]
75+
)
76+
77+
generated_content += f"""
78+
.. card:: {version}
79+
:class-body: sd-p-2
80+
:class-title: sd-mb-0
81+
:text-align: center
82+
:link: {DOC_ROOT}/{tag_prefix}{version}/{url_suffix}
83+
:link-type: url\n"""
84+
85+
# parse the generated ReST
86+
return self.parse_text_to_nodes(generated_content)
87+
88+
89+
class VersionNode(docutils.nodes.Node):
90+
"""
91+
Node for a single version directive. This is only used to transmit information
92+
between the ``.. version::`` directive and the version list, and never rendered on
93+
its own.
94+
"""
95+
96+
def __init__(self, version, url_suffix):
97+
self.version = version
98+
self.url_suffix = url_suffix
99+
100+
101+
class VersionItem(SphinxDirective):
102+
"""
103+
A single item in a version list. This can override the url suffix if a different url
104+
was used for this version.
105+
"""
106+
107+
has_content = False
108+
required_arguments = 1
109+
optional_arguments = 0
110+
final_argument_whitespace = False
111+
option_spec = {
112+
"url-suffix": str,
113+
}
114+
115+
def run(self):
116+
return [
117+
VersionNode(
118+
version=self.arguments[0],
119+
url_suffix=self.options.get("url-suffix"),
120+
)
121+
]
122+
123+
124+
def setup(app):
125+
app.add_directive("version-list", VersionList)
126+
app.add_directive("version", VersionItem)

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
furo
22
sphinx > 7.0
3+
sphinx-design
34
sphinx-gallery
45
sphinx-toggleprompt
56
tomli

docs/src/conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
suppress_warnings = ["config.cache"]
1717

1818
ROOT = os.path.abspath(os.path.join("..", ".."))
19+
sys.path.append(os.path.join(ROOT, "docs", "extensions"))
1920

2021
# We use a second (pseudo) sphinx project located in `docs/generate_examples` to run the
2122
# examples and generate the actual output for our shinx-gallery. This is necessary
@@ -63,6 +64,12 @@ def setup(app):
6364
generate_examples()
6465

6566

67+
rst_prolog = f"""
68+
.. |version| replace:: {torchpme.__version__}
69+
70+
"""
71+
72+
6673
# Add any Sphinx extension module names here, as strings. They can be
6774
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
6875
# ones.
@@ -72,7 +79,10 @@ def setup(app):
7279
"sphinx.ext.viewcode",
7380
"sphinx_gallery.gen_gallery",
7481
"sphinx_toggleprompt",
82+
"sphinx_design",
7583
"chemiscope.sphinx",
84+
# local extensions
85+
"versions_list",
7686
]
7787

7888
# List of patterns, relative to source directory, that match files and

docs/src/references/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
API reference
44
=============
55

6+
.. note::
7+
8+
This is the documentation for version |version|. For other versions, we refer to the
9+
following pages:
10+
11+
.. version-list::
12+
:tag-prefix: v
13+
:url-suffix: references/index.html
14+
15+
.. version:: 0.1.0
16+
617
The main references for public functions and classes inside ``torch-pme``. For example
718
refer to the :ref:`userdoc-how-to` section.
819

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ extras =
9393
examples
9494
metatensor
9595
commands =
96-
sphinx-build {posargs:-E} -W -b html docs/src docs/build/html
96+
sphinx-build {posargs:-E} -d docs/build/doctrees -W -b html docs/src docs/build/html

0 commit comments

Comments
 (0)