diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-09 23:53:55 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-15 22:07:05 +0900 |
| commit | ebdd210a6b2d7884f8f1254ce73bceb121761818 (patch) | |
| tree | bfefcb0ecb4f32547679145f6346ab45a9f311a0 | |
| parent | 2ec6ce85ef781795dcfb63ccef736b33c6ac96a2 (diff) | |
| download | sphinx-git-ebdd210a6b2d7884f8f1254ce73bceb121761818.tar.gz | |
Fix #6900: sphinx-build: -D option does not considers 0 and 1 as a boolean value
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | sphinx/builders/latex/__init__.py | 2 | ||||
| -rw-r--r-- | sphinx/config.py | 6 | ||||
| -rw-r--r-- | tests/test_config.py | 14 |
4 files changed, 23 insertions, 1 deletions
@@ -87,6 +87,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 -------- diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index 6a0d70e5e..de4223a0e 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -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]) diff --git a/sphinx/config.py b/sphinx/config.py index cbe04b3ee..ddee765b7 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -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)') % diff --git a/tests/test_config.py b/tests/test_config.py index a5da0d6ec..1d3a49e95 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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 |
