Add support for .env and custom env files in uv run (#8811)

## Summary

This PR pulls in https://github.com/astral-sh/uv/pull/8263 and
https://github.com/astral-sh/uv/pull/8463, which were originally merged
into the v0.5 tracking branch but can now be committed separately, as
we've made `.env` loading opt-in.

In summary:

- `.env` loading is now opt-in (`--env-file .env`).
- `.env` remains supported on `uv run`, so it's meant for providing
environment variables to the run command, rather than to uv itself.

---------

Co-authored-by: Eduardo González Vaquero <47718648+edugzlez@users.noreply.github.com>
This commit is contained in:
Charlie Marsh 2024-11-04 14:26:05 -05:00 committed by GitHub
parent 224622b089
commit a42c09fdfb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 326 additions and 3 deletions

View file

@ -2656,6 +2656,17 @@ pub struct RunArgs {
#[arg(long)]
pub no_editable: bool,
/// Load environment variables from a `.env` file.
///
/// Can be provided multiple times, with subsequent files overriding values defined in
/// previous files.
#[arg(long, env = EnvVars::UV_ENV_FILE)]
pub env_file: Vec<PathBuf>,
/// Avoid reading environment variables from a `.env` file.
#[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_ENV_FILE)]
pub no_env_file: bool,
/// The command to run.
///
/// If the path to a Python script (i.e., ending in `.py`), it will be