Skip to content

Upgrade to prompt_toolkit 2.0 - #11177

Merged
minrk merged 6 commits into
ipython:masterfrom
takluyver:prompt-toolkit-2
Jun 13, 2018
Merged

minrk merged 6 commits into
ipython:masterfrom
takluyver:prompt-toolkit-2

Conversation

@takluyver

Copy link
Copy Markdown
Member

Continuation of #10964

@takluyver

Copy link
Copy Markdown
Member Author

The remaining failure is in generating the shortcuts list for the docs, if anyone wants to update that script:

https://github.com/ipython/ipython/blob/master/docs/autogen_shortcuts.py

@gpotter2

gpotter2 commented Jun 12, 2018 •

Copy link
Copy Markdown
Contributor

Hi,

here's a custom fix that works

diff --git a/docs/autogen_shortcuts.py b/docs/autogen_shortcuts.py
index 95c8d608b..8535f1c28 100755
--- a/docs/autogen_shortcuts.py
+++ b/docs/autogen_shortcuts.py
@@ -1,7 +1,6 @@
 from os.path import abspath, dirname, join
 
-from IPython.terminal.interactiveshell import KeyBindingManager
-
+from IPython.terminal.shortcuts import create_ipython_shortcuts
 
 def name(c):
     s = c.__class__.__name__
@@ -42,8 +41,14 @@ def multi_filter_str(flt):
 log_filters = {'_AndList': 'And', '_OrList': 'Or'}
 log_invert =  {'_Invert'}
 
-kbm = KeyBindingManager.for_prompt()
-ipy_bindings = kbm.registry.key_bindings
+class _DummyTerminal(object):
+    """Used as a buffer to get prompt_toolkit bindings
+    """
+    handle_return = None
+    input_splitter = None
+    display_completions = None
+
+ipy_bindings = create_ipython_shortcuts(_DummyTerminal()).bindings
 
 dummy_docs = []  # ignore bindings without proper documentation
 

(this patch was generated using git diff).

It would be really great to have a minor IPython release supporting prompt_toolkit 2.0 soon. This and #11185 are two blocking features for me.

Thanks !

@takluyver

Copy link
Copy Markdown
Member Author

Thanks, I applied that patch.

@minrk
minrk merged commit 4235328 into ipython:master Jun 13, 2018
@Carreau Carreau added this to the 7.0 milestone Jun 13, 2018
@gpotter2

Copy link
Copy Markdown
Contributor

@takluyver Also,

My normal inclination would be to do this for 7.0, but I know that people have had problems with tab completion running in a separate thread, and so we may end up doing it as a bugfix, possibly even back to 5.x. The remaining Python 2 users now can't go past 5.x, so there's some extra pressure to backport things.

Are you still willing to backport this ? I see it was only added to 7.0

@takluyver

Copy link
Copy Markdown
Member Author

I'm not sure 😕 . It's ended up being a fairly big change, which probably won't backport cleanly, and may cause other problems.

There's a larger shift in the Python world towards each application having its own dependencies installed in a separate environment. IPython doesn't entirely fit with that, because it's not just any application - you want it installed in the same environment as the modules you're working with. But then prompt_toolkit is a module that's largely useful only for applications.

So for now, I think I'm inclined to push forwards towards 7.0, and see how things go. IPython 5.7 correctly specifies the versions of prompt_toolkit it works with, so it's not a bug that it's incompatible with newer versions.

@gpotter2

Copy link
Copy Markdown
Contributor

Ok, this will be an additional point to make people switch to Python 3. Also it won’t break any app using both IPython and prompt_toolkit 1.0

Only problem we had with python 2.7 is that when we wanted to add prompt_toolkit 2.0 features to scapy, we were blocked by IPython.
We don’t have separate branches as IPython has, but that’s pretty easy to handle anyway

@stonebig

stonebig commented Jun 23, 2018 •

Copy link
Copy Markdown
Contributor

when will we have a chance to have an official Ipython compatible version ? Ipython-7.0 seems months away

@stonebig

Copy link
Copy Markdown
Contributor

any hope for today ?

@2sn

2sn commented Jul 26, 2018

Copy link
Copy Markdown

yes, it would be great to have IPython work with current versions of modules. As you note, prompt-tooolkit 2.x is incompatible with version 1,0.x, so if you have other applications that have been updated, you have to pick which module you prefer or need - IPython or the other ... ! Maybe you need a branch using the new version; users who need the old prompt-toolkit for other apps - and there may be some, can continue use the 6.x series of IPython ...

@ProbonoBonobo

ProbonoBonobo commented Jul 29, 2018 •

Copy link
Copy Markdown

For anyone needing a temporary workaround, I can confirm that reverting to prompt-toolkit v.1.x mostly resolves the errors that prevent ipython, ptpython, etc. from initializing:

$ git clone -b 1.0  --single-branch https://github.com/jonathanslenders/python-prompt-toolkit.git
$ cd python-prompt-toolkit 
$ python3 setup.py install 
$ cd ..
$ export python_prompt_toolkit_install_dir=$(pip3 show prompt_toolkit | echo $(grep -w "Location:")  | awk '{ print substr( $0, 11 ) }')/prompt-toolkit
$ pip3 uninstall prompt_toolkit
$ cp -Rf python-prompt-toolkit $python_prompt_toolkit_install_dir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants