summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2018-12-17 23:08:08 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2018-12-17 23:08:08 +0900
commit4b331dae48cea3564ba6ebcebc5c7218cbcd4ffc (patch)
tree344d7f6997ef02c1246db71f492fad8a5b9653a5
parente9c87b3d13c192a9b6a82d9ce0c6572f85e85743 (diff)
downloadsphinx-git-4b331dae48cea3564ba6ebcebc5c7218cbcd4ffc.tar.gz
Fix #5724: quickstart: sphinx-quickstart fails when $LC_ALL is empty
-rw-r--r--CHANGES1
-rw-r--r--sphinx/cmd/build.py2
-rw-r--r--sphinx/cmd/quickstart.py2
-rw-r--r--sphinx/ext/apidoc.py2
-rw-r--r--sphinx/ext/autosummary/generate.py2
-rw-r--r--sphinx/locale/__init__.py23
6 files changed, 27 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 6f7367919..7acc82fd0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -26,6 +26,7 @@ Bugs fixed
(refs: #1238)
* #5636: C++, fix parsing of floating point literals.
* #5496 (again): C++, fix assertion in partial builds with duplicates.
+* #5724: quickstart: sphinx-quickstart fails when $LC_ALL is empty
Testing
--------
diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py
index 35176c7fc..16aa41742 100644
--- a/sphinx/cmd/build.py
+++ b/sphinx/cmd/build.py
@@ -310,7 +310,7 @@ def build_main(argv=sys.argv[1:]): # type: ignore
def main(argv=sys.argv[1:]): # type: ignore
# type: (List[unicode]) -> int
- locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
if argv[:1] == ['-M']:
diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py
index 61ca3b10f..5494423e4 100644
--- a/sphinx/cmd/quickstart.py
+++ b/sphinx/cmd/quickstart.py
@@ -613,7 +613,7 @@ Makefile to be used with sphinx-build.
def main(argv=sys.argv[1:]):
# type: (List[str]) -> int
- locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
if not color_terminal():
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index a154f6449..25f9275f7 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -387,7 +387,7 @@ Note: By default this script will not overwrite already created files."""))
def main(argv=sys.argv[1:]):
# type: (List[str]) -> int
"""Parse and check the command line arguments."""
- locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
parser = get_parser()
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index cb27a664d..dbe997c01 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -408,7 +408,7 @@ The format of the autosummary directive is documented in the
def main(argv=sys.argv[1:]):
# type: (List[str]) -> None
- locale.setlocale(locale.LC_ALL, '')
+ sphinx.locale.setlocale(locale.LC_ALL, '')
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
app = DummyApplication()
diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py
index 5bdcd6ac6..e136d9af2 100644
--- a/sphinx/locale/__init__.py
+++ b/sphinx/locale/__init__.py
@@ -22,7 +22,7 @@ from sphinx.deprecation import RemovedInSphinx30Warning
if False:
# For type annotation
- from typing import Any, Callable, Dict, Iterator, List, Tuple # NOQA
+ from typing import Any, Callable, Dict, Iterable, Iterator, List, Tuple, Union # NOQA
class _TranslationProxy(UserString, object):
@@ -247,6 +247,27 @@ def init(locale_dirs, language, catalog='sphinx', namespace='general'):
return translator, has_translation
+def setlocale(category, value=None):
+ # type: (int, Union[str, Iterable[str]]) -> 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 future.
+ """
+ try:
+ locale.setlocale(category, value)
+ except locale.Error:
+ pass
+
+
def init_console(locale_dir, catalog):
# type: (unicode, unicode) -> Tuple[NullTranslations, bool]
"""Initialize locale for console.