Skip to content

[WIP] Upgrade to prompt_toolkit 2.0 - #10964

Closed
jonathanslenders wants to merge 1 commit into
ipython:masterfrom
jonathanslenders:prompt_toolkit-2.0
Closed

jonathanslenders wants to merge 1 commit into
ipython:masterfrom
jonathanslenders:prompt_toolkit-2.0

Conversation

@jonathanslenders

Copy link
Copy Markdown
Contributor

There are still some bugs and a couple of things to fix.

  • async autocompletion.
  • result always appears below output prompt
  • debugger has not yet been tested.

@jonathanslenders

Copy link
Copy Markdown
Contributor Author

Comment thread IPython/terminal/interactiveshell.py Outdated
if hasattr(self.pt_cli, 'pre_run_callables'):
self.pt_cli.pre_run_callables.append(set_doc)
self.pt_app.application.buffer.document = Document(s)
if hasattr(self.pt_app.application, 'pre_run_callables'):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this hasattr() check was for compatibility with older prompt_toolkit versions. As this will require 2.x anyway, we can probably remove it and only use pre_run_callables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Fixed now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is actually the use for this pre_prompt function? What is rl_next_input?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Various functions can set some text to appear at the next prompt, e.g. I can run %load foo.py to get the contents of foo.py at the next prompt. There's also %recall which can retrieve entries from history. That gets stored in rl_next_input and then inserted when the next prompt is being prepared.

Comment thread IPython/terminal/interactiveshell.py Outdated
# some configuration options have changed.
# """
# if self.pt_app:
# self.pt_app.layout = create_prompt_layout(**self._extra_prompt_options())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this no longer necessary, or do we need a different way of doing it? There are some settings we can change at runtime, and we needed to do this for them to take effect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed no longer necessary, unless I miss something. All the extra_prompt_options are passed to each prompt() call. This should update them every time.

@takluyver

Copy link
Copy Markdown
Member

Thanks for making a start on this!

I remember you said that PT 2 would add a way to do tab completions on the main thread. I'm looking forward to this, because we've had a number of reports of completion problems resulting from it using a separate thread. Is that API in place? Will it be easy to integrate?

@jonathanslenders

Copy link
Copy Markdown
Contributor Author

prompt_toolkit 2.0 does indeed support synchronous completion. This is even the default, because apparently, that's what most people want, and is the easiest. Asynchronous completion is possible by passing complete_in_thread=True to the prompt() function.

@takluyver

Copy link
Copy Markdown
Member

Great, so we should get synchronous completion without doing anything else.

@takluyver

Copy link
Copy Markdown
Member

Hi @jonathanslenders ! How's v2 coming along? :-)

@jonathanslenders

Copy link
Copy Markdown
Contributor Author

Hi @takluyver,
Thanks for asking. It's going well actually, I still have to do a bit of testing, but it's pretty solid already.
It should be possible to release very soon. Would you merge this for IPython 7, or simply the next 6.x release?
Are you coming to PyCon?

@takluyver

Copy link
Copy Markdown
Member

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.

@takluyver

Copy link
Copy Markdown
Member

I'm not coming to Pycon (I'm avoiding travelling to the US as a kind of personal protest), but I'm hoping to be at EuroPython later this year.

@gpotter2

Copy link
Copy Markdown
Contributor

Hello,

Is there any release date of prompt_toolkit>=2.0.0 and its IPython integration? Yet we can't have both IPython and new prompt_toolkit features running at the same time.

Thanks a lot for both your projects, there are just amazing and really useful!

@Carreau

Carreau commented May 16, 2018

Copy link
Copy Markdown
Member

If we want to make a smallish-7.x release that simply update to prompt_toolkit>=2.0.0 I would be ok with that.

@jonathanslenders
jonathanslenders force-pushed the prompt_toolkit-2.0 branch 3 times, most recently from 0eb9b78 to e04a799 Compare May 20, 2018 22:17
@gpotter2

gpotter2 commented Jun 2, 2018

Copy link
Copy Markdown
Contributor

Seems like prompt_toolkit 2.0.1 has just been released ! (btw great job !)

Hope to see an IPython integration soon :)

@takluyver

Copy link
Copy Markdown
Member

Nice one @jonathanslenders :-) Are you going to get back to this PR, or would you rather someone else picked it up?

And well spotted @gpotter2 - it hasn't even been out one hour yet!

screenshot from 2018-06-02 19-28-05

@jonathanslenders

Copy link
Copy Markdown
Contributor Author

@takluyver: I'm not sure I have the time for all the required testing. I think all the relevant changes are done, so maybe somebody can take it from here.

A couple of things:

if self.pt_cli:
self.pt_cli.print_tokens(tokens)
if self.pt_app:
self.pt_app.print_tokens(tokens) # XXX

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any replacement for the print_tokens() method?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, found it from the file below :-)

@takluyver

Copy link
Copy Markdown
Member

I've rebased and fixed up a few problems in #11177.

@gpotter2

gpotter2 commented Jun 7, 2018

Copy link
Copy Markdown
Contributor

@takluyver Thanks a lot for your work !

@gpotter2

Copy link
Copy Markdown
Contributor

Any reason to keep this PR open ?

@takluyver

Copy link
Copy Markdown
Member

Nope, it was superseded by #11177.

@takluyver takluyver closed this Jun 17, 2018
@Carreau Carreau added this to the no action milestone Sep 7, 2018
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.

4 participants