Skip to content

Use hyphenated version directives #13714

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

Open
wants to merge 2 commits into
base: master
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
52 changes: 36 additions & 16 deletions doc/usage/restructuredtext/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ Describing changes between versions
pair: changes; in version
pair: removed; in version

.. rst:directive:: .. versionadded:: version [brief explanation]
.. rst:directive:: .. version-added:: version [brief explanation]
.. versionadded:: version [brief explanation]

This directive documents the version of the project
which added the described feature.
Expand All @@ -551,56 +552,75 @@ Describing changes between versions
There must be no blank line between the directive head and the explanation;
this is to make these blocks visually continuous in the markup.

.. version-changed:: 8.3
The :rst:dir:`versionadded` directive was renamed to :rst:dir:`version-added`.
The previous name is retained as an alias.

Example::

.. versionadded:: 2.5
.. version-added:: 2.5
The *spam* parameter.

.. versionadded:: 2.5
.. version-added:: 2.5
The *spam* parameter.

.. rst:directive:: .. versionchanged:: version [brief explanation]
.. rst:directive:: .. version-changed:: version [brief explanation]
.. versionchanged:: version [brief explanation]

Similar to :rst:dir:`versionadded`, but describes when and what changed in
Similar to :rst:dir:`version-added`, but describes when and what changed in
the named feature in some way (new parameters, changed side effects, etc.).

.. version-changed:: 8.3
The :rst:dir:`versionchanged` directive was renamed to :rst:dir:`version-changed`.
The previous name is retained as an alias.

Example::

.. versionchanged:: 2.8
.. version-changed:: 2.8
The *spam* parameter is now of type *boson*.

.. versionchanged:: 2.8
.. version-changed:: 2.8
The *spam* parameter is now of type *boson*.

.. rst:directive:: .. deprecated:: version [brief explanation]
.. rst:directive:: .. version-deprecated:: version [brief explanation]
.. deprecated:: version [brief explanation]

Similar to :rst:dir:`versionadded`, but describes when the feature was
Similar to :rst:dir:`version-added`, but describes when the feature was
deprecated.
A *brief* explanation can also be given,
for example to tell the reader what to use instead.

.. version-changed:: 8.3
The :rst:dir:`deprecated` directive was renamed to :rst:dir:`version-deprecated`.
The previous name is retained as an alias

Example::

.. deprecated:: 3.1
.. version-deprecated:: 3.1
Use :py:func:`spam` instead.

.. deprecated:: 3.1
.. version-deprecated:: 3.1
Use :py:func:`!spam` instead.

.. rst:directive:: .. versionremoved:: version [brief explanation]
.. rst:directive:: .. version-removed:: version [brief explanation]
.. versionremoved:: version [brief explanation]

Similar to :rst:dir:`versionadded`, but describes when the feature was removed.
Similar to :rst:dir:`version-added`, but describes when the feature was removed.
An explanation may be provided to tell the reader what to use instead,
or why the feature was removed.

.. versionadded:: 7.3
.. version-added:: 7.3

.. version-changed:: 8.3
The :rst:dir:`versionremoved` directive was renamed to :rst:dir:`version-removed`.
The previous name is retained as an alias.

Example::

.. versionremoved:: 4.0
.. version-removed:: 4.0
The :py:func:`spam` function is more flexible, and should be used instead.

.. versionremoved:: 4.0
.. version-removed:: 4.0
The :py:func:`!spam` function is more flexible, and should be used instead.


Expand Down
4 changes: 2 additions & 2 deletions sphinx/addnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class desc_sig_literal_char(desc_sig_element, _sig_element=True):
class versionmodified(nodes.Admonition, nodes.TextElement):
"""Node for version change entries.

Currently used for "versionadded", "versionchanged", "deprecated"
and "versionremoved" directives.
Currently used for "version-added", "version-changed", "version-deprecated"
and "version-removed" directives, along with their aliases.
"""


Expand Down
2 changes: 1 addition & 1 deletion sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def setup(app):

