-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I know VS Code with Pylance supports loading environment variables from a .env (dotenv file), which is great. It allows me to, for example, easily run or debug tests right from the editor, using all the environment variables needed.
Here's the example from the docs:
# API endpoint
MYPROJECT_APIENDPOINT=https://my.domain.com/api/dev/
# Variables for the database
MYPROJECT_DBURL=https://my.domain.com/db/dev
MYPROJECT_DBUSER=devadmin
MYPROJECT_DBPASSWORD=!dfka**213=Feature Request
I would like VS Code / Pylance to also support defining the variables with export, as in:
# API endpoint
export MYPROJECT_APIENDPOINT=https://my.domain.com/api/dev/
# Variables for the database
export MYPROJECT_DBURL=https://my.domain.com/db/dev
export MYPROJECT_DBUSER=devadmin
export MYPROJECT_DBPASSWORD=!dfka**213=This would allow me to use the same set of environment variables from the command line by sourcing that file.
For example I could load the environment:
$ source .envAnd then run other commands that would use the same environment variables, for example, to run the tests usingcoverage:
$ coverage run --source ./app/ -m pytestCurrent behavior
As Currently VS Code / Pylance doesn't support having export in these .env files, I have to manually add the export before each variable before using it on the command line, and then I have to manually remove those exports manually to run again the tests from inside VS Code.
Apart from the double effort of adding and removing those exports, you can imagine that I often forget I had to do that, and I end up spending a long time debugging "why it's not working" in one place or the other, while it was just that I forgot to add or remove those exports. 😅