Skip to content

Commit

Permalink
Remove sphinx.locale.setlocale
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Mar 24, 2023
1 parent 7d928b3 commit c7d7f29
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _init_i18n(self) -> None:
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)
Expand Down
6 changes: 3 additions & 3 deletions sphinx/cmd/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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 __
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sphinx/cmd/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sphinx/ext/apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ def get_parser() -> argparse.ArgumentParser:

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)
Expand Down
7 changes: 3 additions & 4 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,10 @@ def get_parser() -> argparse.ArgumentParser:


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)
Expand Down
22 changes: 1 addition & 21 deletions sphinx/locale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__))


Expand Down

0 comments on commit c7d7f29

Please sign in to comment.