Skip to content

Commit

Permalink
Merge pull request sphinx-doc#7099 from tk0miya/6581_latex_reversed_t…
Browse files Browse the repository at this point in the history
…octree

Fix sphinx-doc#6581: :reversed: for toctree does not effect to LaTeX build
  • Loading branch information
tk0miya committed Feb 7, 2020
2 parents bab2134 + 753080a commit 1a52381
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Bugs fixed
* #6906, #6907: autodoc: failed to read the source codes encoeded in cp1251
* #6961: latex: warning for babel shown twice
* #7059: latex: LaTeX compilation falls into infinite loop (wrapfig issue)
* #6581: latex: ``:reversed:`` option for toctree does not effect to LaTeX build
* #6559: Wrong node-ids are generated in glossary directive
* #6986: apidoc: misdetects module name for .so file inside module
* #6899: apidoc: private members are not shown even if ``--private`` given
Expand Down
1 change: 1 addition & 0 deletions sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def parse_content(self, toctree):
# entries contains all entries (self references, external links etc.)
if 'reversed' in self.options:
toctree['entries'] = list(reversed(toctree['entries']))
toctree['includefiles'] = list(reversed(toctree['includefiles']))

return ret

Expand Down
17 changes: 17 additions & 0 deletions tests/test_directive_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ def test_toctree_glob_and_url(app):
includefiles=[])


@pytest.mark.sphinx(testroot='toctree-glob')
def test_reversed_toctree(app):
text = (".. toctree::\n"
" :reversed:\n"
"\n"
" foo\n"
" bar/index\n"
" baz\n")

app.env.find_files(app.config, app.builder)
doctree = restructuredtext.parse(app, text, 'index')
assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree])
assert_node(doctree[0][0],
entries=[(None, 'baz'), (None, 'bar/index'), (None, 'foo')],
includefiles=['baz', 'bar/index', 'foo'])


@pytest.mark.sphinx(testroot='toctree-glob')
def test_toctree_twice(app):
text = (".. toctree::\n"
Expand Down
6 changes: 2 additions & 4 deletions tests/test_environment_toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,14 @@ def test_glob(app):
[bullet_list, addnodes.toctree])]) # [0][1][1][1][0]
assert_node(toctree[0][1][1][1][0], addnodes.toctree, caption=None,
glob=True, hidden=False, titlesonly=False,
maxdepth=-1, numbered=0, includefiles=includefiles,
maxdepth=-1, numbered=0, includefiles=list(reversed(includefiles)),
entries=[(None, 'qux/index'), (None, 'baz'), (None, 'bar/bar_3'),
(None, 'bar/bar_2'), (None, 'bar/bar_1'), (None, 'bar/index'),
(None, 'foo')])
includefiles = ['foo', 'bar/index', 'bar/bar_1', 'bar/bar_2',
'bar/bar_3', 'baz', 'qux/index']

# other collections
assert app.env.toc_num_entries['index'] == 3
assert app.env.toctree_includes['index'] == includefiles + includefiles
assert app.env.toctree_includes['index'] == includefiles + list(reversed(includefiles))
for file in includefiles:
assert 'index' in app.env.files_to_rebuild[file]
assert 'index' in app.env.glob_toctrees
Expand Down

0 comments on commit 1a52381

Please sign in to comment.