Skip to content

Commit 8716e20

Browse files
feat: add custom versionchanged/versionadded logic for replacing |vnext| (DisnakeDev#1376)
Signed-off-by: arielle <me@arielle.codes> Co-authored-by: vi <8530778+shiftinv@users.noreply.github.com>
1 parent 1d3739e commit 8716e20

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,8 @@ We use [towncrier](https://github.com/twisted/towncrier) for managing our change
121121
### Documentation
122122
We use Sphinx to build the project's documentation, which includes [automatically generating](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) the API Reference from docstrings using the [NumPy style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html).
123123
To build the documentation locally, use `pdm run docs` and visit http://127.0.0.1:8009/ once built.
124+
125+
Changes should be marked with a [version directive](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#describing-changes-between-versions) as documented on the Sphinx documentation.
126+
127+
For the `version` argument, provide ``|vnext|`` as the argument.
128+
We have a custom role which replaces ``|vnext|`` with the next version of the library upon building the documentation.

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"collapse",
5757
"enumattrs",
5858
"nitpick_file_ignorer",
59+
"versionchange",
5960
]
6061

6162
autodoc_member_order = "bysource"

docs/extensions/versionchange.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: MIT
2+
from __future__ import annotations
3+
4+
from typing import TYPE_CHECKING
5+
6+
import sphinx.domains.changeset
7+
8+
if TYPE_CHECKING:
9+
from sphinx.application import Sphinx
10+
11+
from ._types import SphinxExtensionMeta
12+
13+
14+
class VersionAddedNext(sphinx.domains.changeset.VersionChange):
15+
"""Add support for a `|vnext|` version placeholder in versionadded directives."""
16+
17+
def run(self):
18+
# If the argument is |vnext|, replace with config version
19+
if self.arguments and self.arguments[0] == "|vnext|":
20+
# Get the version from the Sphinx config
21+
version = self.env.config.version
22+
self.arguments[0] = version
23+
return super().run()
24+
25+
26+
def setup(app: Sphinx) -> SphinxExtensionMeta:
27+
app.add_directive("versionadded", VersionAddedNext, override=True)
28+
app.add_directive("versionchanged", VersionAddedNext, override=True)
29+
app.add_directive("deprecated", VersionAddedNext, override=True)
30+
31+
return {
32+
"parallel_read_safe": True,
33+
"parallel_write_safe": True,
34+
}

0 commit comments

Comments
 (0)