From f781f55b28662cf759f06cda48f7b48a6c0c70e6 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Mon, 30 Jun 2014 22:54:28 +0900 Subject: [PATCH] * With non-callable `setup` in a conf.py, now sphinx-build emits user-friendly error message. Closes #1499 --- CHANGES | 2 ++ sphinx/application.py | 12 ++++++++++-- tests/test_config.py | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 08cc0ad4c..7133c9b83 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,8 @@ Bugs fixed Thanks to Jorge_C. * #1467: Exception on Python3 if nonexistent method is specified by automethod * #1441: autosummary can't handle nested classes correctly. +* #1499: With non-callable `setup` in a conf.py, now sphinx-build emits + user-friendly error message. Release 1.2.2 (released Mar 2, 2014) ==================================== diff --git a/sphinx/application.py b/sphinx/application.py index 9030adf99..4fb9eb384 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -27,7 +27,7 @@ from sphinx import package_dir, locale from sphinx.roles import XRefRole from sphinx.config import Config from sphinx.errors import SphinxError, SphinxWarning, ExtensionError, \ - VersionRequirementError + VersionRequirementError, ConfigError from sphinx.domains import ObjType, BUILTIN_DOMAINS from sphinx.domains.std import GenericObject, Target, StandardDomain from sphinx.builders import BUILTIN_BUILDERS @@ -119,7 +119,15 @@ class Sphinx(object): self.setup_extension(extension) # the config file itself can be an extension if self.config.setup: - self.config.setup(self) + # py31 doesn't have 'callable' function for bellow check + if hasattr(self.config.setup, '__call__'): + self.config.setup(self) + else: + raise ConfigError( + "'setup' that is specified in the conf.py has not been " + + "callable. Please provide a callable `setup` function " + + "in order to behave as a sphinx extension conf.py itself." + ) # now that we know all config values, collect them from conf.py self.config.init_values() diff --git a/tests/test_config.py b/tests/test_config.py index 976b962fb..1e00091dd 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -110,6 +110,13 @@ def test_errors_warnings(dir): assert warned[0] +@with_tempdir +def test_errors_if_setup_is_not_callable(dir): + # test the error to call setup() in the config file + (dir / 'conf.py').write_text(u'setup = 1') + raises_msg(ConfigError, 'callable', TestApp, srcdir=dir) + + def test_needs_sphinx(): raises(VersionRequirementError, TestApp, confoverrides={'needs_sphinx': '9.9'})