diff options
| author | Jean-Philippe Camguilhem <jp.camguilhem@gmail.com> | 2011-11-19 16:09:41 +0100 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2011-11-21 20:47:54 -0600 |
| commit | f1013bebcdd013cd1cb47cf7585c0eaa34ec3b75 (patch) | |
| tree | 3051fd9b58b0f3f1c4e4a5b0a0341db85841bc88 | |
| parent | c96ca8631d7899b2fe6770180b066fbec031473d (diff) | |
| download | pyramid-f1013bebcdd013cd1cb47cf7585c0eaa34ec3b75.tar.gz pyramid-f1013bebcdd013cd1cb47cf7585c0eaa34ec3b75.tar.bz2 pyramid-f1013bebcdd013cd1cb47cf7585c0eaa34ec3b75.zip | |
add bpython support for pshell
| -rw-r--r-- | docs/narr/commandline.rst | 14 | ||||
| -rw-r--r-- | pyramid/scripts/pshell.py | 18 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/dummy.py | 9 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_pshell.py | 9 |
4 files changed, 48 insertions, 2 deletions
diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index 0dc41e919..dc2b75ed6 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -111,6 +111,7 @@ For a URL that doesn't match any views, ``pviews`` will simply print out a single: interactive shell single: IPython single: pshell + single: bpython .. _interactive_shell: @@ -284,6 +285,19 @@ standard Python interpreter shell 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/pshell --enable-bpython \ + development.ini#MyProject + .. index:: pair: routes; printing single: proutes diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 499d96aca..d04d9faff 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -40,6 +40,10 @@ class PShellCommand(object): 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 " @@ -142,6 +146,9 @@ 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() + if shell is None and not self.options.disable_ipython: shell = self.make_ipython_v0_11_shell() if shell is None: @@ -163,6 +170,17 @@ class PShellCommand(object): 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: diff --git a/pyramid/tests/test_scripts/dummy.py b/pyramid/tests/test_scripts/dummy.py index 3275f7804..d580203af 100644 --- a/pyramid/tests/test_scripts/dummy.py +++ b/pyramid/tests/test_scripts/dummy.py @@ -5,7 +5,7 @@ class DummyTweens(object): self.name_to_alias = {} def implicit(self): return self._implicit - + class Dummy: pass @@ -31,6 +31,11 @@ class DummyInteractor: 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' @@ -72,7 +77,7 @@ class DummyRoute(object): def match(self, route): return self.matchdict - + class DummyRequest: application_url = 'http://example.com:5432' script_name = '' diff --git a/pyramid/tests/test_scripts/test_pshell.py b/pyramid/tests/test_scripts/test_pshell.py index e38da2077..95bdce463 100644 --- a/pyramid/tests/test_scripts/test_pshell.py +++ b/pyramid/tests/test_scripts/test_pshell.py @@ -22,6 +22,7 @@ class TestPShellCommand(unittest.TestCase): 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 @@ -34,6 +35,14 @@ class TestPShellCommand(unittest.TestCase): self.assertEqual(interact.local, {'foo': 'bar'}) self.assertTrue('a help message' in interact.banner) + def test_make_bpython_shell(self): + command = self._makeOne() + bpython = dummy.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 = dummy.DummyIPShellFactory() |
