Accept multiple `.env` files in `UV_ENV_FILE` (#11665)

According to the [UV
documentation](https://docs.astral.sh/uv/configuration/files/#env), the
UV_ENV_FILE environment variable should support multiple .env files,
separated by spaces. However, when I tried using this feature in my
repository, it didn’t work as expected.

To investigate, I checked the UV repository for relevant tests and found
`run_with_multiple_env_files`.
This test asserts the following `error: No environment file found at:
.env1 .env2.`

This discrepancy could indicate either a mismatch between the
documentation and the implementation or a bug in the code.

I decided to fix the issue in the code since the ability to pass
multiple `.env` files is a valuable feature.
If my fix isn’t appropriate, I’d be happy to make any necessary
adjustments.

---------

Co-authored-by: Yaroslav Limanskiy <yaroslav.limanskiy@pandadoc.com>
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
Seven4ME 2025-02-21 06:37:22 +01:00 committed by GitHub
parent 4bab1cd002
commit 88aa6e26d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -2784,7 +2784,7 @@ pub struct RunArgs {
///
/// Can be provided multiple times, with subsequent files overriding values defined in previous
/// files.
#[arg(long, env = EnvVars::UV_ENV_FILE)]
#[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE)]
pub env_file: Vec<PathBuf>,
/// Avoid reading environment variables from a `.env` file.

View File

@ -3974,12 +3974,14 @@ fn run_with_multiple_env_files() -> Result<()> {
"###);
uv_snapshot!(context.filters(), context.run().arg("test.py").env(EnvVars::UV_ENV_FILE, ".env1 .env2"), @r###"
success: false
exit_code: 2
success: true
exit_code: 0
----- stdout -----
palpatine
obi_wan_kenobi
C3PO
----- stderr -----
error: No environment file found at: `.env1 .env2`
"###);
Ok(())