Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add bpython support to pshell

  • Loading branch information...
commit c28a03e359c90f097ab9e895fe6c3695bedf03e5 1 parent 28f21cd
@jpcw jpcw authored
View
16 docs/narr/commandline.rst
@@ -110,6 +110,7 @@ out a *Not found* message.
.. index::
single: interactive shell
single: IPython
+ single: bpython
single: paster pshell
single: pshell
@@ -286,6 +287,21 @@ unconditionally.
development.ini#MyProject
+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.
+
+.. code-block:: text
+
+ [chrism@vitaminf shellenv]$ ../bin/paster pshell --enable-bpython \
+ development.ini#MyProject
+
+
+
.. index::
pair: routes; printing
single: paster proutes
View
18 pyramid/paster.py
@@ -131,6 +131,10 @@ class PShellCommand(PCommand):
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('--setup',
dest='setup',
help=("A callable that will be passed the environment "
@@ -222,6 +226,9 @@ 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()
+
if shell is None and not self.options.disable_ipython:
shell = self.make_ipython_v0_11_shell()
if shell is None:
@@ -243,6 +250,17 @@ def shell(env, help):
interact(banner, local=env)
return shell
+ def make_bpython_shell(self, BPShellFactory=None):
+ if BPShellFactory is None: # pragma: no cover
+ try:
+ from bpython import embed
+ BPShellFactory = embed
+ except ImportError:
+ return None
+ def shell(env, help):
+ BPShell = BPShellFactory(locals_=env, banner=help + '\n')
+ return shell
+
def make_ipython_v0_11_shell(self, IPShellFactory=None):
if IPShellFactory is None: # pragma: no cover
try:
View
47 pyramid/tests/test_paster.py
@@ -21,6 +21,7 @@ def _makeOne(self, patch_bootstrap=True, patch_config=True,
class Options(object): pass
self.options = Options()
self.options.disable_ipython = True
+ self.options.enable_bpython = False
self.options.setup = None
cmd.options = self.options
return cmd
@@ -33,6 +34,14 @@ def test_make_default_shell(self):
self.assertEqual(interact.local, {'foo': 'bar'})
self.assertTrue('a help message' in interact.banner)
+ def test_make_bpython_shell(self):
+ command = self._makeOne()
+ bpython = DummyBPythonShell()
+ shell = command.make_bpython_shell(bpython)
+ shell({'foo': 'bar'}, 'a help message')
+ self.assertEqual(bpython.locals_, {'foo': 'bar'})
+ self.assertTrue('a help message' in bpython.banner)
+
def test_make_ipython_v0_11_shell(self):
command = self._makeOne()
ipshell_factory = DummyIPShellFactory()
@@ -72,6 +81,25 @@ 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):
command = self._makeOne()
shell = DummyShell()
@@ -334,7 +362,7 @@ class IMyRoute(Interface):
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
self.assertEqual(L[-1].split()[:4], ['a', '/a', '<function', 'view'])
-
+
def test_single_route_one_view_registered_with_factory(self):
from zope.interface import Interface
from pyramid.registry import Registry
@@ -371,7 +399,7 @@ def test__get_mapper(self):
registry = Registry()
result = command._get_mapper(registry)
self.assertEqual(result.__class__, RoutesMapper)
-
+
class TestPViewsCommand(unittest.TestCase):
def _getTargetClass(self):
from pyramid.paster import PViewsCommand
@@ -570,7 +598,7 @@ def factory(request): pass
result = command._find_multi_routes(mapper, request)
self.assertEqual(result, [{'match':{}, 'route':routes[0]},
{'match':{}, 'route':routes[1]}])
-
+
def test__find_multi_routes_some_match(self):
command = self._makeOne()
def factory(request): pass
@@ -580,7 +608,7 @@ def factory(request): pass
request = DummyRequest({'PATH_INFO':'/a'})
result = command._find_multi_routes(mapper, request)
self.assertEqual(result, [{'match':{}, 'route':routes[1]}])
-
+
def test__find_multi_routes_none_match(self):
command = self._makeOne()
def factory(request): pass
@@ -590,7 +618,7 @@ def factory(request): pass
request = DummyRequest({'PATH_INFO':'/a'})
result = command._find_multi_routes(mapper, request)
self.assertEqual(result, [])
-
+
def test_views_command_not_found(self):
from pyramid.registry import Registry
registry = Registry()
@@ -953,7 +981,7 @@ def __init__(self, implicit, explicit):
self.name_to_alias = {}
def implicit(self):
return self._implicit
-
+
class Dummy:
pass
@@ -979,6 +1007,11 @@ def __call__(self, banner, local):
self.banner = banner
self.local = local
+class DummyBPythonShell:
+ def __call__(self, locals_, banner):
+ self.locals_ = locals_
+ self.banner = banner
+
class DummyIPShell(object):
IP = Dummy()
IP.BANNER = 'foo'
@@ -1030,7 +1063,7 @@ def __init__(self, name, pattern, factory=None,
def match(self, route):
return self.matchdict
-
+
class DummyRequest:
application_url = 'http://example.com:5432'
script_name = ''

0 comments on commit c28a03e

Please sign in to comment.
Something went wrong with that request. Please try again.