From 1a72f8c67766af28dc387f6dba28067140ea9e8f Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 9 Jan 2026 15:37:20 -0600 Subject: [PATCH] Fix handling of `UV_NO_SYNC=1 uv run ...` (#17391) Closes #17390 --------- Co-authored-by: Claude --- crates/uv/src/settings.rs | 3 +- crates/uv/tests/it/run.rs | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 08e49f2c9..f0b169b20 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, diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 9c6c4b6fb..0f3298908 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");