Fix handling of UV_NO_SYNC=1 uv run ... (#17391)

Closes #17390

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Zanie Blue
2026-01-09 15:37:20 -06:00
committed by GitHub
parent ef83fc34bc
commit 1a72f8c677
2 changed files with 61 additions and 1 deletions

View File

@@ -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,

View File

@@ -2433,6 +2433,65 @@ fn run_no_sync() -> Result<()> {
Ok(())
}
/// Test that `UV_NO_SYNC=1` environment variable works for `uv run`.
///
/// See: <https://github.com/astral-sh/uv/issues/17390>
#[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");