.. versionchanged:: 0.6
Docutils 0.5-style directive classes are now supported.
.. deprecated:: 1.8
.. versionchanged:: 1.8
Docutils 0.4-style (function based) directives support is deprecated.
.. versionchanged:: 1.8
Add *override* keyword.
Expand Down
10 changes: 9 additions & 1 deletion sphinx/builders/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class ChangesBuilder(Builder):
"""Write a summary with all versionadded/changed/deprecated/removed directives."""
"""Write a summary with all version-related directives."""

name = 'changes'
epilog = __('The overview file is in %(outdir)s.')
Expand All @@ -43,9 +43,13 @@ def get_outdated_docs(self) -> str:
return str(self.outdir)

typemap = {
'version-added': 'added',
'versionadded': 'added',
'version-changed': 'changed',
'versionchanged': 'changed',
'version-deprecated': 'deprecated',
'deprecated': 'deprecated',
'version-removed': 'removed',
'versionremoved': 'removed',
}

Expand Down Expand Up @@ -112,9 +116,13 @@ def write_documents(self, _docnames: Set[str]) -> None:
f.write(self.templates.render('changes/versionchanges.html', ctx))

hltext = [
f'.. version-added:: {version}',
f'.. versionadded:: {version}',
f'.. version-changed:: {version}',
f'.. versionchanged:: {version}',
f'.. version-deprecated:: {version}',
f'.. deprecated:: {version}',
f'.. version-removed:: {version}',
f'.. versionremoved:: {version}',
]

Expand Down
17 changes: 14 additions & 3 deletions sphinx/domains/changeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from sphinx.environment import BuildEnvironment
from sphinx.util.typing import ExtensionMetadata, OptionSpec

name_aliases = {
'version-added': 'versionadded',
'version-changed': 'versionchanged',
'version-deprecated': 'deprecated',
'version-removed': 'versionremoved',
}

