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

Improve compatibility and consistency between Python REPL and terminal commands in the Command Palette #22970

Closed
raphaelchinchilla opened this issue Feb 26, 2024 · 4 comments
Assignees
Labels
feature-request Request for new features or functionality info-needed Issue requires more information from poster

Comments

@raphaelchinchilla
Copy link

TLDR: Streamline the Python REPL experience by unifying REPL and terminal commands, and adding customization options for IPython integration.

(This is a mix of feature request and bug report)

Suppose one has a python script open.

There are (at least) three methods to use a "vanilla python interface" (not using the Interactive Mode or the Debugger) using the Command Palette:

  • Run the whole file in a terminal using Python: Run File in Terminal.
  • Select part of the file (or all of it), and run the command Python: Run Selection/Line in Terminal (which has the default shortcut command Shift+Enter).
  • Use the command Python: Start REPL and then copy and paste the code.

Unfortunately, none of these commands seems to be compatible with each other in several ways:

  1. If one does Python: Start REPL and then selects part of the script and runs Python: Run Selection/Line in Terminal (or use the keyboard shortcut), it creates a new terminal instead of opening in the current REPL.
  2. Same behavior as above if one runs Python: Run File in Terminal
  3. If one has run some code using Python: Run Selection/Line in Terminal and then selects Python: Run File in Terminal, one gets an error as the IDE tries to run /path/to/python/bin "/path/to/file" inside the Python terminal, which obviously does not work.
  4. There is no way to start the REPL associated to Python: Run Selection/Line in Terminal without actually selecting a code and running it.

My suggestion is to clean up all of these commands: The command Python: Start REPL should start the same REPL as the one started with Python: Run Selection/Line in Terminal. The command Python: Run File in Terminal should run the code in the REPL if it is open, and to run in a new REPL, the command should be the Python: Run File in Dedicated Terminal. Running the command Python: Start REPL several times should create new REPLs, so the code can be run in different ones.

A bonus would be that the REPL is chosen to be IPython if the user wants. This is already possible by modifying the settings.json and including the entry

    "python.terminal.launchArgs": [
        "-m",
        "IPython",
        "--no-autoindent",
        "--matplotlib",        
        "-i",
    ],

but it would be better if this has some more support, including have custom launch arguments to be able to include %load_ext autoreload \n %autoreload 2

The issue #22674 is already acknowledging that there are a lot of people in the community (like me) asking for a better REPL experience, with a variable explorer and a plots plane, like the Julia extension or Spyder (and that is not based on the Interactive Mode, which has several issues). While I agree that it would be great if these features were made available, I think that what I report above would be an easier fix and also a first step in the right direction.

Finally, I know that there are some extensions that are supposed to provide IPython integration. However, these are small projects, several of them seem to be effectively abandoned. At least one is in current development, but seems to be a one person effort. Moreover, any extension does not fix the issues above and only creates yet another method to run python files.

@raphaelchinchilla raphaelchinchilla added the feature-request Request for new features or functionality label Feb 26, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 26, 2024
@anthonykim1
Copy link

anthonykim1 commented Mar 1, 2024

Hi @raphaelchinchilla Thank you much for the bug report and suggestion on better integration across different ways of triggering REPL.

I agree that there should be more unified experience in regards to Python: Start REPL and the shift+enter inside a Python file that triggers command being sent to the REPL.

In terms of native IPython support, we do not have plan to ship IPython in box for multiple reason including the size of it and existence of interactive window. See related here: #17172 and #19955

Good news is there is investigation for VS Code Native REPL that will provide some of the main features that people have been desiring such as autocomplete, syntax highlighting, command history. This native REPL will potentially be able to leverage Jupyter's variable viewer feature that is behind notebook at the current moment.

In terms of variable explorer, Jupyter extension just launched a variable viewer that nicely goes on the side var that you can check it out if you wish.

Is there any specific reason for your preference towards IPython? I would love to take some of the nice things that attracted you with IPython and Spyder's interactive mode.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Mar 1, 2024
@anthonykim1 anthonykim1 removed the triage-needed Needs assignment to the proper sub-team label Mar 1, 2024
@raphaelchinchilla
Copy link
Author

Thank you @anthonykim1 for taking the time to look at this.

In terms of native IPython support, we do not have plan to ship IPython in box for multiple reason including the size of it and existence of interactive window. See related here: #17172 and #19955

It is a shame to hear that. I will go on later in why I don't like the interactive window.

Good news is there is investigation for VS Code Native REPL that will provide some of the main features that people have been desiring such as autocomplete, syntax highlighting, command history. This native REPL will potentially be able to leverage Jupyter's variable viewer feature that is behind notebook at the current moment.

This sounds promising, interested to see what it happens out of it.

In terms of variable explorer, Jupyter extension just launched a variable viewer that nicely goes on the side var that you can check it out if you wish.

Is there any specific reason for your preference towards IPython? I would love to take some of the nice things that attracted you with IPython and Spyder's interactive mode.

For me, IPython is better than the regular Python REPL as it supports all of the magic commands. But a particular application that I really like about IPython is that I can just go to my code and set a breakpoint by writing breakpoint() without having to go to a have heavy debugger that slows my code. IPython also supports post mortem execution with the command %pdb on which is very useful for me.

VS Code's Interactive Mode is similar enough to Spyder that I use it when I need to use Python on VS Code. However, it has the fundamental flaw that one cannot use it for debugging microsoft/vscode-jupyter#1278. This might be solved one day but as it has been almost 5 years and there is no solution yet, I figured I might just use IPython.

I believe that the fundamental flaw is that ipykernels do not seem to work very well with debugging pipelines. Writing breakpoint() never sets a breakpoint, and post mortem execution is not great either.

Anyway, if these would be fixed by VS Code's REPL (which if I understand well, will be different than the Interactive Mode), then great. Otherwise, I would rather just continue to use IPython and have a nice way to start a kernel...

Copy link

github-actions bot commented Jun 7, 2024

Hey @anthonykim1, this issue might need further attention.

@raphaelchinchilla, 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 Jul 8, 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 Jul 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants