diff options
| -rw-r--r-- | docs/narr/commandline.rst | 20 | ||||
| -rw-r--r-- | pyramid/scripts/pshell.py | 17 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_pshell.py | 24 |
3 files changed, 35 insertions, 26 deletions
diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst index 89df13ce4..cb0c914d7 100644 --- a/docs/narr/commandline.rst +++ b/docs/narr/commandline.rst @@ -245,7 +245,7 @@ exposed, and the request is configured to generate urls from the host .. code-block:: text $ $VENV/bin/pshell starter/development.ini - Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32) + Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32) [GCC 4.4.3] on linux2 Type "help" for more information. @@ -278,10 +278,10 @@ IPython or bpython If you have `IPython <http://en.wikipedia.org/wiki/IPython>`_ and/or `bpython <http://bpython-interpreter.org/>`_ in -the interpreter you use to invoke the ``pshell`` command, ``pshell`` will +the interpreter you use to invoke the ``pshell`` command, ``pshell`` will autodiscover and use the first one found, in this order: -IPython, bpython, standard Python interpreter. However you could -specifically invoke one of your choice with the ``-p choice`` or +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 @@ -308,20 +308,16 @@ and then your shell factory should return a function that accepts two arguments, .. code-block:: python def ptpython_shell_factory(): - try: - from ptpython.repl import embed - def PTPShell(banner, **kwargs): - print(banner) - return embed(**kwargs) - except ImportError: - return None + from ptpython.repl import embed + def PTPShell(banner, **kwargs): + print(banner) + return embed(**kwargs) def shell(env, help): PTPShell(banner=help, locals=env) return shell - .. index:: pair: routes; printing single: proutes diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py index 563418302..9c2573caa 100644 --- a/pyramid/scripts/pshell.py +++ b/pyramid/scripts/pshell.py @@ -98,7 +98,7 @@ class PShellCommand(object): env = self.bootstrap[0](config_uri, options=parse_vars(self.args[1:])) # remove the closer from the env - closer = env.pop('closer') + self.closer = env.pop('closer') # setup help text for default environment env_help = dict(env) @@ -148,7 +148,12 @@ class PShellCommand(object): help += '\n %-12s %s' % (var, self.object_help[var]) if shell is None: - shell = self.make_shell() + try: + shell = self.make_shell() + except ValueError as e: + self.out(str(e)) + self.closer() + return 1 if self.pystartup and os.path.isfile(self.pystartup): with open(self.pystartup, 'rb') as fp: @@ -159,12 +164,12 @@ class PShellCommand(object): try: shell(env, help) finally: - closer() + self.closer() def make_shell(self): shells = {} - priority_order = ['ipython', 'bpython'] + priority_order = ['ipython', 'bpython', 'python'] for ep in self.pkg_resources.iter_entry_points('pyramid.pshell'): name = ep.name @@ -189,6 +194,10 @@ class PShellCommand(object): if factory is not None: shell = factory() + else: + raise ValueError( + 'could not find a shell named "%s"' % user_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 b5c2775d6..985a3010e 100644 --- a/pyramid/tests/test_scripts/test_pshell.py +++ b/pyramid/tests/test_scripts/test_pshell.py @@ -89,6 +89,13 @@ class TestPShellCommand(unittest.TestCase): def test_command_loads_default_shell_with_unknown_shell(self): command = self._makeOne() + out_calls = [] + + def out(msg): + out_calls.append(msg) + + command.out = out + shell = dummy.DummyShell() bad_shell = dummy.DummyShell() @@ -101,21 +108,17 @@ class TestPShellCommand(unittest.TestCase): ) command.make_default_shell = lambda: shell - command.options.python_shell = 'unknow_python_shell' - command.run() + command.options.python_shell = 'unknown_python_shell' + result = command.run() + self.assertEqual(result, 1) + self.assertEqual( + out_calls, ['could not find a shell named "unknown_python_shell"'] + ) 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.env, { - 'app':self.bootstrap.app, 'root':self.bootstrap.root, - 'registry':self.bootstrap.registry, - 'request':self.bootstrap.request, - 'root_factory':self.bootstrap.root_factory, - }) - self.assertEqual(bad_shell.env, {}) self.assertTrue(self.bootstrap.closer.called) - self.assertTrue(shell.help) def test_command_loads_ipython_v1_1(self): command = self._makeOne() @@ -219,6 +222,7 @@ class TestPShellCommand(unittest.TestCase): { 'ipython': lambda: ipshell, 'bpython': lambda: bpshell, + 'python': lambda: dshell, } ) |
