Skip to content

Commit

Permalink
Unset target when creating virtual environments
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed May 3, 2024
1 parent 4f87edb commit 0a49304
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/uv-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Interpreter {
scheme: virtualenv.scheme,
sys_executable: virtualenv.executable,
prefix: virtualenv.root,
target: None,
..self
}
}
Expand Down
49 changes: 47 additions & 2 deletions crates/uv/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4809,9 +4809,9 @@ fn require_hashes_registry_invalid_hash() -> Result<()> {
Ok(())
}

/// Sync to a `--target` directory.
/// Sync to a `--target` directory with a built distribution.
#[test]
fn target() -> Result<()> {
fn target_built_distribution() -> Result<()> {
let context = TestContext::new("3.12");

// Install `iniconfig` to the target directory.
Expand Down Expand Up @@ -4900,3 +4900,48 @@ fn target() -> Result<()> {

Ok(())
}

/// Sync to a `--target` directory with a package that requires building from source.
#[test]
fn target_source_distribution() -> Result<()> {
let context = TestContext::new("3.12");

// Install `iniconfig` to the target directory.
let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("iniconfig==2.0.0")?;

uv_snapshot!(command(&context)
.arg("requirements.in")
.arg("--no-binary")
.arg("iniconfig")
.arg("--target")
.arg("target"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ iniconfig==2.0.0
"###);

// Ensure that the package is present in the target directory.
assert!(context.temp_dir.child("target").child("iniconfig").is_dir());

// Ensure that we can't import the package.
context.assert_command("import iniconfig").failure();

// Ensure that we can import the package by augmenting the `PYTHONPATH`.
Command::new(venv_to_interpreter(&context.venv))
.arg("-B")
.arg("-c")
.arg("import iniconfig")
.env("PYTHONPATH", context.temp_dir.child("target").path())
.current_dir(&context.temp_dir)
.assert()
.success();

Ok(())
}

0 comments on commit 0a49304

Please sign in to comment.