Skip to content

Commit dc30920

Browse files
authored
Merge pull request #10481 from AA-Turner/lang-none-en
Coerce `language = None` in `conf.py` to Engligh
2 parents 004012b + 2004149 commit dc30920

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Dependencies
77
Incompatible changes
88
--------------------
99

10+
* #10474: :confval:`language` does not accept ``None`` as it value. The default
11+
value of ``language`` becomes to ``'en'`` now.
12+
1013
Deprecated
1114
----------
1215

doc/usage/configuration.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,16 @@ documentation on :ref:`intl` for details.
725725
(e.g. the German version of ``myfigure.png`` will be ``myfigure.de.png``
726726
by default setting) and substitute them for original figures. In the LaTeX
727727
builder, a suitable language will be selected as an option for the *Babel*
728-
package. Default is ``None``, which means that no translation will be done.
728+
package. Default is ``'en'``.
729729

730730
.. versionadded:: 0.5
731731

732732
.. versionchanged:: 1.4
733733

734734
Support figure substitution
735735

736+
.. versionchanged:: 5.0
737+
736738
Currently supported languages by Sphinx are:
737739

738740
* ``ar`` -- Arabic
@@ -745,7 +747,7 @@ documentation on :ref:`intl` for details.
745747
* ``da`` -- Danish
746748
* ``de`` -- German
747749
* ``el`` -- Greek
748-
* ``en`` -- English
750+
* ``en`` -- English (default)
749751
* ``eo`` -- Esperanto
750752
* ``es`` -- Spanish
751753
* ``et`` -- Estonian

sphinx/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi
163163
raise ConfigError(__("config directory doesn't contain a conf.py file (%s)") %
164164
confdir)
165165
namespace = eval_config_file(filename, tags)
166+
167+
# Note: Old sphinx projects have been configured as "langugae = None" because
168+
# sphinx-quickstart previously generated this by default.
169+
# To keep compatibility, they should be fallback to 'en' for a while
170+
# (This conversion should not be removed before 2025-01-01).
171+
if namespace.get("language", ...) is None:
172+
logger.warning(__("Invalid configuration value found: 'language = None'. "
173+
"Update your configuration to a valid langauge code. "
174+
"Falling back to 'en' (English)."))
175+
namespace["language"] = "en"
176+
166177
return cls(namespace, overrides or {})
167178

168179
def convert_overrides(self, name: str, value: Any) -> Any:

tests/test_config.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,49 @@ def test_nitpick_ignore_regex_fullmatch(app, status, warning):
381381
assert len(warning) == len(nitpick_warnings)
382382
for actual, expected in zip(warning, nitpick_warnings):
383383
assert expected in actual
384+
385+
386+
def test_conf_py_language_none(tempdir):
387+
"""Regression test for #10474."""
388+
389+
# Given a conf.py file with language = None
390+
(tempdir / 'conf.py').write_text("language = None", encoding='utf-8')
391+
392+
# When we load conf.py into a Config object
393+
cfg = Config.read(tempdir, {}, None)
394+
cfg.init_values()
395+
396+
# Then the language is coerced to English
397+
assert cfg.language == "en"
398+
399+
400+
@mock.patch("sphinx.config.logger")
401+
def test_conf_py_language_none_warning(logger, tempdir):
402+
"""Regression test for #10474."""
403+
404+
# Given a conf.py file with language = None
405+
(tempdir / 'conf.py').write_text("language = None", encoding='utf-8')
406+
407+
# When we load conf.py into a Config object
408+
Config.read(tempdir, {}, None)
409+
410+
# Then a warning is raised
411+
assert logger.warning.called
412+
assert logger.warning.call_args[0][0] == (
413+
"Invalid configuration value found: 'language = None'. "
414+
"Update your configuration to a valid langauge code. "
415+
"Falling back to 'en' (English).")
416+
417+
418+
def test_conf_py_no_language(tempdir):
419+
"""Regression test for #10474."""
420+
421+
# Given a conf.py file with no language attribute
422+
(tempdir / 'conf.py').write_text("", encoding='utf-8')
423+
424+
# When we load conf.py into a Config object
425+
cfg = Config.read(tempdir, {}, None)
426+
cfg.init_values()
427+
428+
# Then the language is coerced to English
429+
assert cfg.language == "en"

0 commit comments

Comments
 (0)