Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow system Python discovery with --target and --prefix #9371

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,22 @@ pub(crate) async fn pip_install(
)
.collect();

// Determine whether we're modifying the discovered environment, or a separate target.
let mutable = !(target.is_some() || prefix.is_some());

// Detect the current Python interpreter.
let environment = PythonEnvironment::find(
&python
.as_deref()
.map(PythonRequest::parse)
.unwrap_or_default(),
EnvironmentPreference::from_system_flag(system, true),
EnvironmentPreference::from_system_flag(system, mutable),
&cache,
)?;

report_target_environment(&environment, &cache, printer)?;
if mutable {
report_target_environment(&environment, &cache, printer)?;
}

// Apply any `--target` or `--prefix` directories.
let environment = if let Some(target) = target {
Expand Down
9 changes: 7 additions & 2 deletions crates/uv/src/commands/pip/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,22 @@ pub(crate) async fn pip_sync(
}
}

// Determine whether we're modifying the discovered environment, or a separate target.
let mutable = !(target.is_some() || prefix.is_some());

// Detect the current Python interpreter.
let environment = PythonEnvironment::find(
&python
.as_deref()
.map(PythonRequest::parse)
.unwrap_or_default(),
EnvironmentPreference::from_system_flag(system, true),
EnvironmentPreference::from_system_flag(system, mutable),
&cache,
)?;

report_target_environment(&environment, &cache, printer)?;
if mutable {
report_target_environment(&environment, &cache, printer)?;
}

// Apply any `--target` or `--prefix` directories.
let environment = if let Some(target) = target {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl TestContext {
// Exclude `link-mode` on Windows since we set it in the remote test suite
if cfg!(windows) {
filters.push(("--link-mode <LINK_MODE> ".to_string(), String::new()));
filters.push(((r#"link-mode = "copy"\n"#).to_string(), String::new()));
filters.push((r#"link-mode = "copy"\n"#.to_string(), String::new()));
}

filters.extend(
Expand Down
30 changes: 30 additions & 0 deletions crates/uv/tests/it/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5361,6 +5361,36 @@ fn target_no_build_isolation() -> Result<()> {
Ok(())
}

/// Sync to a `--target` directory without a virtual environment.
#[test]
fn target_system() -> Result<()> {
let context = TestContext::new_with_versions(&["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!(context.filters(), context.pip_sync()
.arg("requirements.in")
.arg("--target")
.arg("target"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 1 package in [TIME]
Prepared 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());

Ok(())
}

/// Sync to a `--prefix` directory.
#[test]
fn prefix() -> Result<()> {
Expand Down
Loading