From b001edb03683eba9b72853828717568bd267da3c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Jan 2026 20:53:28 +0000 Subject: [PATCH 1/2] Add failing test for UV_NO_SYNC=1 env var not working with uv run This test demonstrates issue #17390 where setting `UV_NO_SYNC=1` environment variable does not prevent `uv run` from syncing the environment. The root cause is that `RunSettings::resolve()` doesn't use `resolve_flag()` to combine the CLI argument with the environment variable, unlike other commands like `uv add`, `uv remove`, and `uv version` which handle it correctly. --- crates/uv/tests/it/run.rs | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 9c6c4b6fba8c4..0f3298908efbd 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -2433,6 +2433,65 @@ fn run_no_sync() -> Result<()> { Ok(()) } +/// Test that `UV_NO_SYNC=1` environment variable works for `uv run`. +/// +/// See: +#[test] +fn run_no_sync_env_var() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "project" + version = "0.1.0" + requires-python = ">=3.12" + dependencies = ["anyio==3.7.0"] + + [build-system] + requires = ["setuptools>=42"] + build-backend = "setuptools.build_meta" + "#, + )?; + + // Running with `UV_NO_SYNC=1` should succeed, even if the lockfile isn't present. + uv_snapshot!(context.filters(), context.run().env(EnvVars::UV_NO_SYNC, "1").arg("--").arg("python").arg("--version"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + Python 3.12.[X] + + ----- stderr ----- + "###); + + context.lock().assert().success(); + + // Running with `UV_NO_SYNC=1` should not install any requirements. + uv_snapshot!(context.filters(), context.run().env(EnvVars::UV_NO_SYNC, "1").arg("--").arg("python").arg("--version"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + Python 3.12.[X] + + ----- stderr ----- + "###); + + context.sync().assert().success(); + + // But it should have access to the installed packages. + uv_snapshot!(context.filters(), context.run().env(EnvVars::UV_NO_SYNC, "1").arg("--").arg("python").arg("-c").arg("import anyio; print(anyio.__name__)"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + anyio + + ----- stderr ----- + "###); + + Ok(()) +} + #[test] fn run_empty_requirements_txt() -> Result<()> { let context = TestContext::new("3.12"); From 53ecea1ab50eb0962317edcfb8014cc75593ac77 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Jan 2026 20:59:39 +0000 Subject: [PATCH 2/2] Fix UV_NO_SYNC=1 not working for uv run The `RunSettings::resolve()` function was passing the `no_sync` CLI argument directly without using `resolve_flag()` to combine it with the `UV_NO_SYNC` environment variable. This fix adds `resolve_flag(no_sync, "no-sync", environment.no_sync)` to properly resolve the flag from both CLI and environment variable sources, matching how other commands (add, remove, version) already handle this flag. Fixes #17390 --- crates/uv/src/settings.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index da7055138f9d7..8b0beda0b0b9b 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -620,6 +620,7 @@ impl RunSettings { // Resolve flags from CLI and environment variables. let locked = resolve_flag(locked, "locked", environment.locked); let frozen = resolve_flag(frozen, "frozen", environment.frozen); + let no_sync = resolve_flag(no_sync, "no-sync", environment.no_sync); // Check for conflicts between locked and frozen. check_conflicts(locked, frozen); @@ -677,7 +678,7 @@ impl RunSettings { all_packages, package, no_project, - no_sync, + no_sync: no_sync.is_enabled(), active: flag(active, no_active, "active"), python: python.and_then(Maybe::into_option), python_platform,