add ability to load from .env files before invoking the command
Summary
Pipenv and other equivalent tools have the ability to load an .env file during execution of a script etc
https://pipenv.pypa.io/en/stable/shell.html#automatic-loading-of-env
The PR adds a new flag --load-dotenv and a new ENV UV_RUN_LOAD_DOTENV that enables this feature for uv run
resolves #1384
Test Plan
Have tested it locally by successfully invoking scripts that require ENV's to be set.
dotenv is implicitly unmaintained.
Ref: https://github.com/rustsec/advisory-db/issues/1254
@eth3lbert I will switch it to dotenvy if you are happy with the idea of the PR :)
Can't wait for this to land, we're excited to switch to uv, but are currently blocked by this.
@charliermarsh This PR is currently configured to be opt in, but in light of the discussion in the issue thread, should we instead make it opt out?
i.e.
--no-load-dotenv
UV_RUN_NO_LOAD_DOTENV
And also the naming can be discussed, I kept it scoped to UV_RUN_ as this is a run specific variable, but perhaps if there is a need for full uv configuration with a .env, we just call it UV_NO_LOAD_DOTENV and then just expand its use within uv later.
Could this be used to set UV_PROJECT_ENVIRONMENT in the .env file, offering a slightly better workaround to the issues discussed in #7642 and #1495 ?
@PhilipVinc currently it only affects the run command, it would have to be further expanded to support uv global config.
Yeah I think my preference would be:
- Read
.envby default (only inuv runfor now; we may expand it later). - Allow users to pass
--env-file(orUV_ENV_FILE) to override the file. - Add
--no-env-fileandUV_NO_ENV_FILEto disable it.
I think we can omit the UV_RUN_ prefixes.
closing this as it seems to be implemented already
Yeah I think my preference would be:
- Read
.envby default (only inuv runfor now; we may expand it later).- Allow users to pass
--env-file(orUV_ENV_FILE) to override the file.- Add
--no-env-fileandUV_NO_ENV_FILEto disable it.I think we can omit the
UV_RUN_prefixes.
@haydn-j-evans @charliermarsh
Thanks for the summary of features regarding .env setup.
Before I raise a bug, I wanted to check if the first option in the above list ever implemented?
In the latest version 0.6.9, I can confirm the second option to set .env manually every time works,
but not the first option where uv run is suppose to pick up the .env by default
UPDATE: Never mind just found: #9381