Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add bpython support to pshell with raydeo remarks and design

  • Loading branch information...
commit 02b604677c91805c1c0bd2ae9e31eb260261bf9a 1 parent c28a03e
@jpcw jpcw authored
View
36 docs/narr/commandline.rst
@@ -269,39 +269,25 @@ 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 ``paster`` command, the ``pshell``
-command 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/paster 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/paster pshell --enable-bpython \
+ [chrism@vitaminf shellenv]$ ../bin/pshell -p ipython | bpython | python \
development.ini#MyProject
-
.. index::
pair: routes; printing
single: paster proutes
View
26 pyramid/paster.py
@@ -127,14 +127,9 @@ class PShellCommand(PCommand):
max_args = 1
parser = Command.standard_parser(simulate=True)
- 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 "
@@ -226,14 +221,23 @@ def command(self, shell=None):
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()
View
55 pyramid/tests/test_paster.py
@@ -20,9 +20,8 @@ def _makeOne(self, patch_bootstrap=True, patch_config=True,
if patch_options:
class Options(object): pass
self.options = Options()
- self.options.disable_ipython = True
- self.options.enable_bpython = False
self.options.setup = None
+ self.options.python_shell = ''
cmd.options = self.options
return cmd
@@ -66,6 +65,7 @@ def test_command_loads_default_shell(self):
shell = 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.command()
self.assertTrue(self.config_factory.parser)
@@ -81,33 +81,15 @@ def test_command_loads_default_shell(self):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
- def test_command_loads_bpython_shell(self):
- command = self._makeOne()
- shell = DummyBPythonShell()
- command.make_bpython_shell = lambda: shell
- command.options.enable_bpython = True
- command.command()
- 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 = DummyShell()
bad_shell = 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.command()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -128,8 +110,9 @@ def test_command_loads_ipython_v0_11(self):
shell = 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.command()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -149,8 +132,9 @@ def test_command_loads_ipython_v0_10(self):
shell = 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.command()
self.assertTrue(self.config_factory.parser)
self.assertEqual(self.config_factory.parser.filename,
@@ -165,6 +149,27 @@ def test_command_loads_ipython_v0_10(self):
self.assertTrue(self.bootstrap.closer.called)
self.assertTrue(shell.help)
+ def test_command_loads_bpython_shell(self):
+ command = self._makeOne()
+ shell = 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.command()
+ 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()
Please sign in to comment.
Something went wrong with that request. Please try again.