From 88aa6e26d15828af514038ba04459830ee2ed00b Mon Sep 17 00:00:00 2001 From: Seven4ME <35870022+Seven4ME@users.noreply.github.com> Date: Fri, 21 Feb 2025 06:37:22 +0100 Subject: [PATCH] Accept multiple `.env` files in `UV_ENV_FILE` (#11665) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Charlie Marsh --- crates/uv-cli/src/lib.rs | 2 +- crates/uv/tests/it/run.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index d9e08a813..530873112 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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, /// Avoid reading environment variables from a `.env` file. diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 1ae18d843..4c36be01e 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -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(())