uv icon indicating copy to clipboard operation
uv copied to clipboard

add ability to load from .env files before invoking the command

Open haydn-j-evans opened this issue 1 year ago • 7 comments

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.

haydn-j-evans avatar Sep 13 '24 11:09 haydn-j-evans

dotenv is implicitly unmaintained. Ref: https://github.com/rustsec/advisory-db/issues/1254

eth3lbert avatar Sep 13 '24 11:09 eth3lbert

@eth3lbert I will switch it to dotenvy if you are happy with the idea of the PR :)

haydn-j-evans avatar Sep 13 '24 11:09 haydn-j-evans

Can't wait for this to land, we're excited to switch to uv, but are currently blocked by this.

theintz avatar Sep 26 '24 10:09 theintz

@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.

haydn-j-evans avatar Oct 09 '24 12:10 haydn-j-evans

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 avatar Oct 09 '24 12:10 PhilipVinc

@PhilipVinc currently it only affects the run command, it would have to be further expanded to support uv global config.

haydn-j-evans avatar Oct 09 '24 12:10 haydn-j-evans

Yeah I think my preference would be:

  • Read .env by default (only in uv run for now; we may expand it later).
  • Allow users to pass --env-file (or UV_ENV_FILE) to override the file.
  • Add --no-env-file and UV_NO_ENV_FILE to disable it.

I think we can omit the UV_RUN_ prefixes.

charliermarsh avatar Oct 09 '24 22:10 charliermarsh

closing this as it seems to be implemented already

haydn-j-evans avatar Nov 05 '24 12:11 haydn-j-evans

Yeah I think my preference would be:

  • Read .env by default (only in uv run for now; we may expand it later).
  • Allow users to pass --env-file (or UV_ENV_FILE) to override the file.
  • Add --no-env-file and UV_NO_ENV_FILE to 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

shreyansp avatar Mar 26 '25 11:03 shreyansp