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

Remove extraneous script packages in uv sync --script #12158

Merged
merged 1 commit into from
Mar 14, 2025
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
6 changes: 5 additions & 1 deletion crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,11 @@ pub(crate) async fn update_environment(

// Check if the current environment satisfies the requirements
let site_packages = SitePackages::from_environment(&venv)?;
if source_trees.is_empty() && reinstall.is_none() && upgrade.is_none() {
if reinstall.is_none()
&& upgrade.is_none()
&& source_trees.is_empty()
&& matches!(modifications, Modifications::Sufficient)
{
match site_packages.satisfies_spec(&requirements, &constraints, &overrides, &marker_env)? {
// If the requirements are already satisfied, we're done.
SatisfiesResult::Fresh {
Expand Down
37 changes: 31 additions & 6 deletions crates/uv/tests/it/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3962,6 +3962,8 @@ fn sync_active_script_environment() -> Result<()> {

----- stderr -----
Using script environment at: foo
Resolved 3 packages in [TIME]
Audited 3 packages in [TIME]
"###);

// Requesting another Python version will invalidate the environment
Expand Down Expand Up @@ -7598,37 +7600,60 @@ fn sync_script() -> Result<()> {
+ iniconfig==2.0.0
");

// Remove a dependency.
script.write_str(indoc! { r#"
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "anyio",
# ]
# ///

import anyio
"#
})?;

uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Using script environment at: [CACHE_DIR]/environments-v2/script-[HASH]
Resolved 3 packages in [TIME]
Uninstalled 1 package in [TIME]
- iniconfig==2.0.0
"###);

// Modify the `requires-python`.
script.write_str(indoc! { r#"
# /// script
# requires-python = ">=3.8, <3.11"
# dependencies = [
# "anyio",
# "iniconfig",
# ]
# ///

import anyio
"#
})?;

uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r"
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Recreating script environment at: [CACHE_DIR]/environments-v2/script-[HASH]
Resolved 6 packages in [TIME]
Resolved 5 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 6 packages in [TIME]
Installed 5 packages in [TIME]
+ anyio==4.3.0
+ exceptiongroup==1.2.0
+ idna==3.6
+ iniconfig==2.0.0
+ sniffio==1.3.1
+ typing-extensions==4.10.0
");
"###);

// `--locked` and `--frozen` should fail with helpful error messages.
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py").arg("--locked"), @r"
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/tests/it/tool_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ fn tool_install_editable() {
----- stdout -----

----- stderr -----
Resolved 1 package in [TIME]
Audited 1 package in [TIME]
Installed 1 executable: black
"###);

Expand Down Expand Up @@ -2201,6 +2203,8 @@ fn tool_install_upgrade() {
----- stdout -----

----- stderr -----
Resolved [N] packages in [TIME]
Audited [N] packages in [TIME]
Installed 2 executables: black, blackd
"###);

Expand Down Expand Up @@ -3190,6 +3194,8 @@ fn tool_install_at_latest_upgrade() {
----- stdout -----

----- stderr -----
Resolved [N] packages in [TIME]
Audited [N] packages in [TIME]
Installed 2 executables: black, blackd
"###);

Expand Down
Loading