summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Camguilhem <jp.camguilhem@gmail.com>2011-11-22 00:20:07 +0100
committerMichael Merickel <michael@merickel.org>2011-11-21 20:47:55 -0600
commit2cf5d280866e8936b0fee0952c89ebde164337ee (patch)
tree3dfbb22416ecf914f473d5a5114fc5d87d418aa4
parent7bae406b11df0e3039798898e7951a09f31c0e53 (diff)
downloadpyramid-2cf5d280866e8936b0fee0952c89ebde164337ee.tar.gz
pyramid-2cf5d280866e8936b0fee0952c89ebde164337ee.tar.bz2
pyramid-2cf5d280866e8936b0fee0952c89ebde164337ee.zip
add bpython support to pshell with raydeo remarks and design
-rw-r--r--docs/narr/commandline.rst34
-rw-r--r--pyramid/scripts/pshell.py26
-rw-r--r--pyramid/tests/test_scripts/test_pshell.py55
3 files changed, 56 insertions, 59 deletions
diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst
index dc2b75ed6..0f0e17ca6 100644
--- a/docs/narr/commandline.rst
+++ b/docs/narr/commandline.rst
@@ -268,34 +268,22 @@ exposed, and the request is configured to generate urls from the host
.. index::
single: IPython
+ single: bpython
-IPython
-~~~~~~~
-
-If you have `IPython <http://en.wikipedia.org/wiki/IPython>`_ installed in
-the interpreter you use to invoke the ``pshell`` command, ``pshell`` will use
-an IPython interactive shell instead of a standard Python interpreter shell.
-If you don't want this to happen, even if you have IPython installed, you can
-pass the ``--disable-ipython`` flag to the ``pshell`` command to use a
-standard Python interpreter shell unconditionally.
-
-.. code-block:: text
-
- [chrism@vitaminf shellenv]$ ../bin/pshell --disable-ipython \
- development.ini#MyProject
-
-
-bpython
-~~~~~~~
+IPython or bpython
+~~~~~~~~~~~~~~~~~~
-If you have `bpython <http://bpython-interpreter.org/>`_ installed in
-the interpreter you use to invoke the ``pshell`` command, ``pshell`` will use
-a bpython interactive shell instead of a standard Python if you pass the ``-b``
-or ``--enable-bpython`` flag to the ``pshell`` command.
+If you have `IPython <http://en.wikipedia.org/wiki/IPython>`_ or
+`bpython <http://bpython-interpreter.org/>`_ or both installed in
+the interpreter you use to invoke the ``pshell`` command, ``pshell`` will
+autodiscover them and use the first respectively found in this order :
+IPython, bpython, standard Python interpreter. However you could
+specifically invoke one of your choice with the ``-p choice`` or
+``--python-shell choice`` option.
.. code-block:: text
- [chrism@vitaminf shellenv]$ ../bin/pshell --enable-bpython \
+ [chrism@vitaminf shellenv]$ ../bin/pshell -p ipython | bpython | python \
development.ini#MyProject
.. index::
diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py
index d04d9faff..3fbfa5e62 100644
--- a/pyramid/scripts/pshell.py
+++ b/pyramid/scripts/pshell.py
@@ -36,14 +36,9 @@ class PShellCommand(object):
summary = "Open an interactive shell with a Pyramid application loaded"
parser = optparse.OptionParser()
- parser.add_option('-d', '--disable-ipython',
- action='store_true',
- dest='disable_ipython',
- help="Don't use IPython even if it is available")
- parser.add_option('-b', '--enable-bpython',
- action='store_true',
- dest='enable_bpython',
- help="Use bpython as pshell")
+ parser.add_option('-p', '--python-shell',
+ action='store', type='string', dest='python_shell',
+ default = '', help='ipython | bpython | python')
parser.add_option('--setup',
dest='setup',
help=("A callable that will be passed the environment "
@@ -146,14 +141,23 @@ class PShellCommand(object):
for var in sorted(self.object_help.keys()):
help += '\n %-12s %s' % (var, self.object_help[var])
- if shell is None and self.options.enable_bpython:
- shell = self.make_bpython_shell()
+ user_shell = self.options.python_shell.lower()
+ if not user_shell:
+ if shell is None:
+ shell = self.make_ipython_v0_11_shell()
+ if shell is None:
+ shell = self.make_ipython_v0_10_shell()
+ if shell is None:
+ shell = self.make_bpython_shell()
- if shell is None and not self.options.disable_ipython:
+ if shell is None and user_shell == 'ipython':
shell = self.make_ipython_v0_11_shell()
if shell is None:
shell = self.make_ipython_v0_10_shell()
+ if shell is None and user_shell == 'bpython':
+ shell = self.make_bpython_shell()
+
if shell is None:
shell = self.make_default_shell()
diff --git a/pyramid/tests/test_scripts/test_pshell.py b/pyramid/tests/test_scripts/test_pshell.py
index 4f3853f91..4e5deb31d 100644
--- a/pyramid/tests/test_scripts/test_pshell.py
+++ b/pyramid/tests/test_scripts/test_pshell.py
@@ -21,8 +21,7 @@ class TestPShellCommand(unittest.TestCase):
if patch_options:
class Options(object): pass
self.options = Options()
- self.options.disable_ipython = True
- self.options.enable_bpython = False
+ self.options.python_shell = ''
self.options.setup = None
cmd.options = self.options
return cmd
@@ -67,6 +66,7 @@ class TestPShellCommand(unittest.TestCase):
shell = dummy.DummyShell()
command.make_ipython_v0_11_shell = lambda: None
command.make_ipython_v0_10_shell = lambda: None
+ command.make_bpython_shell = lambda: None
command.make_default_shell = lambda: shell
command.run()
self.assertTrue(self.config_factory.parser)
@@ -82,33 +82,15 @@ class TestPShellCommand(unittest.TestCase):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
- def test_command_loads_bpython_shell(self):
- command = self._makeOne()
- shell = dummy.DummyBPythonShell()
- command.make_bpython_shell = lambda: shell
- command.options.enable_bpython = True
- command.run()
- self.assertTrue(self.config_factory.parser)
- self.assertEqual(self.config_factory.parser.filename,
- '/foo/bar/myapp.ini')
- self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.locals_, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- })
- self.assertTrue(self.bootstrap.closer.called)
- self.assertTrue(shell.banner)
-
- def test_command_loads_default_shell_with_ipython_disabled(self):
+ def test_command_loads_default_shell_with_unknow_shell(self):
command = self._makeOne()
shell = dummy.DummyShell()
bad_shell = dummy.DummyShell()
command.make_ipython_v0_11_shell = lambda: bad_shell
command.make_ipython_v0_10_shell = lambda: bad_shell
+ command.make_bpython_shell = lambda: bad_shell
command.make_default_shell = lambda: shell
- command.options.disable_ipython = True
+ command.options.python_shell = 'unknow_python_shell'
command.run()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -129,8 +111,9 @@ class TestPShellCommand(unittest.TestCase):
shell = dummy.DummyShell()
command.make_ipython_v0_11_shell = lambda: shell
command.make_ipython_v0_10_shell = lambda: None
+ command.make_bpython_shell = lambda: None
command.make_default_shell = lambda: None
- command.options.disable_ipython = False
+ command.options.python_shell = 'ipython'
command.run()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -150,8 +133,9 @@ class TestPShellCommand(unittest.TestCase):
shell = dummy.DummyShell()
command.make_ipython_v0_11_shell = lambda: None
command.make_ipython_v0_10_shell = lambda: shell
+ command.make_bpython_shell = lambda: None
command.make_default_shell = lambda: None
- command.options.disable_ipython = False
+ command.options.python_shell = 'ipython'
command.run()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -166,6 +150,27 @@ class TestPShellCommand(unittest.TestCase):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
+ def test_command_loads_bpython_shell(self):
+ command = self._makeOne()
+ shell = dummy.DummyBPythonShell()
+ command.make_ipython_v0_11_shell = lambda: None
+ command.make_ipython_v0_10_shell = lambda: None
+ command.make_bpython_shell = lambda: shell
+ command.options.python_shell = 'bpython'
+ command.run()
+ self.assertTrue(self.config_factory.parser)
+ self.assertEqual(self.config_factory.parser.filename,
+ '/foo/bar/myapp.ini')
+ self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
+ self.assertEqual(shell.locals_, {
+ 'app':self.bootstrap.app, 'root':self.bootstrap.root,
+ 'registry':self.bootstrap.registry,
+ 'request':self.bootstrap.request,
+ 'root_factory':self.bootstrap.root_factory,
+ })
+ self.assertTrue(self.bootstrap.closer.called)
+ self.assertTrue(shell.banner)
+
def test_command_loads_custom_items(self):
command = self._makeOne()
model = dummy.Dummy()