Skip to content

Commit

Permalink
Update warning, revert my original warning patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed May 28, 2022
1 parent fb6db30 commit 479e482
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
15 changes: 6 additions & 9 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,15 @@ def read(cls, confdir: str, overrides: Dict = None, tags: Tags = None) -> "Confi
confdir)
namespace = eval_config_file(filename, tags)

# Note: Old sphinx projects has been configured as "langugae = None" because
# sphinx-quickstart had generated the configuration by default formerly.
# Note: Old sphinx projects have been configured as "langugae = None" because
# sphinx-quickstart previously generated this by default.
# To keep compatibility, they should be fallback to 'en' for a while
# (At least 2 years or more since v5.0 release).
# (This conversion should not be removed before 2025-01-01).
if namespace.get("language", ...) is None:
logging.warning(__("Invalid configuration found: 'language = None'. "
"Now it takes only a string. Please update your configuration. "
"Fallback to 'en' (English)."))
logger.warning(__("Invalid configuration value found: 'language = None'. "
"Update your configuration to a valid langauge code. "
"Falling back to 'en' (English)."))
namespace["language"] = "en"
warnings.warn("'None' is not a valid value for 'language', coercing to 'en'. "
"Update 'conf.py' to a valid language code to silence this "
"warning.", RuntimeWarning, stacklevel=4)

return cls(namespace, overrides or {})

Expand Down
18 changes: 10 additions & 8 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,22 @@ def test_conf_py_language_none(tempdir):
assert cfg.language == "en"


def test_conf_py_language_none_warning(tempdir):
def test_conf_py_language_none_warning(tempdir, caplog):
"""Regression test for #10474."""

# Given a conf.py file with language = None
(tempdir / 'conf.py').write_text("language = None", encoding='utf-8')

# When we load conf.py into a Config object
Config.read(tempdir, {}, None)

# Then a warning is raised
with pytest.warns(
RuntimeWarning,
match="'None' is not a valid value for 'language', coercing to 'en'. "
"Update 'conf.py' to a valid language code to silence this "
"warning."):
# When we load conf.py into a Config object
Config.read(tempdir, {}, None)
assert len(caplog.messages) == 1
assert caplog.messages[0] == (
"Invalid configuration value found: 'language = None'. "
"Update your configuration to a valid langauge code. "
"Falling back to 'en' (English).")
assert caplog.records[0].levelname == "WARNING"


def test_conf_py_no_language(tempdir):
Expand Down

0 comments on commit 479e482

Please sign in to comment.