Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.9] gh-121277: Allow .. versionadded:: next in docs (GH-121278) #128117

Open
wants to merge 2 commits into
base: 3.9
Choose a base branch
from
Open
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
36 changes: 31 additions & 5 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from sphinx import addnodes
from sphinx.builders import Builder
from sphinx.domains.changeset import VersionChange
try:
from sphinx.errors import NoUri
except ImportError:
Expand Down Expand Up @@ -332,7 +333,22 @@ def run(self):
return PyMethod.run(self)


# Support for documenting version of removal in deprecations
# Support for documenting version of changes, additions, deprecations

def expand_version_arg(argument, release):
"""Expand "next" to the current version"""
if argument == 'next':
return translators['sphinx'].gettext('{} (unreleased)').format(release)
return argument


class PyVersionChange(VersionChange):
def run(self):
# Replace the 'next' special token with the current development version
self.arguments[0] = expand_version_arg(self.arguments[0],
self.config.release)
return super().run()


class DeprecatedRemoved(Directive):
has_content = True
Expand All @@ -348,18 +364,24 @@ def run(self):
node = addnodes.versionmodified()
node.document = self.state.document
node['type'] = 'deprecated-removed'
version = (self.arguments[0], self.arguments[1])
node['version'] = version
env = self.state.document.settings.env
version = (
expand_version_arg(self.arguments[0], env.config.release),
self.arguments[1],
)
if version[1] == 'next':
raise ValueError(
'deprecated-removed:: second argument cannot be `next`')
node['version'] = version
current_version = tuple(int(e) for e in env.config.version.split('.'))
removed_version = tuple(int(e) for e in self.arguments[1].split('.'))
removed_version = tuple(int(e) for e in version[1].split('.'))
if current_version < removed_version:
label = self._deprecated_label
else:
label = self._removed_label

label = translators['sphinx'].gettext(label)
text = label.format(deprecated=self.arguments[0], removed=self.arguments[1])
text = label.format(deprecated=version[0], removed=version[1])
if len(self.arguments) == 3:
inodes, messages = self.state.inline_text(self.arguments[2],
self.lineno+1)
Expand Down Expand Up @@ -607,6 +629,10 @@ def setup(app):
app.add_directive('availability', Availability)
app.add_directive('audit-event', AuditEvent)
app.add_directive('audit-event-table', AuditEventListDirective)
app.add_directive('versionadded', PyVersionChange, override=True)
app.add_directive('versionchanged', PyVersionChange, override=True)
app.add_directive('versionremoved', PyVersionChange, override=True)
app.add_directive('deprecated', PyVersionChange, override=True)
app.add_directive('deprecated-removed', DeprecatedRemoved)
app.add_builder(PydocTopicsBuilder)
app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Writers of CPython's documentation can now use ``next`` as the version for
the ``versionchanged``, ``versionadded``, ``deprecated`` directives.
Loading