versionlabels = {
'versionadded': _('Added in version %s'),
Expand Down Expand Up @@ -56,12 +62,13 @@ class VersionChange(SphinxDirective):
option_spec: ClassVar[OptionSpec] = {}

def run(self) -> list[Node]:
name = name_aliases.get(self.name, self.name)
node = addnodes.versionmodified()
node.document = self.state.document
self.set_source_info(node)
node['type'] = self.name
node['type'] = name
node['version'] = self.arguments[0]
text = versionlabels[self.name] % self.arguments[0]
text = versionlabels[name] % self.arguments[0]
if len(self.arguments) == 2:
inodes, messages = self.parse_inline(
self.arguments[1], lineno=self.lineno + 1
Expand All @@ -73,7 +80,7 @@ def run(self) -> list[Node]:
messages = []
if self.content:
node += self.parse_content_to_nodes()
classes = ['versionmodified', versionlabel_classes[self.name]]
classes = ['versionmodified', versionlabel_classes[name]]
if len(node) > 0 and isinstance(node[0], nodes.paragraph):
# the contents start with a paragraph
if node[0].rawsource:
Expand Down Expand Up @@ -168,9 +175,13 @@ def get_changesets_for(self, version: str) -> list[ChangeSet]:

def setup(app: Sphinx) -> ExtensionMetadata:
app.add_domain(ChangeSetDomain)
app.add_directive('version-deprecated', VersionChange)
app.add_directive('deprecated', VersionChange)
app.add_directive('version-added', VersionChange)
app.add_directive('versionadded', VersionChange)
app.add_directive('version-changed', VersionChange)
app.add_directive('versionchanged', VersionChange)
app.add_directive('version-removed', VersionChange)
app.add_directive('versionremoved', VersionChange)

return {
Expand Down
33 changes: 24 additions & 9 deletions tests/roots/test-changes/base.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
Version markup
--------------

.. versionadded:: 0.6
.. version-added:: 0.6
Some funny **stuff**.

.. versionchanged:: 0.6
.. version-changed:: 0.6
Even more funny stuff.

.. deprecated:: 0.6
.. version-deprecated:: 0.6
Boring stuff.

.. versionremoved:: 0.6
.. version-removed:: 0.6
Goodbye boring stuff.

.. versionadded:: 1.2
.. version-added:: 1.2

First paragraph of version-added.

.. version-changed:: 1.2
First paragraph of version-changed.

Second paragraph of version-changed.

First paragraph of versionadded.
.. version-deprecated:: 1.3
First paragraph of version-deprecated.

.. versionchanged:: 1.2
First paragraph of versionchanged.
.. version-added:: 0.6
Deprecated alias

Second paragraph of versionchanged.
.. version-changed:: 0.6
Deprecated alias

.. versionremoved:: 0.6
Deprecated alias

.. deprecated:: 0.6
Deprecated alias
4 changes: 2 additions & 2 deletions tests/roots/test-changes/c-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Memory

Allocate *n* bytes of memory.

.. versionchanged:: 0.6
.. version-changed:: 0.6

Can now be replaced with a different allocator.

Expand All @@ -17,7 +17,7 @@ System

Access to the system allocator.

.. versionadded:: 0.6
.. version-added:: 0.6

.. c:function:: void* Test_SysMalloc(size_t n)

Expand Down
6 changes: 3 additions & 3 deletions tests/roots/test-changes/library/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Classes

Class for handling paths.

.. versionadded:: 0.5
.. version-added:: 0.5

Innovative new way to handle paths.
Innovative new way to handle paths.

.. deprecated:: 0.6
.. version-deprecated:: 0.6

So, that was a bad idea it turns out.
16 changes: 8 additions & 8 deletions tests/roots/test-intl/versionchange.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
i18n with versionchange
============================

.. deprecated:: 1.0
This is the *first* paragraph of deprecated.
.. version-deprecated:: 1.0
This is the *first* paragraph of version-deprecated.

This is the *second* paragraph of deprecated.
This is the *second* paragraph of version-deprecated.

.. versionadded:: 1.0
This is the *first* paragraph of versionadded.
.. version-added:: 1.0
This is the *first* paragraph of version-added.

.. versionchanged:: 1.0
.. version-changed:: 1.0

This is the *first* paragraph of versionchanged.
This is the *first* paragraph of version-changed.

.. versionremoved:: 1.0 This is the *first* paragraph of versionremoved.
.. version-removed:: 1.0 This is the *first* paragraph of version-removed.
18 changes: 15 additions & 3 deletions tests/roots/test-intl/xx/LC_MESSAGES/versionchange.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ msgstr ""
msgid "i18n with versionchange"
msgstr "I18N WITH VERSIONCHANGE"

msgid "This is the *first* paragraph of version-deprecated."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF VERSION-DEPRECATED."

msgid "This is the *second* paragraph of version-deprecated."
msgstr "THIS IS THE *SECOND* PARAGRAPH OF VERSION-DEPRECATED."

msgid "This is the *first* paragraph of version-added."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF VERSION-ADDED."

msgid "This is the *first* paragraph of version-changed."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF VERSION-CHANGED."

msgid "This is the *first* paragraph of version-removed."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF VERSION-REMOVED."

msgid "This is the *first* paragraph of deprecated."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF DEPRECATED."

msgid "This is the *second* paragraph of deprecated."
msgstr "THIS IS THE *SECOND* PARAGRAPH OF DEPRECATED."

msgid "This is the *first* paragraph of versionadded."
msgstr "THIS IS THE *FIRST* PARAGRAPH OF VERSIONADDED."

Expand Down
29 changes: 20 additions & 9 deletions tests/roots/test-root/markup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,38 @@ Figures
Version markup
--------------

.. versionadded:: 0.6
.. version-added:: 0.6
Some funny **stuff**.

.. versionchanged:: 0.6
.. version-changed:: 0.6
Even more funny stuff.

.. deprecated:: 0.6
.. version-deprecated:: 0.6
Boring stuff.

.. versionremoved:: 0.6
.. version-removed:: 0.6
Goodbye boring stuff.

.. versionadded:: 1.2
.. version-added:: 1.2

First paragraph of version-added.

.. version-changed:: 1.2
First paragraph of version-changed.

First paragraph of versionadded.
Second paragraph of version-changed.

.. versionchanged:: 1.2
First paragraph of versionchanged.
.. version-added:: 0.6
Deprecated alias for version-added.

Second paragraph of versionchanged.
.. version-changed:: 0.6
Deprecated alias for version-changed.

.. deprecated:: 0.6
Deprecated alias for version-deprecated.

.. versionremoved:: 0.6
Deprecated alias for version-removed.

Code blocks
-----------
Expand Down
Loading
Loading