microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.32k stars 1.18k forks source link

Properly differentiate Windows, Linux, and WSL in pythonrc.py script #23829

Open vladjohnson opened 3 months ago

vladjohnson commented 3 months ago

Does this issue occur when all extensions are disabled?: Yes

Hi there, I am having issues with VS Code custom sequences making their way into the Python shell. For instance: ]633;E;quit()]633;D;0]633;A>>> ]633;B]633;C. I've tried disabling the shell integration, but it does not work. Please help! Screenshot 2024-07-16 171128

Steps to Reproduce:

  1. Open a .py file and run python file using the "Run Python File" button on the right upper corner.
  2. In the opened terminal, type python or python3.
vscodenpa commented 3 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.91.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

vladjohnson commented 3 months ago

Problem still exists. Thank you!

Tyriar commented 3 months ago

@anthonykim1 is this stuff not behind an opt-in setting atm?

vladjohnson commented 3 months ago

@anthonykim1 @Tyriar thank you so much for helping out!

anthonykim1 commented 2 months ago

Thanks for filing the issue @vladjohnson

@Tyriar Yeap, this is not behind a setting atm.

I'm bit surprised about this because we don't enable this for windows folks at all. We use

if sys.platform != "win32":
    sys.ps1 = PS1()

to filter out windows folks and only attach such sequence for non-windows users who use Terminal Python REPL.

Now I am wondering if "win32" is not sufficient.

Can you please

import sys

and print

sys.platform

and let me know of the value?

I'm guessing we may have to handle it better for WSL.

vladjohnson commented 2 months ago

@anthonykim1 sure thing! The platform value is 'linux'. I am running Ubuntu 20.04 LTS in WSL 2. Thanks!

anthonykim1 commented 2 months ago

@vladjohnson Thanks for this!

So I basically need to be more through than sys.platform != "window32" and sort out that user can be in 'linux' environment via Windows.

I'll mark this as bug, and let you know once I have the fix. Thank you

vladjohnson commented 2 months ago

Thank you! Appreciate it, @anthonykim1

anthonykim1 commented 4 weeks ago

Hi @vladjohnson I haven't got a chance to solve the problem itself, we now have a setting to toggle on/off which is related to what you are seeing on the screen.

Its called

python.terminal.shellIntegration.enabled

and you can toggle this off on your settings UI or modify your settings.json starting TOMORROW's pre-release version of the Python extension.

Still planning to fix the root cause like I've mentioned in

So I basically need to be more through than sys.platform != "window32" and sort out that user can be in 'linux' environment via Windows.

But perhaps you could utilize the setting beforehand :) - Thanks again for your patience

vladjohnson commented 4 weeks ago

Thanks :) Appreciate it, @anthonykim1