#196: Add a warning if an extension module doesn't have a `setup()` function.

This commit is contained in:
Georg Brandl 2009-06-15 17:31:29 +02:00
parent f45aeb4b05
commit 5e439cbbb5
3 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,9 @@
Release 0.6.2 (in development) 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; * #158: Allow '..' in template names, and absolute template paths;
Jinja 2 by default disables both. Jinja 2 by default disables both.

View File

@ -167,7 +167,10 @@ class Sphinx(object):
except ImportError, err: except ImportError, err:
raise ExtensionError('Could not import extension %s' % extension, raise ExtensionError('Could not import extension %s' % extension,
err) 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) mod.setup(self)
self._extensions[extension] = mod self._extensions[extension] = mod

View File

@ -57,3 +57,13 @@ def test_output():
assert app._warncount == old_count + 1 assert app._warncount == old_count + 1
finally: finally:
app.cleanup() 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()