Skip to content

Commit e52cd5c

Browse files
Remove extraneous script packages in uv sync --script (#12158)
## Summary Closes #12145.
1 parent 40efe61 commit e52cd5c

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

crates/uv/src/commands/project/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,11 @@ pub(crate) async fn update_environment(
20322032

20332033
// Check if the current environment satisfies the requirements
20342034
let site_packages = SitePackages::from_environment(&venv)?;
2035-
if source_trees.is_empty() && reinstall.is_none() && upgrade.is_none() {
2035+
if reinstall.is_none()
2036+
&& upgrade.is_none()
2037+
&& source_trees.is_empty()
2038+
&& matches!(modifications, Modifications::Sufficient)
2039+
{
20362040
match site_packages.satisfies_spec(&requirements, &constraints, &overrides, &marker_env)? {
20372041
// If the requirements are already satisfied, we're done.
20382042
SatisfiesResult::Fresh {

crates/uv/tests/it/sync.rs

+31-6
Original file line numberDiff line numberDiff line change
@@ -3962,6 +3962,8 @@ fn sync_active_script_environment() -> Result<()> {
39623962
39633963
----- stderr -----
39643964
Using script environment at: foo
3965+
Resolved 3 packages in [TIME]
3966+
Audited 3 packages in [TIME]
39653967
"###);
39663968

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

7603+
// Remove a dependency.
7604+
script.write_str(indoc! { r#"
7605+
# /// script
7606+
# requires-python = ">=3.11"
7607+
# dependencies = [
7608+
# "anyio",
7609+
# ]
7610+
# ///
7611+
7612+
import anyio
7613+
"#
7614+
})?;
7615+
7616+
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r###"
7617+
success: true
7618+
exit_code: 0
7619+
----- stdout -----
7620+
7621+
----- stderr -----
7622+
Using script environment at: [CACHE_DIR]/environments-v2/script-[HASH]
7623+
Resolved 3 packages in [TIME]
7624+
Uninstalled 1 package in [TIME]
7625+
- iniconfig==2.0.0
7626+
"###);
7627+
76017628
// Modify the `requires-python`.
76027629
script.write_str(indoc! { r#"
76037630
# /// script
76047631
# requires-python = ">=3.8, <3.11"
76057632
# dependencies = [
76067633
# "anyio",
7607-
# "iniconfig",
76087634
# ]
76097635
# ///
76107636
76117637
import anyio
76127638
"#
76137639
})?;
76147640

7615-
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r"
7641+
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py"), @r###"
76167642
success: true
76177643
exit_code: 0
76187644
----- stdout -----
76197645
76207646
----- stderr -----
76217647
Recreating script environment at: [CACHE_DIR]/environments-v2/script-[HASH]
7622-
Resolved 6 packages in [TIME]
7648+
Resolved 5 packages in [TIME]
76237649
Prepared 2 packages in [TIME]
7624-
Installed 6 packages in [TIME]
7650+
Installed 5 packages in [TIME]
76257651
+ anyio==4.3.0
76267652
+ exceptiongroup==1.2.0
76277653
+ idna==3.6
7628-
+ iniconfig==2.0.0
76297654
+ sniffio==1.3.1
76307655
+ typing-extensions==4.10.0
7631-
");
7656+
"###);
76327657

76337658
// `--locked` and `--frozen` should fail with helpful error messages.
76347659
uv_snapshot!(&filters, context.sync().arg("--script").arg("script.py").arg("--locked"), @r"

crates/uv/tests/it/tool_install.rs

+6
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ fn tool_install_editable() {
563563
----- stdout -----
564564
565565
----- stderr -----
566+
Resolved 1 package in [TIME]
567+
Audited 1 package in [TIME]
566568
Installed 1 executable: black
567569
"###);
568570

@@ -2201,6 +2203,8 @@ fn tool_install_upgrade() {
22012203
----- stdout -----
22022204
22032205
----- stderr -----
2206+
Resolved [N] packages in [TIME]
2207+
Audited [N] packages in [TIME]
22042208
Installed 2 executables: black, blackd
22052209
"###);
22062210

@@ -3190,6 +3194,8 @@ fn tool_install_at_latest_upgrade() {
31903194
----- stdout -----
31913195
31923196
----- stderr -----
3197+
Resolved [N] packages in [TIME]
3198+
Audited [N] packages in [TIME]
31933199
Installed 2 executables: black, blackd
31943200
"###);
31953201

0 commit comments

Comments
 (0)