From a9657b4579b53710e838b48e3c78b30a2b22b991 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 1 Jun 2018 12:44:53 +0900 Subject: [PATCH 01/10] Fix #5016: ``character_level_inline_markup`` setting is not initialized --- CHANGES | 4 ++++ sphinx/environment/__init__.py | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index bca34a529..0f26145e7 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,10 @@ Features added Bugs fixed ---------- +* #5016: ``character_level_inline_markup`` setting is not initialized for + combination of non reST source parsers (ex. recommonmark) and docutils-0.13 + + Testing -------- diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index 86d69cc3a..dee74830d 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -66,6 +66,7 @@ default_settings = { 'halt_level': 5, 'file_insertion_enabled': True, 'smartquotes_locales': [], + 'character_level_inline_markup': False, # for docutils-0.13.1 or older } # This is increased every time an environment attribute is added From 88cbd6a5975ce089de9f85b9bec3820aad9b37f7 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 5 Jun 2018 18:43:19 +0200 Subject: [PATCH 02/10] Update CHANGES for PR #5040 --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index bca34a529..d8f7b4b1b 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian + Testing -------- From 96b9b9a127646c51e4bb8db980d528802a6ba652 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 7 Jun 2018 00:54:02 +0900 Subject: [PATCH 03/10] Fix #5048: crashed with numbered toctree --- CHANGES | 1 + sphinx/environment/collectors/toctree.py | 9 +++++---- tests/test_toctree.py | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index d8f7b4b1b..a573d9ae5 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Bugs fixed ---------- * #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian +* #5048: crashed with numbered toctree Testing -------- diff --git a/sphinx/environment/collectors/toctree.py b/sphinx/environment/collectors/toctree.py index c8b00c900..35f19b18a 100644 --- a/sphinx/environment/collectors/toctree.py +++ b/sphinx/environment/collectors/toctree.py @@ -165,13 +165,14 @@ class TocTreeCollector(EnvironmentCollector): elif isinstance(subnode, addnodes.compact_paragraph): numstack[-1] += 1 if depth > 0: - number = tuple(numstack) + number = list(numstack) + secnums[subnode[0]['anchorname']] = tuple(numstack) else: number = None - secnums[subnode[0]['anchorname']] = number - subnode[0]['secnumber'] = list(number) + secnums[subnode[0]['anchorname']] = None + subnode[0]['secnumber'] = number if titlenode: - titlenode['secnumber'] = list(number) + titlenode['secnumber'] = number titlenode = None elif isinstance(subnode, addnodes.toctree): _walk_toctree(subnode, depth) diff --git a/tests/test_toctree.py b/tests/test_toctree.py index 42ec0ce89..e37862ae0 100644 --- a/tests/test_toctree.py +++ b/tests/test_toctree.py @@ -8,6 +8,8 @@ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import re + import pytest @@ -35,3 +37,12 @@ def test_singlehtml_toctree(app, status, warning): app.builder._get_local_toctree('index') except AttributeError: pytest.fail('Unexpected AttributeError in app.builder.fix_refuris') + + +@pytest.mark.sphinx(testroot='toctree', srcdir="numbered-toctree") +def test_numbered_toctree(app, status, warning): + # give argument to :numbered: option + index = (app.srcdir / 'index.rst').text() + index = re.sub(':numbered:.*', ':numbered: 1', index) + (app.srcdir / 'index.rst').write_text(index, encoding='utf-8') + app.builder.build_all() From fb41dcefab5e00ab8022f543bfc84f111b7a38b5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 1 Jun 2018 14:39:43 +0900 Subject: [PATCH 04/10] Fix sphinx.testing uses deprecated pytest API; Node.get_marker(name) --- CHANGES | 1 + sphinx/testing/fixtures.py | 10 ++++++++-- tests/test_ext_apidoc.py | 5 ++++- tests/test_setup_command.py | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index d8f7b4b1b..0c049318d 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Bugs fixed ---------- * #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian +* sphinx.testing uses deprecated pytest API; ``Node.get_marker(name)`` Testing -------- diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index be0037b70..741dbb353 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -39,7 +39,10 @@ def app_params(request, test_params, shared_result, sphinx_test_tempdir, rootdir # ##### process pytest.mark.sphinx - markers = request.node.get_marker("sphinx") + if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer + markers = request.node.iter_markers("sphinx") + else: + markers = request.node.get_marker("sphinx") pargs = {} kwargs = {} # type: Dict[str, str] @@ -86,7 +89,10 @@ def test_params(request): have same 'shared_result' value. **NOTE**: You can not specify shared_result and srcdir in same time. """ - env = request.node.get_marker('test_params') + if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer + env = request.node.get_closest_marker('test_params') + else: + env = request.node.get_marker('test_params') kwargs = env.kwargs if env else {} result = { 'shared_result': None, diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py index d3d61d1e0..8c81a6e12 100644 --- a/tests/test_ext_apidoc.py +++ b/tests/test_ext_apidoc.py @@ -32,7 +32,10 @@ def apidoc(rootdir, tempdir, apidoc_params): @pytest.fixture def apidoc_params(request): - markers = request.node.get_marker("apidoc") + if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer + markers = request.node.iter_markers("apidoc") + else: + markers = request.node.get_marker("apidoc") pargs = {} kwargs = {} diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index facb8879d..cd1f89c0c 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -27,7 +27,10 @@ def setup_command(request, tempdir, rootdir): Run `setup.py build_sphinx` with args and kwargs, pass it to the test and clean up properly. """ - marker = request.node.get_marker('setup_command') + if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer + marker = request.node.get_closest_marker('setup_command') + else: + marker = request.node.get_marker('setup_command') args = marker.args if marker else [] pkgrootdir = tempdir / 'test-setup' From b9d06fd80217ab8f9f47da0c4f5aa6980423fe73 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 7 Jun 2018 21:54:03 +0900 Subject: [PATCH 05/10] Fix #5016: crashed when recommonmark.AutoStrictify is enabled --- CHANGES | 3 +-- sphinx/environment/__init__.py | 1 - sphinx/io.py | 8 ++++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 14272aeb1..73662360b 100644 --- a/CHANGES +++ b/CHANGES @@ -18,8 +18,7 @@ Bugs fixed * #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian * sphinx.testing uses deprecated pytest API; ``Node.get_marker(name)`` -* #5016: ``character_level_inline_markup`` setting is not initialized for - combination of non reST source parsers (ex. recommonmark) and docutils-0.13 +* #5016: crashed when recommonmark.AutoStrictify is enabled Testing -------- diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index dee74830d..86d69cc3a 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -66,7 +66,6 @@ default_settings = { 'halt_level': 5, 'file_insertion_enabled': True, 'smartquotes_locales': [], - 'character_level_inline_markup': False, # for docutils-0.13.1 or older } # This is increased every time an environment attribute is added diff --git a/sphinx/io.py b/sphinx/io.py index 8f1da22bd..4cb59c90e 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -13,6 +13,7 @@ import re from docutils.core import Publisher from docutils.io import FileInput, NullOutput +from docutils.parsers.rst import Parser as RSTParser from docutils.readers import standalone from docutils.statemachine import StringList, string2lines from docutils.writers import UnfilteredWriter @@ -282,6 +283,13 @@ def read_doc(app, env, filename): source = input_class(app, env, source=None, source_path=filename, encoding=env.config.source_encoding) parser = app.registry.create_source_parser(app, filename) + if parser.__class__.__name__ == 'CommonMarkParser' and parser.settings_spec == (): + # a workaround for recommonmark + # If recommonmark.AutoStrictify is enabled, the parser invokes reST parser + # internally. But recommonmark-0.4.0 does not provide settings_spec for reST + # parser. As a workaround, this copies settings_spec for RSTParser to the + # CommonMarkParser. + parser.settings_spec = RSTParser.settings_spec pub = Publisher(reader=reader, parser=parser, From 49ab23db0b68e590b2c98a9c1390cda3dc7a514d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 31 May 2018 12:39:17 +0900 Subject: [PATCH 06/10] Fix #5022: latex: crashed with docutils package provided by Debian/Ubuntu --- CHANGES | 1 + sphinx/writers/latex.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 14272aeb1..dcb1b581e 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Bugs fixed * sphinx.testing uses deprecated pytest API; ``Node.get_marker(name)`` * #5016: ``character_level_inline_markup`` setting is not initialized for combination of non reST source parsers (ex. recommonmark) and docutils-0.13 +* #5022: latex: crashed with docutils package provided by Debian/Ubuntu Testing -------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 0e5462ea2..941181d0a 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -18,7 +18,6 @@ from collections import defaultdict from os import path from docutils import nodes, writers -from docutils.utils.roman import toRoman from docutils.writers.latex2e import Babel from six import itervalues, text_type @@ -32,6 +31,12 @@ from sphinx.util.nodes import clean_astext from sphinx.util.template import LaTeXRenderer from sphinx.util.texescape import tex_escape_map, tex_replace_map +try: + from docutils.utils.roman import toRoman +except ImportError: + # In Debain/Ubuntu, roman package is provided as roman, not as docutils.utils.roman + from roman import toRoman + if False: # For type annotation from typing import Any, Callable, Dict, Iterator, List, Pattern, Tuple, Set, Union # NOQA From 7416e9907cb7da824374728c7567c9ec79ce54ac Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 24 May 2018 23:22:30 +0900 Subject: [PATCH 07/10] Fix #5009: latex: a label for table is vanished if table does not have a caption --- CHANGES | 1 + sphinx/templates/latex/longtable.tex_t | 6 +++++- sphinx/templates/latex/tabular.tex_t | 2 ++ sphinx/templates/latex/tabulary.tex_t | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index dcb1b581e..a436038eb 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,7 @@ Bugs fixed * #5016: ``character_level_inline_markup`` setting is not initialized for combination of non reST source parsers (ex. recommonmark) and docutils-0.13 * #5022: latex: crashed with docutils package provided by Debian/Ubuntu +* #5009: latex: a label for table is vanished if table does not have a caption Testing -------- diff --git a/sphinx/templates/latex/longtable.tex_t b/sphinx/templates/latex/longtable.tex_t index b7310a780..9b8c46d81 100644 --- a/sphinx/templates/latex/longtable.tex_t +++ b/sphinx/templates/latex/longtable.tex_t @@ -9,8 +9,12 @@ <%= table.get_colspec() %> <%- if table.caption -%> \caption{<%= ''.join(table.caption) %>\strut}<%= labels %>\\*[\sphinxlongtablecapskipadjust] -<% endif -%> \hline +<% elif labels -%> +\hline\noalign{\phantomsection<%= labels %>}% +<% else -%> +\hline +<% endif -%> <%= ''.join(table.header) %> \endfirsthead diff --git a/sphinx/templates/latex/tabular.tex_t b/sphinx/templates/latex/tabular.tex_t index 3fd347e53..26e4ff107 100644 --- a/sphinx/templates/latex/tabular.tex_t +++ b/sphinx/templates/latex/tabular.tex_t @@ -14,6 +14,8 @@ \sphinxcapstartof{table} \sphinxcaption{<%= ''.join(table.caption) %>}<%= labels %> \sphinxaftercaption +<% elif labels -%> +\phantomsection<%= labels %> <% endif -%> \begin{tabular}[t]<%= table.get_colspec() -%> \hline diff --git a/sphinx/templates/latex/tabulary.tex_t b/sphinx/templates/latex/tabulary.tex_t index 16d15192b..385076529 100644 --- a/sphinx/templates/latex/tabulary.tex_t +++ b/sphinx/templates/latex/tabulary.tex_t @@ -14,6 +14,8 @@ \sphinxcapstartof{table} \sphinxcaption{<%= ''.join(table.caption) %>}<%= labels %> \sphinxaftercaption +<% elif labels -%> +\phantomsection<%= labels %> <% endif -%> \begin{tabulary}{\linewidth}[t]<%= table.get_colspec() -%> \hline From 7bebdd0f973b3a9e06804005736c5645a87b6b5e Mon Sep 17 00:00:00 2001 From: jfbu Date: Fri, 8 Jun 2018 10:18:53 +0200 Subject: [PATCH 08/10] Add tests for non-captioned table with label in latex --- .../test-latex-table/expects/longtable_having_widths.tex | 4 +++- .../roots/test-latex-table/expects/table_having_widths.tex | 3 +++ tests/roots/test-latex-table/longtable.rst | 5 +++++ tests/roots/test-latex-table/tabular.rst | 7 ++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/roots/test-latex-table/expects/longtable_having_widths.tex b/tests/roots/test-latex-table/expects/longtable_having_widths.tex index d41a87586..505ae4d70 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_widths.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_widths.tex @@ -1,7 +1,7 @@ \label{\detokenize{longtable:longtable-having-widths-option}} \begin{savenotes}\sphinxatlongtablestart\begin{longtable}{|\X{30}{100}|\X{70}{100}|} -\hline +\hline\noalign{\phantomsection\label{\detokenize{longtable:namedlongtable}}\label{\detokenize{longtable:mylongtable}}}% \sphinxstyletheadfamily header1 &\sphinxstyletheadfamily @@ -43,3 +43,5 @@ cell3-2 \\ \hline \end{longtable}\sphinxatlongtableend\end{savenotes} + +See {\hyperref[\detokenize{longtable:mylongtable}]{\sphinxcrossref{mylongtable}}}, same as {\hyperref[\detokenize{longtable:namedlongtable}]{\sphinxcrossref{\DUrole{std,std-ref}{this one}}}}. diff --git a/tests/roots/test-latex-table/expects/table_having_widths.tex b/tests/roots/test-latex-table/expects/table_having_widths.tex index 914793181..5a69d5b22 100644 --- a/tests/roots/test-latex-table/expects/table_having_widths.tex +++ b/tests/roots/test-latex-table/expects/table_having_widths.tex @@ -2,6 +2,7 @@ \begin{savenotes}\sphinxattablestart \centering +\phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}} \begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|} \hline \sphinxstyletheadfamily @@ -28,3 +29,5 @@ cell3-2 \end{tabular} \par \sphinxattableend\end{savenotes} + +See {\hyperref[\detokenize{tabular:mytabular}]{\sphinxcrossref{\DUrole{std,std-ref}{this}}}}, same as {\hyperref[\detokenize{tabular:namedtabular}]{\sphinxcrossref{namedtabular}}}. diff --git a/tests/roots/test-latex-table/longtable.rst b/tests/roots/test-latex-table/longtable.rst index 370226f21..bace9d4d2 100644 --- a/tests/roots/test-latex-table/longtable.rst +++ b/tests/roots/test-latex-table/longtable.rst @@ -18,9 +18,12 @@ longtable longtable having :widths: option -------------------------------- +.. _mylongtable: + .. table:: :class: longtable :widths: 30,70 + :name: namedlongtable ======= ======= header1 header2 @@ -30,6 +33,8 @@ longtable having :widths: option cell3-1 cell3-2 ======= ======= +See mylongtable_, same as :ref:`this one `. + longtable having :align: option ------------------------------- diff --git a/tests/roots/test-latex-table/tabular.rst b/tests/roots/test-latex-table/tabular.rst index b28add3d3..7f0909540 100644 --- a/tests/roots/test-latex-table/tabular.rst +++ b/tests/roots/test-latex-table/tabular.rst @@ -1,4 +1,4 @@ -taburar and taburary +tabular and tabulary ==================== simple table @@ -15,8 +15,11 @@ cell3-1 cell3-2 table having :widths: option ---------------------------- +.. _mytabular: + .. table:: :widths: 30,70 + :name: namedtabular ======= ======= header1 header2 @@ -26,6 +29,8 @@ table having :widths: option cell3-1 cell3-2 ======= ======= +See :ref:`this `, same as namedtabular_. + table having :align: option (tabulary) -------------------------------------- From 45c63a8e2df9f0da6520fd3b4c8bf259fc9c4361 Mon Sep 17 00:00:00 2001 From: jfbu Date: Fri, 8 Jun 2018 18:45:29 +0200 Subject: [PATCH 09/10] LaTeX, follow-up to PR #5012, avoid label separated by pagebreak PR #5012 took care of this for longtable, but the problem can also arise with tabular/tabulary and is much easier to fix. --- sphinx/templates/latex/tabular.tex_t | 2 +- sphinx/templates/latex/tabulary.tex_t | 2 +- tests/roots/test-latex-table/expects/table_having_widths.tex | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx/templates/latex/tabular.tex_t b/sphinx/templates/latex/tabular.tex_t index 26e4ff107..67d71c985 100644 --- a/sphinx/templates/latex/tabular.tex_t +++ b/sphinx/templates/latex/tabular.tex_t @@ -15,7 +15,7 @@ \sphinxcaption{<%= ''.join(table.caption) %>}<%= labels %> \sphinxaftercaption <% elif labels -%> -\phantomsection<%= labels %> +\phantomsection<%= labels %>\nobreak <% endif -%> \begin{tabular}[t]<%= table.get_colspec() -%> \hline diff --git a/sphinx/templates/latex/tabulary.tex_t b/sphinx/templates/latex/tabulary.tex_t index 385076529..4d3571a7b 100644 --- a/sphinx/templates/latex/tabulary.tex_t +++ b/sphinx/templates/latex/tabulary.tex_t @@ -15,7 +15,7 @@ \sphinxcaption{<%= ''.join(table.caption) %>}<%= labels %> \sphinxaftercaption <% elif labels -%> -\phantomsection<%= labels %> +\phantomsection<%= labels %>\nobreak <% endif -%> \begin{tabulary}{\linewidth}[t]<%= table.get_colspec() -%> \hline diff --git a/tests/roots/test-latex-table/expects/table_having_widths.tex b/tests/roots/test-latex-table/expects/table_having_widths.tex index 5a69d5b22..b4fcea04e 100644 --- a/tests/roots/test-latex-table/expects/table_having_widths.tex +++ b/tests/roots/test-latex-table/expects/table_having_widths.tex @@ -2,7 +2,7 @@ \begin{savenotes}\sphinxattablestart \centering -\phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}} +\phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}}\nobreak \begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|} \hline \sphinxstyletheadfamily From 6d739017c3edffef3cab04df722ef598f1081784 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 9 Jun 2018 14:15:54 +0900 Subject: [PATCH 10/10] Fix mypy violation --- sphinx/directives/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index ae67cf4c6..2f232a666 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -240,7 +240,7 @@ class LiteralIncludeReader(object): new_lines = self.read_file(self.filename) old_filename = self.options.get('diff') old_lines = self.read_file(old_filename) - diff = unified_diff(old_lines, new_lines, old_filename, self.filename) # type: ignore + diff = unified_diff(old_lines, new_lines, old_filename, self.filename) return list(diff) def pyobject_filter(self, lines, location=None):