microsoft / vscode-python

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

Don't export .env values into the global environment #24209

Open pamelafox opened 1 month ago

pamelafox commented 1 month ago

Currently the Python extension exports the .env values into the global environment. That feature caused my days of debugging this year, due to its interaction with the azd CLI (https://github.com/Azure/azure-dev/issues/4384), and I had absolutely no expectation that such a feature would exist. I know that there is a way in settings to turn it off, but I think that it should be an opt-in feature since it can have such a confusing effect on the local environment.

I have not heard of any other language extensions having the same feature, either.

karthiknadig commented 1 month ago

An activated terminal environment is somewhat strange rom general languages perspective. May be we can make the setting more explicit with not defaults, something like: python.terminal.envFile. this way it only works i you set it a .env.

I will need to investigate this further to see i this breaks any expectations of existing users. Surface it better, in cases where it might get missed. Define a clearer overriding order between the various ways you can set environment variables.

anthonykim1 commented 1 month ago

Also would be beneficial to explain/define behavior for when changes are made to existing env file (and user has not restarted), when env file suddenly does not exist (file deletion from user), what happens when extension is deactivated (do we store cached env somewhere). Related: https://github.com/microsoft/vscode-python/issues/23856