From f05dfe73d675e198ad271fa23c7dcdcd1f988551 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Mon, 20 Apr 2020 22:55:29 -0400 Subject: cmd2 now considers ipy a pyscript environment --- cmd2/cmd2.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'cmd2/cmd2.py') diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 99ddffa3..c22cb76d 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3191,7 +3191,7 @@ class Cmd(cmd.Cmd): saved_sys_path = None if self.in_pyscript(): - err = "Recursively entering interactive Python consoles is not allowed." + err = "Recursively entering interactive Python shells is not allowed." self.perror(err) return @@ -3341,9 +3341,6 @@ class Cmd(cmd.Cmd): :return: True if running of commands should stop """ from .py_bridge import PyBridge - banner = ('Entering an embedded IPython shell. Type quit or -d to exit.\n' - 'Run Python code from external files with: run filename.py\n') - exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0]) # noinspection PyUnusedLocal def load_ipy(cmd2_app: Cmd, py_bridge: PyBridge): @@ -3364,11 +3361,23 @@ class Cmd(cmd.Cmd): del cmd2_app del py_bridge - embed(banner1=banner, exit_msg=exit_msg) + # Start ipy shell + embed(banner1=('Entering an embedded IPython shell. Type quit or -d to exit.\n' + 'Run Python code from external files with: run filename.py\n'), + exit_msg='Leaving IPython, back to {}'.format(sys.argv[0])) - new_py_bridge = PyBridge(self) - load_ipy(self, new_py_bridge) - return new_py_bridge.stop + if self.in_pyscript(): + err = "Recursively entering interactive Python shells is not allowed." + self.perror(err) + return + + try: + self._in_py = True + new_py_bridge = PyBridge(self) + load_ipy(self, new_py_bridge) + return new_py_bridge.stop + finally: + self._in_py = False history_description = "View, run, edit, save, or clear previously entered commands" -- cgit v1.2.1