From 7ba4b0a21b0bb2efe0523bec0c1db07771816347 Mon Sep 17 00:00:00 2001 From: Bernardas Date: Wed, 15 Mar 2017 07:50:31 +0000 Subject: [PATCH 1/2] add support for embeded ptpython shell --- scrapy/utils/console.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py index 1888d9599..a9d73aada 100644 --- a/scrapy/utils/console.py +++ b/scrapy/utils/console.py @@ -31,6 +31,15 @@ def _embed_bpython_shell(namespace={}, banner=''): bpython.embed(locals_=namespace, banner=banner) return wrapper +def _embed_ptpython_shell(namespace={}, banner=''): + """Start a ptpython shell""" + import ptpython.repl + @wraps(_embed_ptpython_shell) + def wrapper(namespace=namespace, banner=''): + print(banner) + ptpython.repl.embed(locals=namespace) + return wrapper + def _embed_standard_shell(namespace={}, banner=''): """Start a standard python shell""" import code @@ -49,7 +58,8 @@ def _embed_standard_shell(namespace={}, banner=''): DEFAULT_PYTHON_SHELLS = OrderedDict([ ('ipython', _embed_ipython_shell), ('bpython', _embed_bpython_shell), - ( 'python', _embed_standard_shell), + ('ptpython', _embed_ptpython_shell), + ('python', _embed_standard_shell), ]) def get_shell_embed_func(shells=None, known_shells=None): From 1a452c038cc0547924051a7cd0786215ec7c2104 Mon Sep 17 00:00:00 2001 From: Bernardas Date: Thu, 18 May 2017 16:57:13 +0000 Subject: [PATCH 2/2] increase ptpython priority since it can use other shells as backend --- scrapy/utils/console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrapy/utils/console.py b/scrapy/utils/console.py index a9d73aada..2e9981556 100644 --- a/scrapy/utils/console.py +++ b/scrapy/utils/console.py @@ -56,9 +56,9 @@ def _embed_standard_shell(namespace={}, banner=''): return wrapper DEFAULT_PYTHON_SHELLS = OrderedDict([ + ('ptpython', _embed_ptpython_shell), ('ipython', _embed_ipython_shell), ('bpython', _embed_bpython_shell), - ('ptpython', _embed_ptpython_shell), ('python', _embed_standard_shell), ])