summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-02 16:40:30 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-02 16:40:30 +0000
commitc793f910ba4055d84cd4cff536a8b58c2f07d87f (patch)
tree9dc18154e693abebccb804b9c1d9c7a025823c4b
parente218b2a4b749d5e7105ffd28f2c02f09b151059b (diff)
downloadpyramid-c793f910ba4055d84cd4cff536a8b58c2f07d87f.tar.gz
pyramid-c793f910ba4055d84cd4cff536a8b58c2f07d87f.tar.bz2
pyramid-c793f910ba4055d84cd4cff536a8b58c2f07d87f.zip
- Compound statements that used an assignment entered into in an
interactive IPython session invoked via ``paster bfgshell`` no longer fail to mutate the shell namespace correctly. For example, this set of statements used to fail:: In [2]: def bar(x): return x ...: In [3]: list(bar(x) for x in 'abc') Out[3]: NameError: 'bar' In this release, the ``bar`` function is found and the correct output is now sent to the console. Thanks to Daniel Holth for the patch.
-rw-r--r--CHANGES.txt20
-rw-r--r--repoze/bfg/paster.py14
-rw-r--r--repoze/bfg/tests/test_paster.py13
3 files changed, 34 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e8e13496e..6ce4a56fc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,23 @@
+Next release
+============
+
+Bug Fixes
+---------
+
+- Compound statements that used an assignment entered into in an
+ interactive IPython session invoked via ``paster bfgshell`` no
+ longer fail to mutate the shell namespace correctly. For example,
+ this set of statements used to fail::
+
+ In [2]: def bar(x): return x
+ ...:
+ In [3]: list(bar(x) for x in 'abc')
+ Out[3]: NameError: 'bar'
+
+ In this release, the ``bar`` function is found and the correct
+ output is now sent to the console. Thanks to Daniel Holth for the
+ patch.
+
1.1b2 (2009-11-02)
==================
diff --git a/repoze/bfg/paster.py b/repoze/bfg/paster.py
index de5dc1f79..e57d17c1b 100644
--- a/repoze/bfg/paster.py
+++ b/repoze/bfg/paster.py
@@ -10,9 +10,9 @@ from paste.util.template import paste_script_template_renderer
from repoze.bfg.scripting import get_root
try:
- from IPython.Shell import IPShellEmbed
+ from IPython.Shell import IPShell
except ImportError:
- IPShellEmbed = None
+ IPShell = None
class StarterProjectTemplate(Template):
@@ -79,7 +79,7 @@ class BFGShellCommand(Command):
interact = (interact,) # for testing
loadapp = (loadapp,) # for testing
- IPShellEmbed = IPShellEmbed # for testing
+ IPShell = IPShell # for testing
verbose = 3
def command(self):
@@ -89,11 +89,11 @@ class BFGShellCommand(Command):
config_file, section_name = self.args
app = get_app(config_file, section_name, loadapp=self.loadapp[0])
root, closer = get_root(app)
- if self.IPShellEmbed is not None and not self.options.disable_ipython:
- shell = self.IPShellEmbed(argv=self.args)
- shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
+ if self.IPShell is not None and not self.options.disable_ipython:
try:
- shell(local_ns={'root':root}, global_ns={})
+ shell = self.IPShell(argv=[], user_ns={'root':root})
+ shell.IP.BANNER = shell.IP.BANNER + '\n\n' + banner
+ shell.mainloop()
finally:
closer()
else:
diff --git a/repoze/bfg/tests/test_paster.py b/repoze/bfg/tests/test_paster.py
index 4650f04cd..7752e1684 100644
--- a/repoze/bfg/tests/test_paster.py
+++ b/repoze/bfg/tests/test_paster.py
@@ -39,7 +39,7 @@ class TestBFGShellCommand(unittest.TestCase):
loadapp = DummyLoadApp(app)
command.loadapp = (loadapp,)
dummy_shell_factory = DummyIPShellFactory()
- command.IPShellEmbed = dummy_shell_factory
+ command.IPShell = dummy_shell_factory
command.args = ('/foo/bar/myapp.ini', 'myapp')
class Options(object): pass
command.options = Options()
@@ -54,7 +54,7 @@ class TestBFGShellCommand(unittest.TestCase):
self.assertEqual(pushed['request'], None)
self.assertEqual(dummy_shell_factory.shell.local_ns,{'root':dummy_root})
self.assertEqual(dummy_shell_factory.shell.global_ns, {})
- self.failUnless(dummy_shell_factory.shell.banner)
+ self.failUnless('\n\n' in dummy_shell_factory.shell.IP.BANNER)
self.assertEqual(len(app.threadlocal_manager.popped), 1)
class TestGetApp(unittest.TestCase):
@@ -76,21 +76,22 @@ class Dummy:
pass
class DummyIPShellFactory(object):
- def __call__(self, argv):
+ def __call__(self, argv, user_ns=None):
shell = DummyIPShell()
+ shell(user_ns, {})
self.shell = shell
return shell
class DummyIPShell(object):
IP = Dummy()
IP.BANNER = 'foo'
- def set_banner(self, banner):
- self.banner = banner
-
def __call__(self, local_ns, global_ns):
self.local_ns = local_ns
self.global_ns = global_ns
+ def mainloop(self):
+ pass
+
dummy_root = Dummy()
dummy_registry = Dummy()