From a7c6cb018067d735a470a0687248912c6148977d Mon Sep 17 00:00:00 2001 From: Tommy Nguyen Date: Sun, 29 Apr 2018 22:07:07 -0400 Subject: [PATCH 1/8] Fix blank URL_ROOT pathto doesn't expand in non-HTML templates so the workaround involves expanding it in the HTML file and passing it as a data attribute to the script. --- sphinx/themes/basic/layout.html | 2 +- sphinx/themes/basic/static/documentation_options.js_t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html index 68c7d9e51..4e672c722 100644 --- a/sphinx/themes/basic/layout.html +++ b/sphinx/themes/basic/layout.html @@ -87,7 +87,7 @@ {%- endmacro %} {%- macro script() %} - + {%- for scriptfile in script_files %} {%- endfor %} diff --git a/sphinx/themes/basic/static/documentation_options.js_t b/sphinx/themes/basic/static/documentation_options.js_t index e76f55a4e..9da9801a1 100644 --- a/sphinx/themes/basic/static/documentation_options.js_t +++ b/sphinx/themes/basic/static/documentation_options.js_t @@ -1,5 +1,5 @@ var DOCUMENTATION_OPTIONS = { - URL_ROOT: '{{ url_root }}', + URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), VERSION: '{{ release|e }}', LANGUAGE: '{{ language }}', COLLAPSE_INDEX: false, From 3a9dacd052016254b0a693e7943c0eff525f0559 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 14 May 2018 00:06:39 +0900 Subject: [PATCH 2/8] Do not use bare raise statement --- sphinx/builders/epub3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 008942a6a..8c32231bd 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -185,7 +185,7 @@ class Epub3Builder(_epub_base.EpubBuilder): navstack[-1].children.append(navpoint) navstack.append(navpoint) else: - raise + raise RuntimeError('Should never reach here. It might be a bug.') return navstack[0].children From c6050a3d1ec4f7245ea51e26062130884f31641f Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 15 May 2018 01:46:40 +0900 Subject: [PATCH 3/8] Fix latex: deeply nested enumerated list which is beginning with non-1 causes LaTeX engine crashed --- CHANGES | 2 ++ sphinx/writers/latex.py | 5 +++-- tests/roots/test-nested-enumerated-list/index.rst | 6 ++++++ tests/test_build_latex.py | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 126d414a5..e1773b6a6 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,8 @@ Bugs fixed topic, admonition, table and section. * #4913: i18n: literal blocks in bullet list are not translated * #4962: cpp domain: raises TypeError on duplicate declaration +* latex: deeply nested enumerated list which is beginning with non-1 causes + LaTeX engine crashed Testing -------- diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 17eabc462..d4deb49ac 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -18,6 +18,7 @@ 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 @@ -1514,8 +1515,8 @@ class LaTeXTranslator(nodes.NodeVisitor): self.body.append('\\begin{enumerate}\n') if 'start' in node: - nested = get_nested_level(node) - self.body.append('\\setcounter{enum%s}{%d}\n' % ('i' * nested, node['start'] - 1)) + enum_depth = "enum%s" % toRoman(get_nested_level(node)).lower() + self.body.append('\\setcounter{%s}{%d}\n' % (enum_depth, node['start'] - 1)) if self.table: self.table.has_problematic = True diff --git a/tests/roots/test-nested-enumerated-list/index.rst b/tests/roots/test-nested-enumerated-list/index.rst index e1a9b5cbc..28ad72f9d 100644 --- a/tests/roots/test-nested-enumerated-list/index.rst +++ b/tests/roots/test-nested-enumerated-list/index.rst @@ -9,6 +9,12 @@ nested-enumerated-list 10) Pyramid 11) Nile River + (x) Atbara + (y) Blue Nile + (#) Sobat + (#) Semliki + (#) Kagera + 6. Markup iii. reStructuredText diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index c6aed1e3e..75515cf64 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1239,4 +1239,5 @@ def test_latex_nested_enumerated_list(app, status, warning): assert r'\setcounter{enumi}{4}' in result assert r'\setcounter{enumii}{3}' in result assert r'\setcounter{enumiii}{9}' in result + assert r'\setcounter{enumiv}{23}' in result assert r'\setcounter{enumii}{2}' in result From ffc6ad5fb41dbdd27028f4183109aea5d0e3f608 Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Tue, 15 May 2018 21:37:29 +0900 Subject: [PATCH 4/8] CHANGES for #4863 --- CHANGES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 126d414a5..fdaae64bb 100644 --- a/CHANGES +++ b/CHANGES @@ -19,8 +19,8 @@ Bugs fixed * #4924: html search: Upper characters problem in any other languages * #4932: apidoc: some subpackage is ignored if sibling subpackage contains a module starting with underscore -* #4938, #4939: i18n doesn't handle node.title correctly tat used for contents, - topic, admonition, table and section. +* #4863, #4938, #4939: i18n doesn't handle node.title correctly tat used for + contents, topic, admonition, table and section. * #4913: i18n: literal blocks in bullet list are not translated * #4962: cpp domain: raises TypeError on duplicate declaration From d8ac86a2bb8d64c3c317363107701e33aff1a3ea Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Wed, 16 May 2018 22:02:29 +0200 Subject: [PATCH 5/8] C++, handle (escaped) line breaks in epxr role Fixes sphinx-doc/sphinx#4825 --- CHANGES | 4 +++- sphinx/domains/cpp.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index fdaae64bb..c5f1f9fdc 100644 --- a/CHANGES +++ b/CHANGES @@ -22,7 +22,9 @@ Bugs fixed * #4863, #4938, #4939: i18n doesn't handle node.title correctly tat used for contents, topic, admonition, table and section. * #4913: i18n: literal blocks in bullet list are not translated -* #4962: cpp domain: raises TypeError on duplicate declaration +* #4962: C++, raised TypeError on duplicate declaration. +* #4825: C++, properly parse expr roles and give better error messages when + (escaped) line breaks are present. Testing -------- diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index fe339b153..23e8c642c 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -12,7 +12,7 @@ import re from copy import deepcopy -from docutils import nodes +from docutils import nodes, utils from docutils.parsers.rst import Directive, directives from six import iteritems, text_type @@ -5962,7 +5962,7 @@ class CPPExprRole(object): class Warner(object): def warn(self, msg): inliner.reporter.warning(msg, line=lineno) - + text = utils.unescape(text).replace('\n', ' ') env = inliner.document.settings.env parser = DefinitionParser(text, Warner(), env.config) try: From ba4b9c0131e41bbf4143701fe60bba3c08cc6762 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 15 May 2018 21:55:41 +0900 Subject: [PATCH 6/8] Update CHANGES for PR #4916 --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index c5f1f9fdc..c3dc3996d 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ Bugs fixed * #4962: C++, raised TypeError on duplicate declaration. * #4825: C++, properly parse expr roles and give better error messages when (escaped) line breaks are present. +* #4915, #4916: links on search page are broken when using dirhtml builder Testing -------- From 4cf1b4894761c2c6313a5d4d32aad84a96efcb08 Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Fri, 18 May 2018 21:27:27 +0200 Subject: [PATCH 7/8] C++, properly use desc_addname in declarations. This meant that the prefix was not rendered in code font, and it broke Breathe. Fixes michaeljones/breathe#374 Example: .. cpp:class:: A .. cpp:member:: A::b ``A::`` not rendered properly. --- CHANGES | 1 + sphinx/domains/cpp.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index c3dc3996d..87b134488 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ Bugs fixed * #4962: C++, raised TypeError on duplicate declaration. * #4825: C++, properly parse expr roles and give better error messages when (escaped) line breaks are present. +* C++, properly use ``desc_addname`` nodes for prefixes of names. * #4915, #4916: links on search page are broken when using dirhtml builder Testing diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 23e8c642c..5475b8d4a 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -1965,26 +1965,34 @@ class ASTNestedName(ASTBase): prefix = '' # type: unicode first = True names = self.names[:-1] if mode == 'lastIsName' else self.names + # If lastIsName, then wrap all of the prefix in a desc_addname, + # else append directly to signode. + # NOTE: Breathe relies on the prefix being in the desc_addname node, + # so it can remove it in inner declarations. + dest = signode + if mode == 'lastIsName': + dest = addnodes.desc_addname() for i in range(len(names)): name = names[i] template = self.templates[i] if not first: - signode += nodes.Text('::') + dest += nodes.Text('::') prefix += '::' if template: - signode += nodes.Text("template ") + dest += nodes.Text("template ") first = False if name != '': if (name.templateArgs and # type: ignore iTemplateParams < len(templateParams)): templateParamsPrefix += text_type(templateParams[iTemplateParams]) iTemplateParams += 1 - name.describe_signature(signode, 'markType', # type: ignore + name.describe_signature(dest, 'markType', # type: ignore env, templateParamsPrefix + prefix, symbol) prefix += text_type(name) if mode == 'lastIsName': if len(self.names) > 1: - signode += addnodes.desc_addname('::', '::') + dest += addnodes.desc_addname('::', '::') + signode += dest if self.templates[-1]: signode += nodes.Text("template ") self.names[-1].describe_signature(signode, mode, env, '', symbol) From b2abab1c458d9bdc6367210c655654a7a4b04aa8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 14 May 2018 23:35:52 +0900 Subject: [PATCH 8/8] Fix #4969: autodoc: constructor method should not have return annotation --- CHANGES | 1 + sphinx/ext/autodoc/__init__.py | 8 +++++--- sphinx/util/inspect.py | 10 +++++++--- tests/test_util_inspect.py | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 87b134488..7a06cef75 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,7 @@ Bugs fixed (escaped) line breaks are present. * C++, properly use ``desc_addname`` nodes for prefixes of names. * #4915, #4916: links on search page are broken when using dirhtml builder +* #4969: autodoc: constructor method should not have return annotation Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index d516146bf..eabe487e3 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1035,9 +1035,11 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ # typing) we try to use the constructor signature as function # signature without the first argument. try: - args = Signature(self.object.__new__, bound_method=True).format_args() + sig = Signature(self.object.__new__, bound_method=True, has_retval=False) + args = sig.format_args() except TypeError: - args = Signature(self.object.__init__, bound_method=True).format_args() + sig = Signature(self.object.__init__, bound_method=True, has_retval=False) + args = sig.format_args() # escape backslashes for reST args = args.replace('\\', '\\\\') @@ -1090,7 +1092,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: not(inspect.ismethod(initmeth) or inspect.isfunction(initmeth)): return None try: - return Signature(initmeth, bound_method=True).format_args() + return Signature(initmeth, bound_method=True, has_retval=False).format_args() except TypeError: # still not possible: happens e.g. for old-style classes # with __init__ in C diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 492db8700..72c3065bc 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -298,8 +298,8 @@ class Signature(object): its return annotation. """ - def __init__(self, subject, bound_method=False): - # type: (Callable, bool) -> None + def __init__(self, subject, bound_method=False, has_retval=True): + # type: (Callable, bool, bool) -> None # check subject is not a built-in class (ex. int, str) if (isinstance(subject, type) and is_builtin_class_method(subject, "__new__") and @@ -307,6 +307,7 @@ class Signature(object): raise TypeError("can't compute signature for built-in type {}".format(subject)) self.subject = subject + self.has_retval = has_retval self.partialmethod_with_noargs = False if PY3: @@ -375,7 +376,10 @@ class Signature(object): def return_annotation(self): # type: () -> Any if PY3 and self.signature: - return self.signature.return_annotation + if self.has_retval: + return self.signature.return_annotation + else: + return inspect.Parameter.empty else: return None diff --git a/tests/test_util_inspect.py b/tests/test_util_inspect.py index 6a3e25b6e..76f21a5e1 100644 --- a/tests/test_util_inspect.py +++ b/tests/test_util_inspect.py @@ -280,6 +280,10 @@ def test_Signature_annotations(): sig = inspect.Signature(f11).format_args() assert sig == '(x: CustomAnnotation, y: 123) -> None' + # has_retval=False + sig = inspect.Signature(f11, has_retval=False).format_args() + assert sig == '(x: CustomAnnotation, y: 123)' + def test_safe_getattr_with_default(): class Foo(object):