From 5e439cbbb5f791d39ad27f55ea594ad0ef935966 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 15 Jun 2009 17:31:29 +0200 Subject: [PATCH] #196: Add a warning if an extension module doesn't have a ``setup()`` function. --- CHANGES | 3 +++ sphinx/application.py | 5 ++++- tests/test_application.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 72bef47bf..069b3ce53 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 0.6.2 (in development) ============================== +* #196: Add a warning if an extension module doesn't have a + ``setup()`` function. + * #158: Allow '..' in template names, and absolute template paths; Jinja 2 by default disables both. diff --git a/sphinx/application.py b/sphinx/application.py index 62b0c53d6..7e926e572 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -167,7 +167,10 @@ class Sphinx(object): except ImportError, err: raise ExtensionError('Could not import extension %s' % extension, err) - if hasattr(mod, 'setup'): + if not hasattr(mod, 'setup'): + self.warn('extension %r has no setup() function; is it really ' + 'a Sphinx extension module?' % extension) + else: mod.setup(self) self._extensions[extension] = mod diff --git a/tests/test_application.py b/tests/test_application.py index 6425e2753..a113c2359 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -57,3 +57,13 @@ def test_output(): assert app._warncount == old_count + 1 finally: app.cleanup() + + +def test_extensions(): + status, warnings = StringIO(), StringIO() + app = TestApp(status=status, warning=warnings) + try: + app.setup_extension('shutil') + assert warnings.getvalue().startswith("WARNING: extension 'shutil'") + finally: + app.cleanup()