microsoft / vscode-python

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

Better documentation about .env file #24034

Open anthonykim1 opened 2 months ago

anthonykim1 commented 2 months ago

https://github.com/microsoft/vscode-python/issues/23280#issuecomment-2083078678 and https://github.com/microsoft/vscode-python/issues/23856

We should have better documentation regarding .env file.

benglewis commented 2 months ago

Honestly, I hate to be a hater and complain, but the Python: Env File option should be off-by-default, at the very least until it is "fixed". What do I mean?

  1. The implementation appeared out of nowhere one day (both myself and another developer on my team had our setup broken one day because of it, and it took me getting mad and searching all of my system packages, shell plugins and configuration and then VSCode extensions one-by-one until I realized that it was vscode-python)
  2. The implementation is not consistent with the python-dotenv package that users are used to using out there in multiple ways:
  3. When the implementation is inconsistent, it can break developers' workflows since it sets a value on the environment variable which will then not be overridden.
  4. Users that use .env files have enough other alternative options that they do not need this from this extension.
anthonykim1 commented 1 month ago

Thanks for the feedback there @benglewis Would you find https://code.visualstudio.com/docs/python/environments#_environment-variables to be helpful at all? Curious to hear what you think. -Thanks

benglewis commented 1 month ago

Maybe, for situations where it is not viable to change/edit code to introduce python-dotenv

shughes-uk commented 1 month ago

This feature cost me hours. We have an app that uses python-dotenv to load settings from a .env file. I wanted to change a setting, so just updated my env file. Normally executing the app should immediately reflect these changes, but now it was using the old value as python-dotenv gives priority to environment variables over the file.

So spend forever trying to track down where the hell the old value was coming from. Eventually https://github.com/fastapi/fastapi/issues/4251 led me to https://github.com/microsoft/vscode-python/issues/23280#issuecomment-2083078678 .

Especially annoying as when I tried to use the vscode debugger to figure it out, of course the issue did not exist (as it was reloading the .env file each launch).

The other issues are closed, but I would beg you to reconsider having this on by default without any indication it happens unless you read the entire extension documentation. At least add a little "loaded .env variables" or something at the start of a terminal boot as a hint!

benglewis commented 1 month ago

Just to clarify @anthonykim1 , my feedback suggesting that it might be useful was regarding allowing a user to actively choose to turn it on and "opt-in". It should 100% definitely not be the default. Additionally, a notification when opening a shell that the .env was loaded into environment variables with a link to the setting, would probably help people that are stuck after having enabled it by mistake

legau commented 3 weeks ago

To add to this, in non-Python projects, activating one time a Python interpreter causes all subsequent terminal sessions to load these old state values with no way (to my knowledge) to remove them except uninstalling the extension. In a non-python project the interpreter will almost never come up automatically to refresh the values except by hand. This is absolutely unexpected behavior even with comprehensive documentation available. There are a lot of issues about this and everyone states the long time it has taken them to debug such weird behavior.