Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with IPython 7 #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cc-a
Copy link

@cc-a cc-a commented Sep 8, 2019

Some minor revisions to accommodate changes made with Ipython7 swapping from IPython.core.inputsplitter to IPython.core.inputtransformer2.

I believe this closes #21

@cc-a
Copy link
Author

cc-a commented Sep 22, 2019

I appreciate rlipython is not a big priority in the IPython community so if you're interested in extra manpower I'd be happy to take it on as a maintainer.

@JeanMax
Copy link

JeanMax commented Nov 21, 2019

It works like a charm on my side! Thanks a lot for this :)

@baogorek
Copy link

Still having some problems with the new branch. Using within Powershell on Windows 10:
First I got:

AttributeError: 'TerminalInteractiveShell' object has no attribute 'has_readline'

so I pip installed pyreadline. Then I got an iPython prompt, but I tried to run an assignment statement and got

AttributeError: 'TransformerManager' object has no attribute 'push'

@cc-a
Copy link
Author

cc-a commented Nov 25, 2019

Thanks @baogorek, I'll take a look when I get the chance.

@baogorek
Copy link

Thanks @cc-a. I just cleaned up my environment and got a little further. With a Python3.6.8 virtual environment with iPython 7.9.0, pyreadline, and this branch installed (still Windows 10), the following command:

ipython --TerminalIPythonApp.interactive_shell_class=rlipython.TerminalInteractiveShell

produced a working console. But there are some pretty gnarly side effects:

In [1]: x = 4

In [2]: y = 5

In [3]: x + y
�[31mOut[�[31;1m3�[0;31m]: �[0m9

In [4]: print(x + y)
9

@cc-a
Copy link
Author

cc-a commented Nov 26, 2019

I was able to get to the same state. The mangled output looks like colour codes, for some reason not being understood correctly by powershell (despite input prompts being coloured correctly). Should be possible to disable colour output as a workaround, though obviously not ideal.

Could you also try multiline statements? I found these were severely broken.

Whats the use case for rlipython in powershell out of interest?

@baogorek
Copy link

Yeah, @cc-a, you're not kidding about multiline statements. I tried a for loop and iPython went into what appeared to be an infinite exception recursion. I'll paste some of that code at the bottom.

About the use case (and thanks for asking), there are times where developing on Windows Subsystem for Linux isn't convenient (e.g., plotting statistical charts), and I am desperately trying to mimic my Linux setup on Windows. That setup is based on tmux, vim, and a vim plugin called Slimux that allows me to send code from any pane to any other pane. It works perfectly. I had almost given up on Windows when 1) I realized I could run NeoVim in a Powershell console just like vim, 2) I discovered iron.nvim and nvimux which got me pretty close to my Linux setup on Windows. I'm able to press a key combo and send highlighted text to R, Powershell, and just about any other REPL...except iPython. Extra characters are a problem but the real headache is that iPython will not execute commands, no matter how many newlines you send.

I found a recently created iron.nvim issue about sending code to iPython and starting digging in. The problem seemed to be the same one from this Emacs Q&A where it was explained that IPython's new terminal interface was responsible for Emacs users not being able to send their code to the REPL. A workaround was suggested in the --simple-prompt flag, which also works for iron.nvim, but this removes so many of the good features of iPython that I'd rather just use the mouse and click on a real iPython console. The comments show that Emacs users aren't exactly thrilled about the workaround either.

Stumbling upon this repo was the first place that I learned about the prompt_toolkit, and it gave me hope that maybe I'd be able to send commands from vim to a functional iPython and have them execute. And if it worked there, it'd probably work on Emacs. And that would make a lot of people happy.

Portion of the error messages:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\devl\envs\test\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "c:\devl\envs\test\lib\site-packages\pyreadline\rlmain.py", line 569, in readline
    self.readline_setup(prompt)
  File "c:\devl\envs\test\lib\site-packages\pyreadline\rlmain.py", line 564, in readline_setup
    BaseReadline.readline_setup(self, prompt)
  File "c:\devl\envs\test\lib\site-packages\pyreadline\rlmain.py", line 253, in readline_setup
    return self.mode.readline_setup(prompt)
  File "c:\devl\envs\test\lib\site-packages\pyreadline\modes\basemode.py", line 127, in readline_setup
    traceback.print_exc()
NameError: name 'traceback' is not defined
pre_input_hook failed
Readline internal error
Traceback (most recent call last):
  File "c:\devl\envs\test\lib\site-packages\pyreadline\modes\basemode.py", line 124, in readline_setup
    self.pre_input_hook()
  File "c:\devl\envs\test\lib\site-packages\rlipython\shell.py", line 363, in pre_readline
    self.readline.insert_text(self._indent_current_str())
  File "c:\devl\envs\test\lib\site-packages\IPython\core\interactiveshell.py", line 2127, in _indent_current_str
    return self.input_splitter.get_indent_spaces() * ' '
AttributeError: 'TransformerManager' object has no attribute 'get_indent_spaces'

@cc-a
Copy link
Author

cc-a commented Nov 27, 2019

🤣 Oh the lengths we go to to avoid having to take our hands off of the keyboard. Not sure how I feel about helping vim users either 😉

I probably won't get a decent chance to look at this before the weekend. Frankly I'm quite unsure how to proceed with the colour code issue. The multiline issue should be resolvable anyway and can be worked around in the meantime with the --no-autoindent flag.

@cc-a
Copy link
Author

cc-a commented Nov 30, 2019

The issue with multiline commands are now resolved.

Regarding the colour codes in the output, I'm still not really sure where to start looking. This also seems to be an issue that was present in older versions and not related to the changes here so this PR isn't really the right place to fix it.

@baogorek
Copy link

baogorek commented Dec 2, 2019

@cc-a, 10-4. I also tried your branch and things were working fine, with the exception of the color codes.

@cc-a
Copy link
Author

cc-a commented Dec 2, 2019

Alright, figured out the colour codes thing and created #24 for the change. I've merged the changes for both this PR and #24 into master on my fork for easy combination. So you should be able to get a fully functioning ipython shell from scratch with:
pip install git+https://github.com/cc-a/rlipython pyreadline

@antoine-gallix
Copy link

Gentle ping. Any chance this get merged soon?

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.

Oops - crash on IPython 7
4 participants