mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '4.x'
This commit is contained in:
commit
b90a52c93c
2
setup.py
2
setup.py
@ -43,7 +43,7 @@ extras_require = {
|
|||||||
'lint': [
|
'lint': [
|
||||||
'flake8>=3.5.0',
|
'flake8>=3.5.0',
|
||||||
'isort',
|
'isort',
|
||||||
'mypy>=0.930',
|
'mypy>=0.931',
|
||||||
'docutils-stubs',
|
'docutils-stubs',
|
||||||
"types-typed-ast",
|
"types-typed-ast",
|
||||||
"types-requests",
|
"types-requests",
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from os import path
|
from os import path
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Tuple, cast
|
from typing import TYPE_CHECKING, Any, Dict, List, Sequence, Tuple, cast
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.nodes import Node, make_id, system_message
|
from docutils.nodes import Node, make_id, system_message
|
||||||
@ -68,7 +68,7 @@ class Figure(images.Figure):
|
|||||||
|
|
||||||
|
|
||||||
class Meta(MetaBase, SphinxDirective):
|
class Meta(MetaBase, SphinxDirective):
|
||||||
def run(self) -> List[Node]:
|
def run(self) -> Sequence[Node]:
|
||||||
result = super().run()
|
result = super().run()
|
||||||
for node in result:
|
for node in result:
|
||||||
# for docutils-0.17 or older. Since docutils-0.18, patching is no longer needed
|
# for docutils-0.17 or older. Since docutils-0.18, patching is no longer needed
|
||||||
@ -83,7 +83,7 @@ class Meta(MetaBase, SphinxDirective):
|
|||||||
# docutils' meta nodes aren't picklable because the class is nested
|
# docutils' meta nodes aren't picklable because the class is nested
|
||||||
meta.__class__ = addnodes.meta
|
meta.__class__ = addnodes.meta
|
||||||
|
|
||||||
return result # type: ignore
|
return result
|
||||||
|
|
||||||
|
|
||||||
class RSTTable(tables.RSTTable):
|
class RSTTable(tables.RSTTable):
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Locale utilities.
|
Locale utilities.
|
||||||
|
|
||||||
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
|
:copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
|
||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
# for Debian-jessie
|
# for Debian-jessie
|
||||||
from urllib3.exceptions import InsecureRequestWarning # type: ignore
|
from urllib3.exceptions import InsecureRequestWarning
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# for requests < 2.4.0
|
# for requests < 2.4.0
|
||||||
InsecureRequestWarning = None # type: ignore
|
InsecureRequestWarning = None
|
||||||
|
|
||||||
|
|
||||||
useragent_header = [('User-Agent',
|
useragent_header = [('User-Agent',
|
||||||
|
@ -79,7 +79,7 @@ def test_domain_py_xrefs(app, status, warning):
|
|||||||
assert_node(node, **attributes)
|
assert_node(node, **attributes)
|
||||||
|
|
||||||
doctree = app.env.get_doctree('roles')
|
doctree = app.env.get_doctree('roles')
|
||||||
refnodes = list(doctree.traverse(pending_xref))
|
refnodes = list(doctree.findall(pending_xref))
|
||||||
assert_refnode(refnodes[0], None, None, 'TopLevel', 'class')
|
assert_refnode(refnodes[0], None, None, 'TopLevel', 'class')
|
||||||
assert_refnode(refnodes[1], None, None, 'top_level', 'meth')
|
assert_refnode(refnodes[1], None, None, 'top_level', 'meth')
|
||||||
assert_refnode(refnodes[2], None, 'NestedParentA', 'child_1', 'meth')
|
assert_refnode(refnodes[2], None, 'NestedParentA', 'child_1', 'meth')
|
||||||
@ -97,7 +97,7 @@ def test_domain_py_xrefs(app, status, warning):
|
|||||||
assert len(refnodes) == 13
|
assert len(refnodes) == 13
|
||||||
|
|
||||||
doctree = app.env.get_doctree('module')
|
doctree = app.env.get_doctree('module')
|
||||||
refnodes = list(doctree.traverse(pending_xref))
|
refnodes = list(doctree.findall(pending_xref))
|
||||||
assert_refnode(refnodes[0], 'module_a.submodule', None,
|
assert_refnode(refnodes[0], 'module_a.submodule', None,
|
||||||
'ModTopLevel', 'class')
|
'ModTopLevel', 'class')
|
||||||
assert_refnode(refnodes[1], 'module_a.submodule', 'ModTopLevel',
|
assert_refnode(refnodes[1], 'module_a.submodule', 'ModTopLevel',
|
||||||
@ -126,7 +126,7 @@ def test_domain_py_xrefs(app, status, warning):
|
|||||||
assert len(refnodes) == 16
|
assert len(refnodes) == 16
|
||||||
|
|
||||||
doctree = app.env.get_doctree('module_option')
|
doctree = app.env.get_doctree('module_option')
|
||||||
refnodes = list(doctree.traverse(pending_xref))
|
refnodes = list(doctree.findall(pending_xref))
|
||||||
print(refnodes)
|
print(refnodes)
|
||||||
print(refnodes[0])
|
print(refnodes[0])
|
||||||
print(refnodes[1])
|
print(refnodes[1])
|
||||||
|
@ -36,7 +36,7 @@ def test_process_doc_handle_figure_caption():
|
|||||||
ids={'testid': figure_node},
|
ids={'testid': figure_node},
|
||||||
citation_refs={},
|
citation_refs={},
|
||||||
)
|
)
|
||||||
document.traverse.return_value = []
|
document.findall.return_value = []
|
||||||
|
|
||||||
domain = StandardDomain(env)
|
domain = StandardDomain(env)
|
||||||
if 'testname' in domain.data['labels']:
|
if 'testname' in domain.data['labels']:
|
||||||
@ -60,7 +60,7 @@ def test_process_doc_handle_table_title():
|
|||||||
ids={'testid': table_node},
|
ids={'testid': table_node},
|
||||||
citation_refs={},
|
citation_refs={},
|
||||||
)
|
)
|
||||||
document.traverse.return_value = []
|
document.findall.return_value = []
|
||||||
|
|
||||||
domain = StandardDomain(env)
|
domain = StandardDomain(env)
|
||||||
if 'testname' in domain.data['labels']:
|
if 'testname' in domain.data['labels']:
|
||||||
|
@ -67,7 +67,7 @@ def parse(new_document):
|
|||||||
parser = RstParser()
|
parser = RstParser()
|
||||||
parser.parse(rst, document)
|
parser.parse(rst, document)
|
||||||
SphinxSmartQuotes(document, startnode=None).apply()
|
SphinxSmartQuotes(document, startnode=None).apply()
|
||||||
for msg in document.traverse(nodes.system_message):
|
for msg in list(document.findall(nodes.system_message)):
|
||||||
if msg['level'] == 1:
|
if msg['level'] == 1:
|
||||||
msg.replace_self([])
|
msg.replace_self([])
|
||||||
return document
|
return document
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from html5lib import HTMLParser
|
from html5lib import HTMLParser
|
||||||
|
|
||||||
|
from sphinx.util import docutils
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
||||||
def test_basic(app, status, warning):
|
def test_basic(app, status, warning):
|
||||||
@ -51,7 +53,10 @@ def test_man_builder(app, status, warning):
|
|||||||
app.build()
|
app.build()
|
||||||
|
|
||||||
content = (app.outdir / 'python.1').read_text()
|
content = (app.outdir / 'python.1').read_text()
|
||||||
assert '\\-\\- "Sphinx" is a tool that makes it easy ...' in content
|
if docutils.__version_info__ > (0, 18):
|
||||||
|
assert r'\-\- \(dqSphinx\(dq is a tool that makes it easy ...' in content
|
||||||
|
else:
|
||||||
|
assert r'\-\- "Sphinx" is a tool that makes it easy ...' in content
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(buildername='latex', testroot='smartquotes', freshenv=True)
|
@pytest.mark.sphinx(buildername='latex', testroot='smartquotes', freshenv=True)
|
||||||
|
@ -60,31 +60,31 @@ def test_NodeMatcher():
|
|||||||
|
|
||||||
# search by node class
|
# search by node class
|
||||||
matcher = NodeMatcher(nodes.paragraph)
|
matcher = NodeMatcher(nodes.paragraph)
|
||||||
assert len(list(doctree.traverse(matcher))) == 3
|
assert len(list(doctree.findall(matcher))) == 3
|
||||||
|
|
||||||
# search by multiple node classes
|
# search by multiple node classes
|
||||||
matcher = NodeMatcher(nodes.paragraph, nodes.literal_block)
|
matcher = NodeMatcher(nodes.paragraph, nodes.literal_block)
|
||||||
assert len(list(doctree.traverse(matcher))) == 4
|
assert len(list(doctree.findall(matcher))) == 4
|
||||||
|
|
||||||
# search by node attribute
|
# search by node attribute
|
||||||
matcher = NodeMatcher(block=1)
|
matcher = NodeMatcher(block=1)
|
||||||
assert len(list(doctree.traverse(matcher))) == 1
|
assert len(list(doctree.findall(matcher))) == 1
|
||||||
|
|
||||||
# search by node attribute (Any)
|
# search by node attribute (Any)
|
||||||
matcher = NodeMatcher(block=Any)
|
matcher = NodeMatcher(block=Any)
|
||||||
assert len(list(doctree.traverse(matcher))) == 3
|
assert len(list(doctree.findall(matcher))) == 3
|
||||||
|
|
||||||
# search by both class and attribute
|
# search by both class and attribute
|
||||||
matcher = NodeMatcher(nodes.paragraph, block=Any)
|
matcher = NodeMatcher(nodes.paragraph, block=Any)
|
||||||
assert len(list(doctree.traverse(matcher))) == 2
|
assert len(list(doctree.findall(matcher))) == 2
|
||||||
|
|
||||||
# mismatched
|
# mismatched
|
||||||
matcher = NodeMatcher(nodes.title)
|
matcher = NodeMatcher(nodes.title)
|
||||||
assert len(list(doctree.traverse(matcher))) == 0
|
assert len(list(doctree.findall(matcher))) == 0
|
||||||
|
|
||||||
# search with Any does not match to Text node
|
# search with Any does not match to Text node
|
||||||
matcher = NodeMatcher(blah=Any)
|
matcher = NodeMatcher(blah=Any)
|
||||||
assert len(list(doctree.traverse(matcher))) == 0
|
assert len(list(doctree.findall(matcher))) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
@ -70,16 +70,16 @@ def test_picklablility():
|
|||||||
copy.settings.warning_stream = None
|
copy.settings.warning_stream = None
|
||||||
copy.settings.env = None
|
copy.settings.env = None
|
||||||
copy.settings.record_dependencies = None
|
copy.settings.record_dependencies = None
|
||||||
for metanode in copy.traverse(meta):
|
for metanode in copy.findall(meta):
|
||||||
metanode.__class__ = addnodes.meta
|
metanode.__class__ = addnodes.meta
|
||||||
loaded = pickle.loads(pickle.dumps(copy, pickle.HIGHEST_PROTOCOL))
|
loaded = pickle.loads(pickle.dumps(copy, pickle.HIGHEST_PROTOCOL))
|
||||||
assert all(getattr(n, 'uid', False) for n in loaded.traverse(is_paragraph))
|
assert all(getattr(n, 'uid', False) for n in loaded.findall(is_paragraph))
|
||||||
|
|
||||||
|
|
||||||
def test_modified():
|
def test_modified():
|
||||||
modified = doctrees['modified']
|
modified = doctrees['modified']
|
||||||
new_nodes = list(merge_doctrees(original, modified, is_paragraph))
|
new_nodes = list(merge_doctrees(original, modified, is_paragraph))
|
||||||
uids = [n.uid for n in modified.traverse(is_paragraph)]
|
uids = [n.uid for n in modified.findall(is_paragraph)]
|
||||||
assert not new_nodes
|
assert not new_nodes
|
||||||
assert original_uids == uids
|
assert original_uids == uids
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ def test_modified():
|
|||||||
def test_added():
|
def test_added():
|
||||||
added = doctrees['added']
|
added = doctrees['added']
|
||||||
new_nodes = list(merge_doctrees(original, added, is_paragraph))
|
new_nodes = list(merge_doctrees(original, added, is_paragraph))
|
||||||
uids = [n.uid for n in added.traverse(is_paragraph)]
|
uids = [n.uid for n in added.findall(is_paragraph)]
|
||||||
assert len(new_nodes) == 1
|
assert len(new_nodes) == 1
|
||||||
assert original_uids == uids[:-1]
|
assert original_uids == uids[:-1]
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ def test_added():
|
|||||||
def test_deleted():
|
def test_deleted():
|
||||||
deleted = doctrees['deleted']
|
deleted = doctrees['deleted']
|
||||||
new_nodes = list(merge_doctrees(original, deleted, is_paragraph))
|
new_nodes = list(merge_doctrees(original, deleted, is_paragraph))
|
||||||
uids = [n.uid for n in deleted.traverse(is_paragraph)]
|
uids = [n.uid for n in deleted.findall(is_paragraph)]
|
||||||
assert not new_nodes
|
assert not new_nodes
|
||||||
assert original_uids[::2] == uids
|
assert original_uids[::2] == uids
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ def test_deleted():
|
|||||||
def test_deleted_end():
|
def test_deleted_end():
|
||||||
deleted_end = doctrees['deleted_end']
|
deleted_end = doctrees['deleted_end']
|
||||||
new_nodes = list(merge_doctrees(original, deleted_end, is_paragraph))
|
new_nodes = list(merge_doctrees(original, deleted_end, is_paragraph))
|
||||||
uids = [n.uid for n in deleted_end.traverse(is_paragraph)]
|
uids = [n.uid for n in deleted_end.findall(is_paragraph)]
|
||||||
assert not new_nodes
|
assert not new_nodes
|
||||||
assert original_uids[:-1] == uids
|
assert original_uids[:-1] == uids
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ def test_deleted_end():
|
|||||||
def test_insert():
|
def test_insert():
|
||||||
insert = doctrees['insert']
|
insert = doctrees['insert']
|
||||||
new_nodes = list(merge_doctrees(original, insert, is_paragraph))
|
new_nodes = list(merge_doctrees(original, insert, is_paragraph))
|
||||||
uids = [n.uid for n in insert.traverse(is_paragraph)]
|
uids = [n.uid for n in insert.findall(is_paragraph)]
|
||||||
assert len(new_nodes) == 1
|
assert len(new_nodes) == 1
|
||||||
assert original_uids[0] == uids[0]
|
assert original_uids[0] == uids[0]
|
||||||
assert original_uids[1:] == uids[2:]
|
assert original_uids[1:] == uids[2:]
|
||||||
@ -120,7 +120,7 @@ def test_insert():
|
|||||||
def test_insert_beginning():
|
def test_insert_beginning():
|
||||||
insert_beginning = doctrees['insert_beginning']
|
insert_beginning = doctrees['insert_beginning']
|
||||||
new_nodes = list(merge_doctrees(original, insert_beginning, is_paragraph))
|
new_nodes = list(merge_doctrees(original, insert_beginning, is_paragraph))
|
||||||
uids = [n.uid for n in insert_beginning.traverse(is_paragraph)]
|
uids = [n.uid for n in insert_beginning.findall(is_paragraph)]
|
||||||
assert len(new_nodes) == 1
|
assert len(new_nodes) == 1
|
||||||
assert len(uids) == 4
|
assert len(uids) == 4
|
||||||
assert original_uids == uids[1:]
|
assert original_uids == uids[1:]
|
||||||
@ -130,7 +130,7 @@ def test_insert_beginning():
|
|||||||
def test_insert_similar():
|
def test_insert_similar():
|
||||||
insert_similar = doctrees['insert_similar']
|
insert_similar = doctrees['insert_similar']
|
||||||
new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph))
|
new_nodes = list(merge_doctrees(original, insert_similar, is_paragraph))
|
||||||
uids = [n.uid for n in insert_similar.traverse(is_paragraph)]
|
uids = [n.uid for n in insert_similar.findall(is_paragraph)]
|
||||||
assert len(new_nodes) == 1
|
assert len(new_nodes) == 1
|
||||||
assert new_nodes[0].rawsource == 'Anyway I need more'
|
assert new_nodes[0].rawsource == 'Anyway I need more'
|
||||||
assert original_uids[0] == uids[0]
|
assert original_uids[0] == uids[0]
|
||||||
|
4
tox.ini
4
tox.ini
@ -32,9 +32,7 @@ commands=
|
|||||||
|
|
||||||
[testenv:du-latest]
|
[testenv:du-latest]
|
||||||
commands =
|
commands =
|
||||||
git clone https://repo.or.cz/docutils.git {temp_dir}/docutils
|
python -m pip install "git+https://repo.or.cz/docutils.git#subdirectory=docutils"
|
||||||
python -m pip install {temp_dir}/docutils/docutils
|
|
||||||
rm -rf {temp_dir}/docutils
|
|
||||||
{[testenv]commands}
|
{[testenv]commands}
|
||||||
|
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
|
Loading…
Reference in New Issue
Block a user