Clear discovered interpreters when creating virtual environment (#15522)

## Summary

Closes https://github.com/astral-sh/uv/issues/15518.
This commit is contained in:
Charlie Marsh 2025-08-25 20:24:24 -04:00 committed by GitHub
parent 9b8d6989d4
commit b723129c7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 82 additions and 0 deletions

View File

@ -106,6 +106,7 @@ impl Interpreter {
sys_prefix: virtualenv.root,
target: None,
prefix: None,
site_packages: vec![],
..self
}
}

View File

@ -5958,3 +5958,84 @@ fn run_python_preference_no_project() {
----- stderr -----
");
}
/// Regression test for: <https://github.com/astral-sh/uv/issues/15518>
#[test]
fn isolate_child_environment() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! { r#"
[project]
name = "foo"
version = "1.0.0"
requires-python = ">=3.12"
dependencies = [
"iniconfig"
]
[tool.uv.workspace]
members = ["child"]
"#
})?;
context
.temp_dir
.child("child")
.child("pyproject.toml")
.write_str(indoc! { r#"
[project]
name = "child"
version = "1.0.0"
requires-python = ">=3.12"
dependencies = []
"#
})?;
// Sync the parent package.
uv_snapshot!(context.filters(), context.sync(), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 3 packages in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
");
// Ensure that the isolated environment can't access `iniconfig` (from the parent package).
uv_snapshot!(context.filters(), context.run().arg("--package").arg("child").arg("--isolated").arg("python").arg("-c").arg("import iniconfig"), @r#"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
Resolved 3 packages in [TIME]
Audited in [TIME]
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'iniconfig'
"#);
// Ensure that the isolated environment can't access `iniconfig` (from the parent package).
uv_snapshot!(context.filters(), context.run().arg("--package").arg("child").arg("--isolated").arg("--with").arg("typing-extensions").arg("python").arg("-c").arg("import iniconfig"), @r#"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
Resolved 3 packages in [TIME]
Audited in [TIME]
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ typing-extensions==4.10.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'iniconfig'
"#);
Ok(())
}