summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-14 11:40:50 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-14 13:33:12 +0900
commitfaedcc48ccb942b9a7b758b699b30f0d026c0771 (patch)
treeea3669f2656676fd4d4bda9691b324129202a3aa
parent1a54a7229c37dd7618033552d5893e6a429d2bc3 (diff)
downloadsphinx-git-faedcc48ccb942b9a7b758b699b30f0d026c0771.tar.gz
Fix #6887: Sphinx crashes with docutils-0.16b0
-rw-r--r--.travis.yml3
-rw-r--r--CHANGES1
-rw-r--r--sphinx/builders/latex/__init__.py11
-rw-r--r--sphinx/domains/std.py12
-rw-r--r--sphinx/util/nodes.py2
-rw-r--r--tests/test_directive_code.py2
-rw-r--r--tox.ini1
7 files changed, 16 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml
index b145ceb8a..008f4e442 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,7 +25,8 @@ matrix:
- TOXENV=du15
- PYTEST_ADDOPTS="--cov ./ --cov-append --cov-config setup.cfg"
- python: 'nightly'
- env: TOXENV=py38
+ env:
+ - TOXENV=du16
- python: '3.6'
env: TOXENV=docs
- python: '3.6'
diff --git a/CHANGES b/CHANGES
index 3692108a3..65b8e47c4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -84,6 +84,7 @@ Bugs fixed
* #6886: LaTeX: xelatex converts straight double quotes into right curly ones
(shows when :confval:`smartquotes` is ``False``)
* #6876: LaTeX: multi-line display of authors on title page has ragged edges
+* #6887: Sphinx crashes with docutils-0.16b0
Testing
--------
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index c24e87a13..6a0d70e5e 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -234,14 +234,13 @@ class LaTeXBuilder(Builder):
destination = SphinxFileOutput(destination_path=path.join(self.outdir, targetname),
encoding='utf-8', overwrite_if_changed=True)
with progress_message(__("processing %s") % targetname):
- toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
- if toctrees:
- if toctrees[0].get('maxdepth') > 0:
- tocdepth = toctrees[0].get('maxdepth')
- else:
- tocdepth = None
+ doctree = self.env.get_doctree(docname)
+ toctree = next(iter(doctree.traverse(addnodes.toctree)), None)
+ if toctree and toctree.get('maxdepth') > 0:
+ tocdepth = toctree.get('maxdepth')
else:
tocdepth = None
+
doctree = self.assemble_doctree(
docname, toctree_only,
appendices=((docclass != 'howto') and self.config.latex_appendices or []))
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 98dda4918..705cf175c 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -612,15 +612,13 @@ class StandardDomain(Domain):
sectname = self.get_numfig_title(node)
if not sectname:
continue
- elif node.traverse(addnodes.toctree):
- n = node.traverse(addnodes.toctree)[0]
- if n.get('caption'):
- sectname = n['caption']
+ else:
+ toctree = next(iter(node.traverse(addnodes.toctree)), None)
+ if toctree and toctree.get('caption'):
+ sectname = toctree.get('caption')
else:
+ # anonymous-only labels
continue
- else:
- # anonymous-only labels
- continue
self.labels[name] = docname, labelid, sectname
def add_object(self, objtype: str, name: str, docname: str, labelid: str) -> None:
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index 52e43c2e2..53b4d056e 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -148,7 +148,7 @@ def apply_source_workaround(node: Element) -> None:
logger.debug('[i18n] PATCH: %r to have rawsource: %s',
get_full_module_name(node), repr_domxml(node))
# strip classifier from rawsource of term
- for classifier in reversed(node.parent.traverse(nodes.classifier)):
+ for classifier in reversed(list(node.parent.traverse(nodes.classifier))):
node.rawsource = re.sub(r'\s*:\s*%s' % re.escape(classifier.astext()),
'', node.rawsource)
diff --git a/tests/test_directive_code.py b/tests/test_directive_code.py
index ecf5423c2..5d93449f1 100644
--- a/tests/test_directive_code.py
+++ b/tests/test_directive_code.py
@@ -573,7 +573,7 @@ def test_literalinclude_pydecorators(app, status, warning):
def test_code_block_highlighted(app, status, warning):
app.builder.build(['highlight'])
doctree = app.env.get_doctree('highlight')
- codeblocks = doctree.traverse(nodes.literal_block)
+ codeblocks = list(doctree.traverse(nodes.literal_block))
assert codeblocks[0]['language'] == 'default'
assert codeblocks[1]['language'] == 'python2'
diff --git a/tox.ini b/tox.ini
index c4ffe33cb..5bc2dec58 100644
--- a/tox.ini
+++ b/tox.ini
@@ -14,6 +14,7 @@ deps =
du13: docutils==0.13.1
du14: docutils==0.14
du15: docutils==0.15
+ du16: docutils==0.16b0.dev0
extras =
test
setenv =