mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.
https://vizro.readthedocs.io/en/stable/
Apache License 2.0
2.61k stars 116 forks source link

Feature: load env automatically #270

Closed Anna-Xiong closed 7 months ago

Anna-Xiong commented 7 months ago

Description

Fearure: when vizro-ai is imported, we load .env in the same directory where the program is run.

limitation:

Screenshot

Notice

antonymilne commented 7 months ago

FYI I just checked and it looks like load_env will by default search upwards through the directory hierarchy for files named .env: https://saurabh-kumar.com/python-dotenv/reference/. So the restriction "it has to be in the same directory" isn't actually true, even though it's likely the most common way people will run this.

Just leaving this with the default load_env behaviour looks good to me πŸ‘ And anyone who wants to change that can do the load_env manually.

Anna-Xiong commented 7 months ago

FYI I just checked and it looks like load_env will by default search upwards through the directory hierarchy for files named .env: https://saurabh-kumar.com/python-dotenv/reference/. So the restriction "it has to be in the same directory" isn't actually true, even though it's likely the most common way people will run this.

Just leaving this with the default load_env behaviour looks good to me πŸ‘ And anyone who wants to change that can do the load_env manually.

Hi Antony, thank you for pointing this out! yes, i just tested, looks like find_dotenv is automatically used. Then we will just add some documentations!

TL;DR if we ever want to enable more default file names in future, we can consider similar approach like this one:

starting from L656 that ths cli.load_dotenv is the function flask uses when app.run() is called inside of run call.

antonymilne commented 7 months ago

Agreed πŸ‘ Though note that .env is the one that flask recommends be used for private variables and hence probably always makes most sense for API tokens.

Variables set on the command line are used over those set in .env, which are used over those set in .flaskenv. .flaskenv should be used for public variables, such as FLASK_APP, while .env should not be committed to your repository so that it can set private variables.