| |
@@ -1,19 +1,22 @@
|
| |
- From a8371a919b4f1552853a879377251ad25c3d988f Mon Sep 17 00:00:00 2001
|
| |
- From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
| |
- Date: Mon, 6 Nov 2023 13:44:17 +0100
|
| |
+ From 9699465414515f0eba76d05069e755b5bcf34eef Mon Sep 17 00:00:00 2001
|
| |
+ From: Karolina Surma <ksurma@redhat.com>
|
| |
+ Date: Mon, 15 Jan 2024 16:19:32 +0100
|
| |
Subject: [PATCH] Make the first party extensions optional, add [extensions]
|
| |
extra
|
| |
|
| |
+
|
| |
+ Co-authored-by: Miro Hrončok <miro@hroncok.cz>
|
| |
---
|
| |
pyproject.toml | 33 +++++++++++++++++++++++++++------
|
| |
- sphinx/application.py | 18 ++++++++++++++----
|
| |
+ sphinx/application.py | 6 +++---
|
| |
+ sphinx/registry.py | 9 ++++++---
|
| |
sphinx/testing/fixtures.py | 6 ++++++
|
| |
tests/test_api_translator.py | 2 ++
|
| |
tests/test_build_html.py | 3 +++
|
| |
- 5 files changed, 52 insertions(+), 10 deletions(-)
|
| |
+ 6 files changed, 47 insertions(+), 12 deletions(-)
|
| |
|
| |
diff --git a/pyproject.toml b/pyproject.toml
|
| |
- index a0ada3cd3ae..7cb0112897a 100644
|
| |
+ index 8f93701..41c28c5 100644
|
| |
--- a/pyproject.toml
|
| |
+++ b/pyproject.toml
|
| |
@@ -55,12 +55,6 @@ classifiers = [
|
| |
@@ -66,60 +69,69 @@
|
| |
lint = [
|
| |
"flake8>=3.5.0",
|
| |
diff --git a/sphinx/application.py b/sphinx/application.py
|
| |
- index d5fbaa9f30a..776bafa1ee3 100644
|
| |
+ index d5fbaa9..b030dab 100644
|
| |
--- a/sphinx/application.py
|
| |
+++ b/sphinx/application.py
|
| |
- @@ -24,7 +24,12 @@
|
| |
- from sphinx import locale, package_dir
|
| |
- from sphinx.config import Config
|
| |
- from sphinx.environment import BuildEnvironment
|
| |
- -from sphinx.errors import ApplicationError, ConfigError, VersionRequirementError
|
| |
- +from sphinx.errors import (
|
| |
- + ApplicationError,
|
| |
- + ConfigError,
|
| |
- + ExtensionError,
|
| |
- + VersionRequirementError,
|
| |
- +)
|
| |
- from sphinx.events import EventManager
|
| |
- from sphinx.highlighting import lexer_classes
|
| |
- from sphinx.locale import __
|
| |
- @@ -226,7 +231,7 @@ def __init__(self, srcdir: str | os.PathLike[str], confdir: str | os.PathLike[st
|
| |
+ @@ -226,7 +226,7 @@ class Sphinx:
|
| |
# load all built-in extension modules, first-party extension modules,
|
| |
# and first-party themes
|
| |
for extension in builtin_extensions:
|
| |
- self.setup_extension(extension)
|
| |
- + self.setup_extension(extension, optional=extension in _first_party_extensions)
|
| |
+ + self.setup_extension(extension, skip_nonimportable=extension in _first_party_extensions)
|
| |
|
| |
# load all user-given extension modules
|
| |
for extension in self.config.extensions:
|
| |
- @@ -395,7 +400,7 @@ def build(self, force_all: bool = False, filenames: list[str] | None = None) ->
|
| |
+ @@ -395,7 +395,7 @@ class Sphinx:
|
| |
|
| |
# ---- general extensibility interface -------------------------------------
|
| |
|
| |
- def setup_extension(self, extname: str) -> None:
|
| |
- + def setup_extension(self, extname: str, optional: bool = False) -> None:
|
| |
+ + def setup_extension(self, extname: str, skip_nonimportable: bool = False) -> None:
|
| |
"""Import and setup a Sphinx extension module.
|
| |
|
| |
Load the extension given by the module *name*. Use this if your
|
| |
- @@ -403,7 +408,12 @@ def setup_extension(self, extname: str) -> None:
|
| |
+ @@ -403,7 +403,7 @@ class Sphinx:
|
| |
called twice.
|
| |
"""
|
| |
logger.debug('[app] setting up extension: %r', extname)
|
| |
- self.registry.load_extension(self, extname)
|
| |
- + try:
|
| |
- + self.registry.load_extension(self, extname)
|
| |
- + except ExtensionError:
|
| |
- + logger.debug('[app] extension not found: %r', extname)
|
| |
- + if not optional:
|
| |
- + raise
|
| |
+ + self.registry.load_extension(self, extname, skip_nonimportable=skip_nonimportable)
|
| |
|
| |
@staticmethod
|
| |
def require_sphinx(version: tuple[int, int] | str) -> None:
|
| |
+ diff --git a/sphinx/registry.py b/sphinx/registry.py
|
| |
+ index 501661d..96d4554 100644
|
| |
+ --- a/sphinx/registry.py
|
| |
+ +++ b/sphinx/registry.py
|
| |
+ @@ -430,7 +430,7 @@ class SphinxComponentRegistry:
|
| |
+ def add_html_theme(self, name: str, theme_path: str) -> None:
|
| |
+ self.html_themes[name] = theme_path
|
| |
+
|
| |
+ - def load_extension(self, app: Sphinx, extname: str) -> None:
|
| |
+ + def load_extension(self, app: Sphinx, extname: str, skip_nonimportable: bool = False) -> None:
|
| |
+ """Load a Sphinx extension."""
|
| |
+ if extname in app.extensions: # already loaded
|
| |
+ return
|
| |
+ @@ -446,9 +446,12 @@ class SphinxComponentRegistry:
|
| |
+ try:
|
| |
+ mod = import_module(extname)
|
| |
+ except ImportError as err:
|
| |
+ + msg = __('Could not import extension %s')
|
| |
+ + if skip_nonimportable:
|
| |
+ + logger.debug(msg % extname)
|
| |
+ + return
|
| |
+ logger.verbose(__('Original exception:\n') + traceback.format_exc())
|
| |
+ - raise ExtensionError(__('Could not import extension %s') % extname,
|
| |
+ - err) from err
|
| |
+ + raise ExtensionError(msg % extname, err) from err
|
| |
+
|
| |
+ setup = getattr(mod, 'setup', None)
|
| |
+ if setup is None:
|
| |
diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py
|
| |
- index 0cc4882fe1c..f57f709b415 100644
|
| |
+ index 0cc4882..f57f709 100644
|
| |
--- a/sphinx/testing/fixtures.py
|
| |
+++ b/sphinx/testing/fixtures.py
|
| |
- @@ -22,6 +22,7 @@
|
| |
+ @@ -22,6 +22,7 @@ DEFAULT_ENABLED_MARKERS = [
|
| |
'sphinx(builder, testroot=None, freshenv=False, confoverrides=None, tags=None,'
|
| |
' docutilsconf=None, parallel=0): arguments to initialize the sphinx test application.'
|
| |
),
|
| |
@@ -140,7 +152,7 @@
|
| |
|
| |
pargs = {}
|
| |
diff --git a/tests/test_api_translator.py b/tests/test_api_translator.py
|
| |
- index 9f2bd448863..81575b71946 100644
|
| |
+ index 9f2bd44..81575b7 100644
|
| |
--- a/tests/test_api_translator.py
|
| |
+++ b/tests/test_api_translator.py
|
| |
@@ -36,6 +36,7 @@ def test_singlehtml_set_translator_for_singlehtml(app, status, warning):
|
| |
@@ -160,10 +172,10 @@
|
| |
def test_json_set_translator_for_json(app, status, warning):
|
| |
translator_class = app.builder.get_translator_class()
|
| |
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
|
| |
- index a89a6fcafaf..8bd44111853 100644
|
| |
+ index 07f101d..c512a33 100644
|
| |
--- a/tests/test_build_html.py
|
| |
+++ b/tests/test_build_html.py
|
| |
- @@ -1547,6 +1547,7 @@ def test_html_math_renderer_is_imgmath(app, status, warning):
|
| |
+ @@ -1544,6 +1544,7 @@ def test_html_math_renderer_is_imgmath(app, status, warning):
|
| |
assert app.builder.math_renderer_name == 'imgmath'
|
| |
|
| |
|
| |
@@ -171,7 +183,7 @@
|
| |
@pytest.mark.sphinx('html', testroot='basic',
|
| |
confoverrides={'extensions': ['sphinxcontrib.jsmath',
|
| |
'sphinx.ext.imgmath']})
|
| |
- @@ -1567,6 +1568,7 @@ def test_html_math_renderer_is_duplicated2(app, status, warning):
|
| |
+ @@ -1564,6 +1565,7 @@ def test_html_math_renderer_is_duplicated2(app, status, warning):
|
| |
assert app.builder.math_renderer_name == 'imgmath' # The another one is chosen
|
| |
|
| |
|
| |
@@ -179,7 +191,7 @@
|
| |
@pytest.mark.sphinx('html', testroot='basic',
|
| |
confoverrides={'extensions': ['sphinxcontrib.jsmath',
|
| |
'sphinx.ext.imgmath'],
|
| |
- @@ -1575,6 +1577,7 @@ def test_html_math_renderer_is_chosen(app, status, warning):
|
| |
+ @@ -1572,6 +1574,7 @@ def test_html_math_renderer_is_chosen(app, status, warning):
|
| |
assert app.builder.math_renderer_name == 'imgmath'
|
| |
|
| |
|
| |
@@ -187,3 +199,6 @@
|
| |
@pytest.mark.sphinx('html', testroot='basic',
|
| |
confoverrides={'extensions': ['sphinxcontrib.jsmath',
|
| |
'sphinx.ext.mathjax'],
|
| |
+ --
|
| |
+ 2.43.0
|
| |
+
|
| |