From 7984dd0750b5ef8926c1aafae578d321f84450e7 Mon Sep 17 00:00:00 2001 From: Keith Mitchell Date: Wed, 28 Oct 2020 15:10:18 -0600 Subject: [PATCH] Switch from 'embedding' to 'starting' IPython Embedding IPython results in issues where import statements and other globals changes in the shell environment don't work as expected.[1] As an example, the following commands result in a NameError: In [1]: import time In [2]: def foo(): ...: print(time.time()) ...: In [3]: foo() --------------------------------------------------------------------------- NameError Traceback (most recent call last) in ----> 1 foo() in foo() 1 def foo(): ----> 2 print(time.time()) 3 NameError: name 'time' is not defined By switching to use "start_ipython()" instead, we get an environment more similar to what we get by running `ipython` directly. [1] https://github.com/ipython/ipython/issues/62 --- baseplate/server/__init__.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/baseplate/server/__init__.py b/baseplate/server/__init__.py index 11274eddb..f00e29c0b 100644 --- a/baseplate/server/__init__.py +++ b/baseplate/server/__init__.py @@ -374,11 +374,9 @@ def load_and_run_shell() -> None: try: # try to use IPython if possible - from IPython.terminal.embed import InteractiveShellEmbed - from IPython.core.interactiveshell import DummyMod - - shell = InteractiveShellEmbed(banner2=banner) - shell(local_ns=env, module=DummyMod()) + from IPython import start_ipython + start_ipython(argv=[], user_ns=env) + raise SystemExit except ImportError: import code