Skip to content

Commit

Permalink
Remove setuptools & wheel from seed packages (#1602) (#1613)
Browse files Browse the repository at this point in the history
## Summary
Removed `wheel` and `setuptools` from seed packages list when creating a
virtual environment

Closes #1602

## Test Plan
Ran the command `cargo nextest run` :
<img width="564" alt="image"
src="https://github.com/astral-sh/uv/assets/6116387/14ed2da6-1b3e-4598-a49f-29dd8c4cb19b">

---------

Co-authored-by: Zanie <[email protected]>
  • Loading branch information
arjunnn and zanieb authored Feb 18, 2024
1 parent 63c3134 commit 3ed386c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Write;
use std::path::Path;
use std::str::FromStr;
use std::vec;

use anstream::eprint;
use anyhow::Result;
Expand Down Expand Up @@ -160,12 +161,15 @@ async fn venv_impl(
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build());

// Resolve the seed packages.
let mut requirements = vec![Requirement::from_str("pip").unwrap()];

// Only include `setuptools` and `wheel` on Python <3.12
if interpreter.python_tuple() < (3, 12) {
requirements.push(Requirement::from_str("setuptools").unwrap());
requirements.push(Requirement::from_str("wheel").unwrap());
}
let resolution = build_dispatch
.resolve(&[
Requirement::from_str("wheel").unwrap(),
Requirement::from_str("pip").unwrap(),
Requirement::from_str("setuptools").unwrap(),
])
.resolve(&requirements)
.await
.map_err(VenvError::Seed)?;

Expand Down
44 changes: 44 additions & 0 deletions crates/uv/tests/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,50 @@ fn seed() -> Result<()> {
exit_code: 0
----- stdout -----
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
+ pip==23.3.1
"###
);

venv.assert(predicates::path::is_dir());

Ok(())
}

#[test]
fn seed_older_python_version() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let bin = create_bin_with_executables(&temp_dir, &["3.10"]).expect("Failed to create bin dir");
let venv = temp_dir.child(".venv");

let filter_venv = regex::escape(&venv.normalized_display().to_string());
let filters = &[
(
r"Using Python 3\.\d+\.\d+ interpreter at .+",
"Using Python [VERSION] interpreter at [PATH]",
),
(&filter_venv, "/home/ferris/project/.venv"),
];
uv_snapshot!(filters, Command::new(get_bin())
.arg("venv")
.arg(venv.as_os_str())
.arg("--seed")
.arg("--python")
.arg("3.10")
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--exclude-newer")
.arg(EXCLUDE_NEWER)
.env("UV_NO_WRAP", "1")
.env("UV_TEST_PYTHON_PATH", bin)
.current_dir(&temp_dir), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Using Python [VERSION] interpreter at [PATH]
Creating virtualenv at: /home/ferris/project/.venv
Expand Down

0 comments on commit 3ed386c

Please sign in to comment.