mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Move VersionChanges directive to sphinx.domains.changeset
This commit is contained in:
parent
25bfa1692a
commit
03d083e784
1
CHANGES
1
CHANGES
@ -118,6 +118,7 @@ Deprecated
|
|||||||
* ``sphinx.ext.mathbase.is_in_section_title()`` is deprecated
|
* ``sphinx.ext.mathbase.is_in_section_title()`` is deprecated
|
||||||
* ``sphinx.ext.mathbase.MathDomain`` is deprecated
|
* ``sphinx.ext.mathbase.MathDomain`` is deprecated
|
||||||
* ``sphinx.ext.mathbase.setup_math()`` is deprecated
|
* ``sphinx.ext.mathbase.setup_math()`` is deprecated
|
||||||
|
* ``sphinx.directives.other.VersionChanges`` is deprecated
|
||||||
* ``sphinx.highlighting.PygmentsBridge.unhighlight()`` is deprecated
|
* ``sphinx.highlighting.PygmentsBridge.unhighlight()`` is deprecated
|
||||||
* ``sphinx.ext.mathbase.get_node_equation_number()`` is deprecated
|
* ``sphinx.ext.mathbase.get_node_equation_number()`` is deprecated
|
||||||
* ``sphinx.ext.mathbase.wrap_displaymath()`` is deprecated
|
* ``sphinx.ext.mathbase.wrap_displaymath()`` is deprecated
|
||||||
|
@ -131,6 +131,11 @@ The following is a list of deprecated interface.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- :meth:`~sphinx.application.Sphinx.add_js_file()`
|
- :meth:`~sphinx.application.Sphinx.add_js_file()`
|
||||||
|
|
||||||
|
* - ``sphinx.directives.other.VersionChanges``
|
||||||
|
- 1.8
|
||||||
|
- 3.0
|
||||||
|
- ``sphinx.domains.changeset.VersionChanges``
|
||||||
|
|
||||||
* - ``sphinx.highlighting.PygmentsBridge.unhighlight()``
|
* - ``sphinx.highlighting.PygmentsBridge.unhighlight()``
|
||||||
- 1.8
|
- 1.8
|
||||||
- 3.0
|
- 3.0
|
||||||
|
@ -17,8 +17,8 @@ from docutils.parsers.rst.directives.misc import Class
|
|||||||
from docutils.parsers.rst.directives.misc import Include as BaseInclude
|
from docutils.parsers.rst.directives.misc import Include as BaseInclude
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
from sphinx import addnodes, locale
|
from sphinx import addnodes
|
||||||
from sphinx.deprecation import DeprecatedDict, RemovedInSphinx30Warning
|
from sphinx.domains.changeset import VersionChange # NOQA # for compatibility
|
||||||
from sphinx.locale import _
|
from sphinx.locale import _
|
||||||
from sphinx.util import url_re, docname_join
|
from sphinx.util import url_re, docname_join
|
||||||
from sphinx.util.docutils import SphinxDirective
|
from sphinx.util.docutils import SphinxDirective
|
||||||
@ -32,19 +32,6 @@ if False:
|
|||||||
from sphinx.application import Sphinx # NOQA
|
from sphinx.application import Sphinx # NOQA
|
||||||
|
|
||||||
|
|
||||||
versionlabels = {
|
|
||||||
'versionadded': _('New in version %s'),
|
|
||||||
'versionchanged': _('Changed in version %s'),
|
|
||||||
'deprecated': _('Deprecated since version %s'),
|
|
||||||
} # type: Dict[unicode, unicode]
|
|
||||||
|
|
||||||
locale.versionlabels = DeprecatedDict(
|
|
||||||
versionlabels,
|
|
||||||
'sphinx.locale.versionlabels is deprecated. '
|
|
||||||
'Please use sphinx.directives.other.versionlabels instead.',
|
|
||||||
RemovedInSphinx30Warning
|
|
||||||
)
|
|
||||||
|
|
||||||
glob_re = re.compile(r'.*[*?\[].*')
|
glob_re = re.compile(r'.*[*?\[].*')
|
||||||
|
|
||||||
|
|
||||||
@ -218,54 +205,6 @@ class Index(SphinxDirective):
|
|||||||
return [indexnode, targetnode]
|
return [indexnode, targetnode]
|
||||||
|
|
||||||
|
|
||||||
class VersionChange(SphinxDirective):
|
|
||||||
"""
|
|
||||||
Directive to describe a change/addition/deprecation in a specific version.
|
|
||||||
"""
|
|
||||||
has_content = True
|
|
||||||
required_arguments = 1
|
|
||||||
optional_arguments = 1
|
|
||||||
final_argument_whitespace = True
|
|
||||||
option_spec = {} # type: Dict
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
# type: () -> List[nodes.Node]
|
|
||||||
node = addnodes.versionmodified()
|
|
||||||
node.document = self.state.document
|
|
||||||
set_source_info(self, node)
|
|
||||||
node['type'] = self.name
|
|
||||||
node['version'] = self.arguments[0]
|
|
||||||
text = versionlabels[self.name] % self.arguments[0]
|
|
||||||
if len(self.arguments) == 2:
|
|
||||||
inodes, messages = self.state.inline_text(self.arguments[1],
|
|
||||||
self.lineno + 1)
|
|
||||||
para = nodes.paragraph(self.arguments[1], '', *inodes, translatable=False)
|
|
||||||
set_source_info(self, para)
|
|
||||||
node.append(para)
|
|
||||||
else:
|
|
||||||
messages = []
|
|
||||||
if self.content:
|
|
||||||
self.state.nested_parse(self.content, self.content_offset, node)
|
|
||||||
if len(node):
|
|
||||||
if isinstance(node[0], nodes.paragraph) and node[0].rawsource:
|
|
||||||
content = nodes.inline(node[0].rawsource, translatable=True)
|
|
||||||
content.source = node[0].source
|
|
||||||
content.line = node[0].line
|
|
||||||
content += node[0].children
|
|
||||||
node[0].replace_self(nodes.paragraph('', '', content, translatable=False))
|
|
||||||
node[0].insert(0, nodes.inline('', '%s: ' % text,
|
|
||||||
classes=['versionmodified']))
|
|
||||||
else:
|
|
||||||
para = nodes.paragraph('', '',
|
|
||||||
nodes.inline('', '%s.' % text,
|
|
||||||
classes=['versionmodified']),
|
|
||||||
translatable=False)
|
|
||||||
node.append(para)
|
|
||||||
|
|
||||||
self.env.get_domain('changeset').note_changeset(node) # type: ignore
|
|
||||||
return [node] + messages
|
|
||||||
|
|
||||||
|
|
||||||
class SeeAlso(BaseAdmonition):
|
class SeeAlso(BaseAdmonition):
|
||||||
"""
|
"""
|
||||||
An admonition mentioning things to look at as reference.
|
An admonition mentioning things to look at as reference.
|
||||||
@ -475,9 +414,6 @@ def setup(app):
|
|||||||
directives.register_directive('moduleauthor', Author)
|
directives.register_directive('moduleauthor', Author)
|
||||||
directives.register_directive('codeauthor', Author)
|
directives.register_directive('codeauthor', Author)
|
||||||
directives.register_directive('index', Index)
|
directives.register_directive('index', Index)
|
||||||
directives.register_directive('deprecated', VersionChange)
|
|
||||||
directives.register_directive('versionadded', VersionChange)
|
|
||||||
directives.register_directive('versionchanged', VersionChange)
|
|
||||||
directives.register_directive('seealso', SeeAlso)
|
directives.register_directive('seealso', SeeAlso)
|
||||||
directives.register_directive('tabularcolumns', TabularColumns)
|
directives.register_directive('tabularcolumns', TabularColumns)
|
||||||
directives.register_directive('centered', Centered)
|
directives.register_directive('centered', Centered)
|
||||||
|
@ -11,19 +11,39 @@
|
|||||||
|
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
|
from docutils import nodes
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
|
from sphinx import addnodes
|
||||||
|
from sphinx import locale
|
||||||
|
from sphinx.deprecation import DeprecatedDict, RemovedInSphinx30Warning
|
||||||
from sphinx.domains import Domain
|
from sphinx.domains import Domain
|
||||||
|
from sphinx.locale import _
|
||||||
|
from sphinx.util.docutils import SphinxDirective
|
||||||
|
from sphinx.util.nodes import set_source_info
|
||||||
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
from typing import Any, Dict, List # NOQA
|
from typing import Any, Dict, List # NOQA
|
||||||
from docutils import nodes # NOQA
|
|
||||||
from sphinx.application import Sphinx # NOQA
|
from sphinx.application import Sphinx # NOQA
|
||||||
from sphinx.environment import BuildEnvironment # NOQA
|
from sphinx.environment import BuildEnvironment # NOQA
|
||||||
|
|
||||||
|
|
||||||
|
versionlabels = {
|
||||||
|
'versionadded': _('New in version %s'),
|
||||||
|
'versionchanged': _('Changed in version %s'),
|
||||||
|
'deprecated': _('Deprecated since version %s'),
|
||||||
|
} # type: Dict[unicode, unicode]
|
||||||
|
|
||||||
|
locale.versionlabels = DeprecatedDict(
|
||||||
|
versionlabels,
|
||||||
|
'sphinx.locale.versionlabels is deprecated. '
|
||||||
|
'Please use sphinx.domains.changeset.versionlabels instead.',
|
||||||
|
RemovedInSphinx30Warning
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ChangeSet = NamedTuple('ChangeSet', [('type', str),
|
ChangeSet = NamedTuple('ChangeSet', [('type', str),
|
||||||
('docname', str),
|
('docname', str),
|
||||||
('lineno', int),
|
('lineno', int),
|
||||||
@ -32,6 +52,54 @@ ChangeSet = NamedTuple('ChangeSet', [('type', str),
|
|||||||
('content', str)])
|
('content', str)])
|
||||||
|
|
||||||
|
|
||||||
|
class VersionChange(SphinxDirective):
|
||||||
|
"""
|
||||||
|
Directive to describe a change/addition/deprecation in a specific version.
|
||||||
|
"""
|
||||||
|
has_content = True
|
||||||
|
required_arguments = 1
|
||||||
|
optional_arguments = 1
|
||||||
|
final_argument_whitespace = True
|
||||||
|
option_spec = {} # type: Dict
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
# type: () -> List[nodes.Node]
|
||||||
|
node = addnodes.versionmodified()
|
||||||
|
node.document = self.state.document
|
||||||
|
set_source_info(self, node)
|
||||||
|
node['type'] = self.name
|
||||||
|
node['version'] = self.arguments[0]
|
||||||
|
text = versionlabels[self.name] % self.arguments[0]
|
||||||
|
if len(self.arguments) == 2:
|
||||||
|
inodes, messages = self.state.inline_text(self.arguments[1],
|
||||||
|
self.lineno + 1)
|
||||||
|
para = nodes.paragraph(self.arguments[1], '', *inodes, translatable=False)
|
||||||
|
set_source_info(self, para)
|
||||||
|
node.append(para)
|
||||||
|
else:
|
||||||
|
messages = []
|
||||||
|
if self.content:
|
||||||
|
self.state.nested_parse(self.content, self.content_offset, node)
|
||||||
|
if len(node):
|
||||||
|
if isinstance(node[0], nodes.paragraph) and node[0].rawsource:
|
||||||
|
content = nodes.inline(node[0].rawsource, translatable=True)
|
||||||
|
content.source = node[0].source
|
||||||
|
content.line = node[0].line
|
||||||
|
content += node[0].children
|
||||||
|
node[0].replace_self(nodes.paragraph('', '', content, translatable=False))
|
||||||
|
node[0].insert(0, nodes.inline('', '%s: ' % text,
|
||||||
|
classes=['versionmodified']))
|
||||||
|
else:
|
||||||
|
para = nodes.paragraph('', '',
|
||||||
|
nodes.inline('', '%s.' % text,
|
||||||
|
classes=['versionmodified']),
|
||||||
|
translatable=False)
|
||||||
|
node.append(para)
|
||||||
|
|
||||||
|
self.env.get_domain('changeset').note_changeset(node) # type: ignore
|
||||||
|
return [node] + messages
|
||||||
|
|
||||||
|
|
||||||
class ChangeSetDomain(Domain):
|
class ChangeSetDomain(Domain):
|
||||||
"""Domain for changesets."""
|
"""Domain for changesets."""
|
||||||
|
|
||||||
@ -79,6 +147,9 @@ class ChangeSetDomain(Domain):
|
|||||||
def setup(app):
|
def setup(app):
|
||||||
# type: (Sphinx) -> Dict[unicode, Any]
|
# type: (Sphinx) -> Dict[unicode, Any]
|
||||||
app.add_domain(ChangeSetDomain)
|
app.add_domain(ChangeSetDomain)
|
||||||
|
app.add_directive('deprecated', VersionChange)
|
||||||
|
app.add_directive('versionadded', VersionChange)
|
||||||
|
app.add_directive('versionchanged', VersionChange)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'version': 'builtin',
|
'version': 'builtin',
|
||||||
|
Loading…
Reference in New Issue
Block a user