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

Switching Kernel/Interpreter in Python Native REPL dropdown forces use of IPyKernel. #23971

Open
szymonhennel opened this issue Aug 19, 2024 · 9 comments
Assignees
Labels
area-repl needs spike Label for issues that need investigation before they can be worked on.

Comments

@szymonhennel
Copy link

Type: Bug

Behavior

Context

Upon starting a native python REPL, the default kernel "Python REPL" is active. With the setting "python.REPL.sendToNativeREPL": true, Shift+Enter sends code from the editor to the REPL. If the user is happy working with the default kernel, everything is fine an no issues occur. If the user wants to use a different kernel, this can be achieved by clicking on the kernel button in the top right corner of the native REPL pane. The kernel selection works as expected, and the selected kernel remains active without issues as long as code is entered and executed manually.

Where the bug manifests

The bug is that when a non-default kernel is selected and code is sent to the REPL from the editor pane by Shift+Enter, this action triggers a change of the kernel back to "Python REPL", and the code sent is interpreted by this default kernel. This makes the setting "Send to active REPL" unusable if the user works with a virtual environment.

Expected behavior

The kernel selection should not be affected by sending code to the REPL.

Environment

Python 3.12.5 on Windows 11 Pro 23H2, virtual environment managed by poetry, python extension v2024.12.3.

User settings

I have checked that any combination of the settings "interactiveWindow.executeWithShiftEnter", "python.terminal.activateEnvInCurrentTerminal" and "python.terminal.activateEnvironment" do not affect the behavior described above.

How to reproduce:

  • Set "python.REPL.sendToNativeREPL": true.
  • Open the native REPL by sending code from the editor with Shift+Enter.
  • Change the kernel of the native REPL to something else than "Python REPL".
  • Send some code from the editor to the native REPL again (Shift+Enter).
  • The kernel of the REPL has been unexpectedly changed back to default.

And since this is my first time interacting with this community I take this opportunity to thank you all for providing this awesome extension.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Aug 19, 2024
@anthonykim1
Copy link

anthonykim1 commented Aug 26, 2024

Hello @szymonhennel Thank you for filing the issue and I truly appreciate your kind words and appreciation here.
You made great points here and I appreciate the detailed info here.

Couple things here, but let's try to unwrap and discuss this step by step:

  1. I will bring this up to the Python team and folks in Jupyter.
  2. The big intention and motivation behind Native REPL feature was to provide Python user to access an enhanced REPL (with features such as intellisense and autocomplete) that the Terminal REPL did not have. All of this without having to install Jupyter extension nor iPyKernel that you need in order to launch and experience the Jupyter notebook or Interactive Window Option to run your Python code. This way, users just need their "basic" Python interpreter to test out their code quickly without having to sit and wait for iPykernel to be installed which is coming from Jupyter side of things.
  3. That being said, the very moment you decide to pick a "kernel" yourself instead of Python REPL, it seems that Jupyter extension switches your mode from Native REPL(Provided by Python extension) to Interactive Window(one provided by Jupyter). The way you know this is the output: Basically if you are in the lightweight native REPL mode, you will not see colorized output but rather output generated by Python extension's REPL server.
Screenshot 2024-08-26 at 4 02 41 PM

If you are in the interactive window mode, you will see colorized output from the iPyKernel itself coming from Jupyter:
Screenshot 2024-08-26 at 3 59 59 PM

  1. It looks like you are satisfied enough with the output that native REPL generates and do not necessary need the one from Jupyter. If that is the case, this can be a great feature request idea that you can post with the 'feature request' tag. I can see this being totally valid request.

  2. I am also wondering if you can change interpreter via command palette (ctrl/cmd + shift + p) 'Select Interpreter' and try opening the Native REPL again and see your desired effect? Instead of changing the kernel via clicking on 'Python REPL'

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Aug 26, 2024
@anthonykim1 anthonykim1 changed the title Native Python REPL: kernel selection is reset every time code is sent to the native REPL (Shift+Enter with sendToNativeREPL set to true) Switching Kernel/Interpreter in Python Native REPL dropdown forces use of IPyKernel. Aug 26, 2024
@szymonhennel
Copy link
Author

Hi @anthonykim1 thank you for answering and sorry for taking a long time to come back to you, I will answer by tomorrow.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Aug 30, 2024
@kirill-dobryakovv
Copy link

Hey @anthonykim1, thank you for the context! Came across the same issue, happy it was brought up!
To answer your question, changing the interpreter via the command palette (ctrl/cmd + shift + p) has zero effect on the issue, it is still reproducible.

It seems like what needs to be fixed here is the command that sends the code over to the interactive window, everything else works fine.

I personally think that using a Jupyter-provided Interactive Window has a nicer workflow than the ipynb.

Tagging @IanMatthewHuff as an engineer involved in making this feature.

@amunger
Copy link

amunger commented Oct 4, 2024

the very moment you decide to pick a "kernel" yourself instead of Python REPL, it seems that Jupyter extension switches your mode from Native REPL to Interactive Window

IIUC, this is what the user is asking for, but doesn't quite work - you can change the kernel, but using sendToNativeRepl will switch the kernel back to python's.

The user should be able to select a different kernel to use here, and would actually provide a workaround for microsoft/vscode-jupyter#15988

Recording 2024-10-04 at 14 03 59

@anthonykim1
Copy link

anthonykim1 commented Oct 6, 2024

I see, with the explanation + video made it super clear. Thanks!

The smoothest transition I can think of would be: Perhaps we need to detect when user has switched their kernel from (native REPL to IW) and automatically change the keybinding (of shift+enter) to send to IW instead of Python Native REPL?

If we detect user change their kernel back to native REPL (Im not sure if this is possible), we would again change/revert the shift+enter keybinding to send command to native REPL instead of IW.

Does this sound reasonable?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Oct 6, 2024
@amunger
Copy link

amunger commented Oct 6, 2024

I think a much simpler solution would just be to not run the selectKernel command if the editor was already opened - allow the user to use a different kernel in the python REPL editor.

@HansAtonenGS
Copy link

I was facing a similar issue, but I managed to change it so it doesn't use the Python REPL editor every time I press Shift+Enter by doing the following:

TL;DR: Change jupyter.interactiveWindow.textEditor.executeSelection to true using the Visual Studio Code Settings UI. This made it start using my kernel as the default option.

Steps:
Open Settings UI:

  • Press Ctrl+Shift+P, search for Settings UI.

Search for the Setting:

  • In the search bar at the top, type jupyter interactive window text editor execute selection.

Enable the Setting:

  • Find the setting named Jupyter: Interactive Window Text Editor Execute Selection.
  • Check the box to enable it.

Copy link

github-actions bot commented Nov 9, 2024

Hey @anthonykim1, this issue might need further attention.

@szymonhennel, you can help us out by closing this issue if the problem no longer exists, or adding more information.

Copy link

github-actions bot commented Dec 9, 2024

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
@anthonykim1 anthonykim1 reopened this Feb 4, 2025
@anthonykim1 anthonykim1 added needs spike Label for issues that need investigation before they can be worked on. area-repl and removed info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-repl needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
Development

No branches or pull requests

5 participants