-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Terminal environment variables loaded by extension are corrupted #23604
Comments
Hi @aatle Thanks for filing this issue. Can you opt out from the new terminal environment variable experiment for now and see if the problem persist? |
As I have said in the original post, that setting is indeed a workaround and fixes the problem. Unfortunately, it is actually not a perfect solution because it also introduces a different problem. (Unrelated to the setting), the Python extension will sometimes still activate the poetry virtual environment but decide to only edit (and corrupt) the The Environment changes show the differences:Project 1: Only ## Extension: ms-python.python
Activated environment for `~\AppData\Local\pypoetry\Cache\virtualenvs\pyriak-WneeXSsL-py3.12\Scripts\python.exe`
- `PATH=c:\Users\abcde\.vscode\extensions\ms-python.python-2024.8.1\python_files\deactivate\bash;C:\Users\abcde\AppData\Local\pypoetry\Cache\virtualenvs\pyriak-WneeXSsL-py3.12\Scripts;${env:PATH}` Project 2: reproducible example, prompt changes to show virtual environment, more variables corrupted: ## Extension: ms-python.python
Activated environment for `~\AppData\Local\pypoetry\Cache\virtualenvs\project-3JzsXiol-py3.12\Scripts\python.exe`
- `EXEPATH=C:\Program Files\Git\bin`
- `HOME=C:\Users\abcde`
- `MSYS=disable_pcon`
- `MSYSTEM=MINGW64`
- `PATH=c:\Users\abcde\.vscode\extensions\ms-python.python-2024.8.1\python_files\deactivate\bash;C:\Users\abcde\AppData\Local\pypoetry\Cache\virtualenvs\project-3JzsXiol-py3.12\Scripts;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\abcde\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files\Git\cmd;C:\Users\abcde\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\abcde\AppData\Local\Programs\Python\Python312;C:\Users\abcde\AppData\Local\Microsoft\WindowsApps;C:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\bin;C:\users\abcde\.local\bin;${env:PATH}`
- `PLINK_PROTOCOL=ssh`
- `PS1=(project-py3.12) ${env:PS1}`
- `PWD=C:/Users/abcde/AppData/Local/Programs/Microsoft VS Code`
- `PYTHONIOENCODING=utf-8`
- `PYTHONUNBUFFERED=1`
- `TERM=xterm-256color`
- `VIRTUAL_ENV=C:/Users/abcde/AppData/Local/pypoetry/Cache/virtualenvs/project-3JzsXiol-py3.12`
- `VIRTUAL_ENV_PROMPT=project-py3.12` For the latter Project 2, the setting indeed fixes things, no environment variables are corrupted, and the extension does not contribute to terminal environment. Project 1 terminal environment changes, with setting enabled## Extension: ms-python.python
- `PATH=C:\Users\abcde\AppData\Local\pypoetry\Cache\virtualenvs\pyriak-WneeXSsL-py3.12\Scripts;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Git\cmd;C:\Users\abcde\AppData\Local\Programs\Python\Python312\Scripts\;C:\Users\abcde\AppData\Local\Programs\Python\Python312\;C:\Users\abcde\AppData\Local\Microsoft\WindowsApps;C:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\bin;c:\users\abcde\.local\bin` |
Hey @anthonykim1, this issue might need further attention. @aatle, you can help us out by closing this issue if the problem no longer exists, or adding more information. |
This issue still exists, and makes all |
I believe this is part of the Terminal Env Var experiment as we prepend PATH and calculate other environment variables from user. #22905 When you say "corrupted" PATH, are you looking the prepending pattern? |
Yes, in My original post isn't entirely clear, I'll clarify and summarize what I think is happening: I am using Windows, poetry virtual environment, and Git Bash terminal. From my understanding, the opt-out experimental feature edits and calculates certain environment variables. So, paths in the edited environment variables such as So, I think that there is a backslash issue somewhere in the process of parsing, editing, and exporting environment variable strings. If I opt out of this feature using the setting, then some of my other environments, which look slightly different for some reason, get even more corrupted such that basic commands like |
@aatle Apologies for late response and thanks for further explanation here.
This is interesting. Are you able to click on show environment contribution and see if WHO (for example Python extension specifically) is contributing to your corrupted environment? Also note that GitBash is currently not officially supported by Python extension at this moment: #23382
If this is the case, then the problem may reside outside of Python extension. Are you able to "correctly" activate your environment outside of VS Code environment? (External terminal for example) |
@anthonykim1 No worries, my workflow has not been inconvenienced by this. I am mostly certain that this bug is caused by the Microsoft Python extension, in certain conditions. Environment Changes# Terminal Environment Changes
## Extension: vscode.git
Enables the following features: git auth provider
- `GIT_ASKPASS=c:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass.sh`
- `VSCODE_GIT_ASKPASS_NODE=C:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\Code.exe`
- `VSCODE_GIT_ASKPASS_EXTRA_ARGS=`
- `VSCODE_GIT_ASKPASS_MAIN=c:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js`
- `VSCODE_GIT_IPC_HANDLE=\\.\pipe\vscode-git-b1ae1b85c2-sock`
## Extension: ms-python.python
Activated environment for `~\AppData\Local\pypoetry\Cache\virtualenvs\non-package-mode-7fHQA28B-py3.12\Scripts\python.exe`
- `EXEPATH=C:\Program Files\Git\bin`
- `HOME=C:\Users\abcde`
- `MSYS=disable_pcon`
- `MSYSTEM=MINGW64`
- `PATH=c:\Users\abcde\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\python_files\deactivate\bash;C:\Users\abcde\AppData\Local\pypoetry\Cache\virtualenvs\non-package-mode-7fHQA28B-py3.12\Scripts;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\abcde\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\abcde\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\abcde\AppData\Local\Programs\Python\Python312;C:\Users\abcde\AppData\Local\Microsoft\WindowsApps;C:\Users\abcde\AppData\Local\Programs\Microsoft VS Code\bin;C:\users\abcde\.local\bin;${env:PATH}`
- `PLINK_PROTOCOL=ssh`
- `PS1=(non-package-mode-py3.12) ${env:PS1}`
- `PWD=C:/Users/abcde/AppData/Local/Programs/Microsoft VS Code`
- `PYTHONIOENCODING=utf-8`
- `PYTHONUNBUFFERED=1`
- `TERM=xterm-256color`
- `VIRTUAL_ENV=C:/Users/abcde/AppData/Local/pypoetry/Cache/virtualenvs/non-package-mode-7fHQA28B-py3.12`
- `VIRTUAL_ENV_PROMPT=non-package-mode-py3.12` This information and more is also available in the original post (some of it might be slightly outdated). The invalid environment variables are: I realized from more testing, it is indeed fixable without more issues by opting out of the terminal var experiment with settings.json. Turning off the feature makes the Python extension not contribute to the environment using variables, and instead uses activation script as you said. "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"], Previously I said that this setting caused even worse errors on some projects, but it seems that this only applied to one specific older project I have, which I fixed. Conditions for bug, updated:
--> Causes certain Python extension environment variable contributions to be invalid because of backslashes in paths |
Hey @anthonykim1, this issue might need further attention. @aatle, you can help us out by closing this issue if the problem no longer exists, or adding more information. |
Type: Bug
Behaviour
In the terminal under specific circumstances, some environment variables are loaded with invalid values because of backslashes, causing certain commands to fail.
It is expected that the environment variable values would not have special escape sequences from backslashes in Windows paths.
Steps to reproduce:
VS Code Python extension loading poetry virtual environment on Git Bash on Windows
C:\Users
, should start with lowercasea
, e.g. "abcde". (Some other characters probably also work for this: b,e,f,n,r,t,v.)poetry
installed (1.8.3 used, but probably any version) usingpip
.pyproject.toml
file with the following contents:(project-py3.12)
, see above.git --help
fail. Possibly some other specific commands also fail. TheHOME
,PATH
, andEXEPATH
environment variables have invalid values.Diagnostic data
Output for
Python
in theOutput
panel(User account name replaced with
abcde
.)Terminal Environment Changes data (open terminal, hover over
bash - Microsoft VS Code
, clickShow environment contributions
)Note that the git extension was able to load its environment variables correctly.
Three corrupted environment variables
Bash
Python (shows escape sequences)
Notes
It would seem that the Python extension is attempting to load environment variables with values that include backslashes because of Windows paths.
But somewhere in the process, a few of the backslashes are being interpreted as escape sequences. For example
\v
becomes a vertical tab and\b
becomes a backspace.The interpretation aligns with how a
.env
file interprets backslashes. See C Escape Sequences.If the user does not have a user account name that starts with a valid escape sequence character, only PATH is corrupted, and not enough to be immediately noticeable.\
A workaround is adding
"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]
to settings.json.Extension version: 2024.8.0
VS Code version: Code 1.90.0 (89de5a8d4d6205e5b11647eb6a74844ca23d2573, 2024-06-04T19:33:54.889Z)
OS version: Windows_NT x64 10.0.22631
Modes:
python.languageServer
setting: DefaultUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
A/B Experiments
The text was updated successfully, but these errors were encountered: