From 6b2cf6319990a6a960b2d8759497c8190966371d Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Thu, 15 Aug 2013 12:55:18 -0500 Subject: [PATCH 1/2] Use standard IPython startup instead of embed --- flask_script/commands.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/flask_script/commands.py b/flask_script/commands.py index b0b3dee..e4e14c1 100644 --- a/flask_script/commands.py +++ b/flask_script/commands.py @@ -258,8 +258,11 @@ def run(self, no_ipython, no_bpython): ipshell(global_ns=dict(), local_ns=context) except ImportError: # 0.12+ - from IPython import embed - embed(banner1=self.banner, user_ns=context) + from IPython.terminal.ipapp import TerminalIPythonApp + app = TerminalIPythonApp.instance(banner1=self.banner, + user_ns=context) + app.initialize(argv=[]) + app.start() return except ImportError: pass From be34f4113f8fdc4ab16deb4f5b44478dd8f4c478 Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Mon, 19 Aug 2013 11:20:19 -0500 Subject: [PATCH 2/2] Re-wrote IPython startup to work with custom user_ns and banner --- flask_script/commands.py | 43 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/flask_script/commands.py b/flask_script/commands.py index e4e14c1..bb27eab 100644 --- a/flask_script/commands.py +++ b/flask_script/commands.py @@ -230,6 +230,35 @@ def get_context(self): """ return self.make_context() + def ipython(self, context): + try: + # 0.10.x + from IPython.Shell import IPShellEmbed + ipshell = IPShellEmbed(banner=self.banner) + ipshell(global_ns=dict(), local_ns=context) + except ImportError: + # 0.12+ + try: + from IPython.terminal import ipapp + except ImportError: + from IPython.frontend.terminal import ipapp + app = ipapp.TerminalIPythonApp.instance() + shell = ipapp.TerminalInteractiveShell.instance( + parent=app, + display_banner=False, + profile_dir=app.profile_dir, + ipython_dir=app.ipython_dir, + user_ns=context, + banner1=self.banner) + shell.configurables.append(app) + app.shell = shell + # shell has already been initialized, so we have to monkeypatch + # app.init_shell() to act as no-op + app.init_shell = lambda: None + app.initialize(argv=[]) + app.start() + + def run(self, no_ipython, no_bpython): """ Runs the shell. If no_bpython is False or use_bpython is True, then @@ -249,20 +278,8 @@ def run(self, no_ipython, no_bpython): pass if not no_ipython: - # Try IPython try: - try: - # 0.10.x - from IPython.Shell import IPShellEmbed - ipshell = IPShellEmbed(banner=self.banner) - ipshell(global_ns=dict(), local_ns=context) - except ImportError: - # 0.12+ - from IPython.terminal.ipapp import TerminalIPythonApp - app = TerminalIPythonApp.instance(banner1=self.banner, - user_ns=context) - app.initialize(argv=[]) - app.start() + self.ipython(context) return except ImportError: pass