diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-20 22:55:29 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-20 22:55:29 -0400 |
commit | f05dfe73d675e198ad271fa23c7dcdcd1f988551 (patch) | |
tree | 2fbca752e6cae94dcfd2ce37286a4c296b82d633 /cmd2 | |
parent | 0ddf61a2b8640d38b182be9100f35350cb2c96f8 (diff) | |
download | cmd2-git-f05dfe73d675e198ad271fa23c7dcdcd1f988551.tar.gz |
cmd2 now considers ipy a pyscript environment
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/cmd2.py | 25 |
1 files changed, 17 insertions, 8 deletions
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 <Ctrl>-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 <Ctrl>-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" |