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

Explain how to disable autoloading of .env file in Python environment docs #6967

Closed
gmeligio opened this issue Jan 19, 2024 · 5 comments
Closed
Labels
doc-enhancement suggested addition or improvement python

Comments

@gmeligio
Copy link

gmeligio commented Jan 19, 2024

The Python environments in VS Code docs say

By default, the Python extension looks for and loads a file named .env in the current workspace folder, then applies those definitions. The file is identified by the default entry "python.envFile": "${workspaceFolder}/.env" in your user settings (see General Python settings). You can change the python.envFile setting at any time to use a different definitions file.

This explains how to change the file path to load but doesn't explain how to disable it. The use case is that sometimes is undesired to load the .env file.

There is a possible solution already that could be documented to guide users on how to disable it if they want. It's to change the default path "${workspaceFolder}/.env" to an unexistent path. This is how I disable it in my case:

// settings.json
"python.envFile": ".disable-loading-env-because-pollutes-shell-session",

An snippet like this could be shown in the relevant webpages and it would be really helpful.

Another small related issue is that there is no link in "Show environment contributions" to Environment variable definitions file . Then, it's hard to connect the "terminal environment contributions" feature with the settings influencing it. This will be solved with #6590.

Affected Webpages

@ntrogh ntrogh added python doc-enhancement suggested addition or improvement labels Jan 19, 2024
@ntrogh
Copy link
Contributor

ntrogh commented Jan 19, 2024

@gmeligio Thanks! Checking with the Python extension team about this.

@ntrogh
Copy link
Contributor

ntrogh commented Jan 19, 2024

@gmeligio Update from the team: if you want to disable the behavior of automatically using .env file definitions to automatically load the environment, you can set the python.envFile setting to an empty string. Make sure to save the settings file and reload your window afterwards. We'll update the docs accordingly to include this information.

In settings.json:

"python.envFile": ""

As for the other item, the team will update the wiki.

@gmeligio
Copy link
Author

Thank you so much, @ntrogh, for looking into this. It looks neat to leave it empty to disable it.

@ntrogh ntrogh closed this as completed Jan 20, 2024
@madfcat
Copy link

madfcat commented Nov 2, 2024

@gmeligio Update from the team: if you want to disable the behavior of automatically using .env file definitions to automatically load the environment, you can set the python.envFile setting to an empty string. Make sure to save the settings file and reload your window afterwards. We'll update the docs accordingly to include this information.

In settings.json:

"python.envFile": ""
As for the other item, the team will update the wiki.

This gave me a lot of issues with my env vars in Docker compose setup running it from VSCode shell 🤦‍♀️
Thanks for the tip!

@gmeligio
Copy link
Author

gmeligio commented Nov 2, 2024

Affected Webpages

Hi @ntrogh . Is it possible to update the Affected Webpages with the suggested solution and examples? I think this issue is less accessible to users needing that documentation.

In settings.json:

"python.envFile": ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement suggested addition or improvement python
Projects
None yet
Development

No branches or pull requests

3 participants