Merge pull request #6908 from tk0miya/6900_sphinx-build-D_accepts_boolean

Fix #6900: sphinx-build: Allow to pass boolean value via ``-D`` option
This commit is contained in:
Takeshi KOMIYA 2019-12-15 22:21:43 +09:00 committed by GitHub
commit d6f1351528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View File

@ -89,6 +89,8 @@ Bugs fixed
* #6876: LaTeX: multi-line display of authors on title page has ragged edges
* #6887: Sphinx crashes with docutils-0.16b0
* #6920: sphinx-build: A console message is wrongly highlighted
* #6900: sphinx-build: ``-D`` option does not considers ``0`` and ``1`` as a
boolean value
Testing
--------

View File

@ -464,7 +464,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
app.add_config_value('latex_logo', None, None, [str])
app.add_config_value('latex_appendices', [], None)
app.add_config_value('latex_use_latex_multicolumn', False, None)
app.add_config_value('latex_use_xindy', default_latex_use_xindy, None)
app.add_config_value('latex_use_xindy', default_latex_use_xindy, None, [bool])
app.add_config_value('latex_toplevel_sectioning', None, None,
ENUM(None, 'part', 'chapter', 'section'))
app.add_config_value('latex_domain_indices', True, None, [list])

View File

@ -217,6 +217,12 @@ class Config:
defvalue = self.values[name][0]
if self.values[name][2] == Any:
return value
elif type(defvalue) is bool or self.values[name][2] == [bool]:
if value == '0':
# given falsy string from command line option
return False
else:
return bool(value)
elif isinstance(defvalue, dict):
raise ValueError(__('cannot override dictionary config setting %r, '
'ignoring (use %r to set individual elements)') %

View File

@ -119,6 +119,20 @@ def test_overrides():
assert config.value8 == ['abc', 'def', 'ghi']
def test_overrides_boolean():
config = Config({}, {'value1': '1',
'value2': '0',
'value3': '0'})
config.add('value1', None, 'env', [bool])
config.add('value2', None, 'env', [bool])
config.add('value3', True, 'env', ())
config.init_values()
assert config.value1 is True
assert config.value2 is False
assert config.value3 is False
@mock.patch("sphinx.config.logger")
def test_errors_warnings(logger, tempdir):
# test the error for syntax errors in the config file