Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-03-20 19:40:00 +0300
committerGitHub <noreply@github.com>2022-03-20 19:40:00 +0300
commit7c144372d7100159f2aa970f4b6126b40a003d98 (patch)
treebde1911d6d293387a405288d16e5baf509643a75
parent79d8e4eb3470d2aa804ba75eb418872c4fd21ede (diff)
parent7f660ab0277032e2b8302c4f3a37ebe772026753 (diff)
Merge pull request #10186 from ultmaster/rst-get-language-patch
Patch rst get language in docutils
-rw-r--r--sphinx/util/docutils.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index 654a7a98b..f954c81d5 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -136,6 +136,30 @@ def patched_get_language() -> Generator[None, None, None]:
@contextmanager
+def patched_rst_get_language() -> Generator[None, None, None]:
+ """Patch docutils.parsers.rst.languages.get_language().
+ Starting from docutils 0.17, get_language() in ``rst.languages``
+ also has a reporter, which needs to be disabled temporarily.
+
+ This should also work for old versions of docutils,
+ because reporter is none by default.
+
+ refs: https://github.com/sphinx-doc/sphinx/issues/10179
+ """
+ from docutils.parsers.rst.languages import get_language
+
+ def patched_get_language(language_code: str, reporter: Reporter = None) -> Any:
+ return get_language(language_code)
+
+ try:
+ docutils.parsers.rst.languages.get_language = patched_get_language
+ yield
+ finally:
+ # restore original implementations
+ docutils.parsers.rst.languages.get_language = get_language
+
+
+@contextmanager
def using_user_docutils_conf(confdir: Optional[str]) -> Generator[None, None, None]:
"""Let docutils know the location of ``docutils.conf`` for Sphinx."""
try:
@@ -154,7 +178,7 @@ def using_user_docutils_conf(confdir: Optional[str]) -> Generator[None, None, No
@contextmanager
def patch_docutils(confdir: Optional[str] = None) -> Generator[None, None, None]:
"""Patch to docutils temporarily."""
- with patched_get_language(), using_user_docutils_conf(confdir):
+ with patched_get_language(), patched_rst_get_language(), using_user_docutils_conf(confdir):
yield