summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt3
-rw-r--r--repoze/bfg/paster.py20
-rw-r--r--repoze/bfg/tests/test_paster.py5
3 files changed, 14 insertions, 14 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 7833eb35f..5b43d7292 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,6 +17,9 @@ Backwards Incompatibilities
Bug Fixes
---------
+- Defer conditional import of IPython to avoid breakage under mod_wsgi.
+ http://bugs.repoze.org/issue138
+
- More correct conversion of provided ``renderer`` values to resource
specification values (internal).
diff --git a/repoze/bfg/paster.py b/repoze/bfg/paster.py
index da1be9692..e0d17f6b4 100644
--- a/repoze/bfg/paster.py
+++ b/repoze/bfg/paster.py
@@ -9,11 +9,6 @@ from paste.util.template import paste_script_template_renderer
from repoze.bfg.scripting import get_root
-try:
- from IPython.Shell import IPShell # pragma: no cover
-except ImportError:
- IPShell = None # pragma: no cover
-
class StarterProjectTemplate(Template):
_template_dir = 'paster_templates/starter'
@@ -43,6 +38,7 @@ def get_app(config_file, name, loadapp=loadapp):
app = loadapp(config_name, name=name, relative_to=here_dir)
return app
+_marker = object()
class BFGShellCommand(Command):
"""Open an interactive shell with a :mod:`repoze.bfg` app loaded.
@@ -78,7 +74,6 @@ class BFGShellCommand(Command):
interact = (interact,) # for testing
loadapp = (loadapp,) # for testing
- IPShell = IPShell # for testing
verbose = 3
def __init__(self, *arg, **kw):
@@ -87,7 +82,12 @@ class BFGShellCommand(Command):
self.usage = '\n' + self.__doc__
Command.__init__(self, *arg, **kw)
- def command(self):
+ def command(self, IPShell=_marker):
+ if IPShell is _marker:
+ try: #pragma no cover
+ from IPython.Shell import IPShell
+ except ImportError: #pragma no cover
+ IPShell = None
cprt =('Type "help" for more information. "root" is the BFG app '
'root object.')
banner = "Python %s on %s\n%s" % (sys.version, sys.platform, cprt)
@@ -95,9 +95,9 @@ class BFGShellCommand(Command):
self.logging_file_config(config_file)
app = get_app(config_file, section_name, loadapp=self.loadapp[0])
root, closer = get_root(app)
- if self.IPShell is not None and not self.options.disable_ipython:
+ if IPShell is not None and not self.options.disable_ipython:
try:
- shell = self.IPShell(argv=[], user_ns={'root':root})
+ shell = IPShell(argv=[], user_ns={'root':root})
shell.IP.BANNER = shell.IP.BANNER + '\n\n' + banner
shell.mainloop()
finally:
@@ -107,5 +107,3 @@ class BFGShellCommand(Command):
self.interact[0](banner, local={'root':root})
finally:
closer()
-
-
diff --git a/repoze/bfg/tests/test_paster.py b/repoze/bfg/tests/test_paster.py
index cabde215e..c2bbb12ad 100644
--- a/repoze/bfg/tests/test_paster.py
+++ b/repoze/bfg/tests/test_paster.py
@@ -20,7 +20,7 @@ class TestBFGShellCommand(unittest.TestCase):
class Options(object): pass
command.options = Options()
command.options.disable_ipython =True
- command.command()
+ command.command(IPShell=None)
self.assertEqual(loadapp.config_name, 'config:/foo/bar/myapp.ini')
self.assertEqual(loadapp.section_name, 'myapp')
self.failUnless(loadapp.relative_to)
@@ -38,12 +38,11 @@ class TestBFGShellCommand(unittest.TestCase):
loadapp = DummyLoadApp(app)
command.loadapp = (loadapp,)
dummy_shell_factory = DummyIPShellFactory()
- command.IPShell = dummy_shell_factory
command.args = ('/foo/bar/myapp.ini', 'myapp')
class Options(object): pass
command.options = Options()
command.options.disable_ipython = False
- command.command()
+ command.command(IPShell=dummy_shell_factory)
self.assertEqual(loadapp.config_name, 'config:/foo/bar/myapp.ini')
self.assertEqual(loadapp.section_name, 'myapp')
self.failUnless(loadapp.relative_to)