summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-03-07 01:28:10 +0000
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2023-03-24 01:30:44 +0000
commitc7d7f2951d0c43280f78c84b65df11d207ea6177 (patch)
tree49a04b6d81abe127c3889da0e4d1bd98df31624e
parent7d928b3e7910d9bd5b232548a2d5998331c29b59 (diff)
downloadsphinx-git-c7d7f2951d0c43280f78c84b65df11d207ea6177.tar.gz
Remove ``sphinx.locale.setlocale``
-rw-r--r--CHANGES1
-rw-r--r--sphinx/application.py2
-rw-r--r--sphinx/cmd/build.py6
-rw-r--r--sphinx/cmd/quickstart.py4
-rw-r--r--sphinx/ext/apidoc.py4
-rw-r--r--sphinx/ext/autosummary/generate.py7
-rw-r--r--sphinx/locale/__init__.py22
7 files changed, 13 insertions, 33 deletions
diff --git a/CHANGES b/CHANGES
index 7106255c9..22ff492cd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,7 @@ Incompatible changes
now-obsolete binary distribution format
* #11089: Remove deprecated code in ``sphinx.builders.linkcheck``.
Patch by Daniel Eades
+* Remove internal-only ``sphinx.locale.setlocale``
Deprecated
----------
diff --git a/sphinx/application.py b/sphinx/application.py
index 8bb27ed90..b824e8532 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -272,7 +272,7 @@ class Sphinx:
the configuration.
"""
if self.config.language == 'en':
- self.translator, has_translation = locale.init([], None)
+ self.translator, _ = locale.init([], None)
else:
logger.info(bold(__('loading translations [%s]... ') % self.config.language),
nonl=True)
diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py
index c6d33f3cf..ecc2a7d2c 100644
--- a/sphinx/cmd/build.py
+++ b/sphinx/cmd/build.py
@@ -16,7 +16,7 @@ from typing import Any, TextIO
from docutils.utils import SystemMessage
import sphinx.locale
-from sphinx import __display_version__, package_dir
+from sphinx import __display_version__
from sphinx.application import Sphinx
from sphinx.errors import SphinxError
from sphinx.locale import __
@@ -310,8 +310,8 @@ def _bug_report_info() -> int:
def main(argv: list[str] = sys.argv[1:]) -> int:
- sphinx.locale.setlocale(locale.LC_ALL, '')
- sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
+ locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.init_console()
if argv[:1] == ['--bug-report']:
return _bug_report_info()
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py
index 17ae61208..6122ddd98 100644
--- a/sphinx/cmd/quickstart.py
+++ b/sphinx/cmd/quickstart.py
@@ -540,8 +540,8 @@ def get_parser() -> argparse.ArgumentParser:
def main(argv: list[str] = sys.argv[1:]) -> int:
- sphinx.locale.setlocale(locale.LC_ALL, '')
- sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
+ locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.init_console()
if not color_terminal():
nocolor()
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index 578b54903..1097463c6 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -392,8 +392,8 @@ Note: By default this script will not overwrite already created files."""))
def main(argv: list[str] = sys.argv[1:]) -> int:
"""Parse and check the command line arguments."""
- sphinx.locale.setlocale(locale.LC_ALL, '')
- sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
+ locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.init_console()
parser = get_parser()
args = parser.parse_args(argv)
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 9e8843c03..9b9abdf26 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -636,11 +636,10 @@ The format of the autosummary directive is documented in the
def main(argv: list[str] = sys.argv[1:]) -> None:
- sphinx.locale.setlocale(locale.LC_ALL, '')
- sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
- translator, _ = sphinx.locale.init([], None)
+ locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.init_console()
- app = DummyApplication(translator)
+ app = DummyApplication(sphinx.locale.get_translator())
logging.setup(app, sys.stdout, sys.stderr) # type: ignore
setup_documenters(app)
args = get_parser().parse_args(argv)
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index 05eaf16a8..95b7a9d25 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -3,7 +3,7 @@
import locale
from gettext import NullTranslations, translation
from os import path
-from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
+from typing import Any, Callable, Dict, List, Optional, Tuple
class _TranslationProxy:
@@ -138,26 +138,6 @@ def init(
return translator, has_translation
-def setlocale(category: int, value: Union[str, Iterable[str], None] = None) -> None:
- """Update locale settings.
-
- This does not throw any exception even if update fails.
- This is workaround for Python's bug.
-
- For more details:
-
- * https://github.com/sphinx-doc/sphinx/issues/5724
- * https://bugs.python.org/issue18378#msg215215
-
- .. note:: Only for internal use. Please don't call this method from extensions.
- This will be removed in Sphinx 6.0.
- """
- try:
- locale.setlocale(category, value)
- except locale.Error:
- pass
-
-
_LOCALE_DIR = path.abspath(path.dirname(__file__))