From bc1387cabbc10dfc6471e39b741187ee4dd036cb Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 4 Apr 2020 11:25:34 +0900 Subject: [PATCH 01/26] LaTeX: Make the ``toplevel_sectioning`` setting optional in LaTeX theme --- CHANGES | 2 ++ sphinx/builders/latex/theming.py | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index ca8a5b726..0a6b30ced 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,8 @@ Deprecated Features added -------------- +* LaTeX: Make the ``toplevel_sectioning`` setting optional in LaTeX theme + Bugs fixed ---------- diff --git a/sphinx/builders/latex/theming.py b/sphinx/builders/latex/theming.py index 56f2735f0..d638639aa 100644 --- a/sphinx/builders/latex/theming.py +++ b/sphinx/builders/latex/theming.py @@ -66,19 +66,29 @@ class BuiltInTheme(Theme): class UserTheme(Theme): """A user defined LaTeX theme.""" + REQUIRED_CONFIG_KEYS = ['docclass', 'wrapperclass'] + OPTIONAL_CONFIG_KEYS = ['toplevel_sectioning'] + def __init__(self, name: str, filename: str) -> None: - self.name = name + super().__init__(name) self.config = configparser.RawConfigParser() self.config.read(path.join(filename)) - try: - self.docclass = self.config.get('theme', 'docclass') - self.wrapperclass = self.config.get('theme', 'wrapperclass') - self.toplevel_sectioning = self.config.get('theme', 'toplevel_sectioning') - except configparser.NoSectionError: - raise ThemeError(__('%r doesn\'t have "theme" setting') % filename) - except configparser.NoOptionError as exc: - raise ThemeError(__('%r doesn\'t have "%s" setting') % (filename, exc.args[0])) + for key in self.REQUIRED_CONFIG_KEYS: + try: + value = self.config.get('theme', key) + setattr(self, key, value) + except configparser.NoSectionError: + raise ThemeError(__('%r doesn\'t have "theme" setting') % filename) + except configparser.NoOptionError as exc: + raise ThemeError(__('%r doesn\'t have "%s" setting') % (filename, exc.args[0])) + + for key in self.OPTIONAL_CONFIG_KEYS: + try: + value = self.config.get('theme', key) + setattr(self, key, value) + except configparser.NoOptionError: + pass class ThemeFactory: From b15b01307ea266222363b0e31709c1d94c7966ac Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 8 Apr 2020 01:32:09 +0900 Subject: [PATCH 02/26] Fix #7422: autodoc: fails with ValueError when using autodoc_mock_imports --- CHANGES | 2 ++ sphinx/util/inspect.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 212f4571f..5e8bcbe33 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #7422: autodoc: fails with ValueError when using autodoc_mock_imports + Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 570ea9df6..64c1568f6 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -17,7 +17,7 @@ import typing import warnings from functools import partial, partialmethod from inspect import ( # NOQA - Parameter, isclass, ismethod, ismethoddescriptor, unwrap + Parameter, isclass, ismethod, ismethoddescriptor ) from io import StringIO from typing import Any, Callable, Mapping, List, Tuple @@ -116,6 +116,15 @@ def getargspec(func: Callable) -> Any: kwonlyargs, kwdefaults, annotations) +def unwrap(obj: Any) -> Any: + """Get an original object from wrapped object (wrapped functions).""" + try: + return inspect.unwrap(obj) + except ValueError: + # might be a mock object + return obj + + def unwrap_all(obj: Any) -> Any: """ Get an original object from wrapped object (unwrapping partials, wrapped @@ -217,7 +226,7 @@ def isattributedescriptor(obj: Any) -> bool: return True elif isdescriptor(obj): # non data descriptor - unwrapped = inspect.unwrap(obj) + unwrapped = unwrap(obj) if isfunction(unwrapped) or isbuiltin(unwrapped) or inspect.ismethod(unwrapped): # attribute must not be either function, builtin and method return False From b2ab2c6325c7723b7b046830976bac334d9999d2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 8 Apr 2020 01:49:24 +0900 Subject: [PATCH 03/26] Fix #7428: py domain: a reference to class ``None`` emits a nitpicky warning --- CHANGES | 2 ++ sphinx/domains/python.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 212f4571f..7d5f80186 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #7428: py domain: a reference to class ``None`` emits a nitpicky warning + Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 64a19fc48..893bb0a22 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -1311,7 +1311,7 @@ def builtin_resolver(app: Sphinx, env: BuildEnvironment, if node.get('refdomain') != 'py': return None - elif node.get('reftype') == 'obj' and node.get('reftarget') == 'None': + elif node.get('reftype') in ('class', 'obj') and node.get('reftarget') == 'None': return contnode elif node.get('reftype') in ('class', 'exc'): reftarget = node.get('reftarget') From 1ca220762b7d13697d9c8354db80493322f724d8 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 9 Apr 2020 00:17:35 +0900 Subject: [PATCH 04/26] Fix #7423: crashed when giving a non-string object to logger --- CHANGES | 2 ++ sphinx/util/logging.py | 2 +- tests/test_util_logging.py | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 212f4571f..810f2ed22 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #7423: crashed when giving a non-string object to logger + Testing -------- diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index fbf161ec0..53053faaf 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -412,7 +412,7 @@ class WarningIsErrorFilter(logging.Filter): message = record.msg # use record.msg itself if location: - raise SphinxWarning(location + ":" + message) + raise SphinxWarning(location + ":" + str(message)) else: raise SphinxWarning(message) else: diff --git a/tests/test_util_logging.py b/tests/test_util_logging.py index 337782d87..36034cd92 100644 --- a/tests/test_util_logging.py +++ b/tests/test_util_logging.py @@ -48,6 +48,14 @@ def test_info_and_warning(app, status, warning): assert 'message5' in warning.getvalue() +def test_Exception(app, status, warning): + logging.setup(app, status, warning) + logger = logging.getLogger(__name__) + + logger.info(Exception) + assert "" in status.getvalue() + + def test_verbosity_filter(app, status, warning): # verbosity = 0: INFO app.verbosity = 0 From 0525c39b9e3b6a4a54cc55ba76fd42d56687d91e Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Thu, 9 Apr 2020 01:15:21 +0900 Subject: [PATCH 05/26] Fix #7435: autodoc_typehints doesn't suppress typehints for classes/methods --- CHANGES | 2 ++ sphinx/ext/autodoc/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 7d5f80186..37d8d6a63 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,8 @@ Bugs fixed ---------- * #7428: py domain: a reference to class ``None`` emits a nitpicky warning +* #7435: autodoc: ``autodoc_typehints='description'`` doesn't suppress typehints + in signature for classes/methods Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index ad3e5f00a..f69e2b5f1 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1174,7 +1174,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type: return ret def format_args(self, **kwargs: Any) -> str: - if self.env.config.autodoc_typehints == 'none': + if self.env.config.autodoc_typehints in ('none', 'description'): kwargs.setdefault('show_annotation', False) # for classes, the relevant signature is the __init__ method's @@ -1430,7 +1430,7 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: return ret def format_args(self, **kwargs: Any) -> str: - if self.env.config.autodoc_typehints == 'none': + if self.env.config.autodoc_typehints in ('none', 'description'): kwargs.setdefault('show_annotation', False) unwrapped = inspect.unwrap(self.object) From a5dadeb890beca64bb9eabe86e6634c9dd3e1d50 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 8 Apr 2020 22:46:03 +0900 Subject: [PATCH 06/26] Fix #7418: std domain: duplication warning for glossary terms is case insensitive --- CHANGES | 3 +++ doc/extdev/index.rst | 2 +- sphinx/domains/std.py | 4 ++-- tests/test_domain_std.py | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 7d5f80186..c9c962380 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ Dependencies Incompatible changes -------------------- +* #7418: std domain: :rst:dir:`term` role becomes case sensitive + Deprecated ---------- @@ -17,6 +19,7 @@ Bugs fixed ---------- * #7428: py domain: a reference to class ``None`` emits a nitpicky warning +* #7418: std domain: duplication warning for glossary terms is case insensitive Testing -------- diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index 8c909e315..266da52b7 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -27,7 +27,7 @@ Discovery of builders by entry point .. versionadded:: 1.6 -:term:`Builder` extensions can be discovered by means of `entry points`_ so +:term:`builder` extensions can be discovered by means of `entry points`_ so that they do not have to be listed in the :confval:`extensions` configuration value. diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index d820cfe5c..52546fb4c 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -305,7 +305,7 @@ def make_glossary_term(env: "BuildEnvironment", textnodes: Iterable[Node], index term['ids'].append(node_id) std = cast(StandardDomain, env.get_domain('std')) - std.note_object('term', termtext.lower(), node_id, location=term) + std.note_object('term', termtext, node_id, location=term) # add an index entry too indexnode = addnodes.index() @@ -565,7 +565,7 @@ class StandardDomain(Domain): # links to tokens in grammar productions 'token': TokenXRefRole(), # links to terms in glossary - 'term': XRefRole(lowercase=True, innernodeclass=nodes.inline, + 'term': XRefRole(innernodeclass=nodes.inline, warn_dangling=True), # links to headings or arbitrary labels 'ref': XRefRole(lowercase=True, innernodeclass=nodes.inline, diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index aa1d29eb1..0032c18ef 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -99,7 +99,7 @@ def test_glossary(app): text = (".. glossary::\n" "\n" " term1\n" - " term2\n" + " TERM2\n" " description\n" "\n" " term3 : classifier\n" @@ -114,7 +114,7 @@ def test_glossary(app): assert_node(doctree, ( [glossary, definition_list, ([definition_list_item, ([term, ("term1", index)], - [term, ("term2", + [term, ("TERM2", index)], definition)], [definition_list_item, ([term, ("term3", @@ -127,7 +127,7 @@ def test_glossary(app): assert_node(doctree[0][0][0][0][1], entries=[("single", "term1", "term-term1", "main", None)]) assert_node(doctree[0][0][0][1][1], - entries=[("single", "term2", "term-term2", "main", None)]) + entries=[("single", "TERM2", "term-TERM2", "main", None)]) assert_node(doctree[0][0][0][2], [definition, nodes.paragraph, "description"]) assert_node(doctree[0][0][1][0][1], @@ -143,7 +143,7 @@ def test_glossary(app): # index objects = list(app.env.get_domain("std").get_objects()) assert ("term1", "term1", "term", "index", "term-term1", -1) in objects - assert ("term2", "term2", "term", "index", "term-term2", -1) in objects + assert ("TERM2", "TERM2", "term", "index", "term-TERM2", -1) in objects assert ("term3", "term3", "term", "index", "term-term3", -1) in objects assert ("term4", "term4", "term", "index", "term-term4", -1) in objects From 9dec86e98d7d71a5ea69bb3b7c7a66d25d6f2278 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Mon, 6 Apr 2020 20:48:42 +0200 Subject: [PATCH 07/26] Escape links to master_doc --- sphinx/themes/agogo/layout.html | 4 ++-- sphinx/themes/basic/globaltoc.html | 2 +- sphinx/themes/basic/layout.html | 4 ++-- sphinx/themes/basic/localtoc.html | 2 +- sphinx/themes/haiku/layout.html | 2 +- sphinx/themes/pyramid/layout.html | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sphinx/themes/agogo/layout.html b/sphinx/themes/agogo/layout.html index cfd7ee38b..aca2e1e33 100644 --- a/sphinx/themes/agogo/layout.html +++ b/sphinx/themes/agogo/layout.html @@ -14,13 +14,13 @@