From 51332c7b08f17a471706aa3a2b5a55d34c28a31d Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 9 Aug 2020 00:44:04 +0900 Subject: [PATCH 1/3] Fix #8074: napoleon: Crashes during processing C-ext module inspect.getfile() raises TypeError if given object is a C-extension. This handles the exception not to be crashed. --- CHANGES | 2 ++ sphinx/ext/napoleon/docstring.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 5f645efa8..092673746 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,8 @@ Features added Bugs fixed ---------- +* #8074: napoleon: Crashes during processing C-ext module + Testing -------- diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 52abf9753..29799cb06 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1074,7 +1074,10 @@ class NumpyDocstring(GoogleDocstring): super().__init__(docstring, config, app, what, name, obj, options) def _get_location(self) -> str: - filepath = inspect.getfile(self._obj) if self._obj is not None else None + try: + filepath = inspect.getfile(self._obj) if self._obj is not None else None + except TypeError: + filepath = None name = self._name if filepath is None and name is None: From a4487f1762e722b1d7639ec13c531a7c2f8ce889 Mon Sep 17 00:00:00 2001 From: Yves Chevallier Date: Sun, 9 Aug 2020 11:44:41 +0200 Subject: [PATCH 2/3] Check if LaTeX package already added --- sphinx/registry.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sphinx/registry.py b/sphinx/registry.py index 0aec0a9fd..4d1e9eb72 100644 --- a/sphinx/registry.py +++ b/sphinx/registry.py @@ -367,7 +367,14 @@ class SphinxComponentRegistry: logger.debug('[app] adding js_file: %r, %r', filename, attributes) self.js_files.append((filename, attributes)) + def has_latex_package(self, name: str) -> bool: + packages = self.latex_packages + self.latex_packages_after_hyperref + return bool([x for x in packages if x[0] == name]) + def add_latex_package(self, name: str, options: str, after_hyperref: bool = False) -> None: + if self.has_latex_package(name): + logger.warn("latex package '%s' already included" % name) + logger.debug('[app] adding latex package: %r', name) if after_hyperref: self.latex_packages_after_hyperref.append((name, options)) From 5f82825e273dfc5df3c4ef499876def8b024fa81 Mon Sep 17 00:00:00 2001 From: Yves Chevallier Date: Sun, 9 Aug 2020 13:33:42 +0200 Subject: [PATCH 3/3] Customize jinja comment-tag --- sphinx/util/template.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sphinx/util/template.py b/sphinx/util/template.py index 18047d687..bb078a2a2 100644 --- a/sphinx/util/template.py +++ b/sphinx/util/template.py @@ -84,6 +84,8 @@ class LaTeXRenderer(SphinxRenderer): self.env.variable_end_string = '%>' self.env.block_start_string = '<%' self.env.block_end_string = '%>' + self.env.comment_start_string = '<#' + self.env.comment_end_string = '<#' class ReSTRenderer(SphinxRenderer):