From aa6fb7daaacdb349cdd5b7fe89658e2d056c4722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 10 Oct 2013 00:56:52 -0200 Subject: [PATCH] IPython refuses to update the namespace. fix #396 IPython embedding code borrowed from https://github.com/mitsuhiko/werkzeug/pull/85 --- scrapy/utils/console.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py index 1c4449b85..25782d512 100644 --- a/scrapy/utils/console.py +++ b/scrapy/utils/console.py @@ -1,21 +1,25 @@ -def start_python_console(namespace=None, noipython=False): +def start_python_console(namespace=None, noipython=False, banner=''): """Start Python console binded to the given namespace. If IPython is available, an IPython console will be started instead, unless `noipython` is True. Also, tab completion will be used on Unix systems. """ if namespace is None: namespace = {} + try: try: # use IPython if available if noipython: - raise ImportError - import IPython + raise ImportError() + try: - IPython.embed(user_ns=namespace) - except AttributeError: - shell = IPython.Shell.IPShellEmbed(argv=[], user_ns=namespace) - shell() + from IPython.frontend.terminal.embed import InteractiveShellEmbed + sh = InteractiveShellEmbed(banner1=banner) + except ImportError: + from IPython.Shell import IPShellEmbed + sh = IPShellEmbed(banner=banner) + + sh(global_ns={}, local_ns=namespace) except ImportError: import code try: # readline module is only available on unix systems @@ -25,6 +29,6 @@ def start_python_console(namespace=None, noipython=False): else: import rlcompleter readline.parse_and_bind("tab:complete") - code.interact(banner='', local=namespace) + code.interact(banner=banner, local=namespace) except SystemExit: # raised when using exit() in python code.interact pass