Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Use standard IPython startup instead of embed #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 30 additions & 10 deletions flask_script/commands.py
Expand Up @@ -230,6 +230,35 @@ def get_context(self):
""" """
return self.make_context() 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): def run(self, no_ipython, no_bpython):
""" """
Runs the shell. If no_bpython is False or use_bpython is True, then Runs the shell. If no_bpython is False or use_bpython is True, then
Expand All @@ -249,17 +278,8 @@ def run(self, no_ipython, no_bpython):
pass pass


if not no_ipython: if not no_ipython:
# Try IPython
try: try:
try: self.ipython(context)
# 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 import embed
embed(banner1=self.banner, user_ns=context)
return return
except ImportError: except ImportError:
pass pass
Expand Down