Remove extraneous script packages in `uv sync --script` (#12158)

## Summary

Closes https://github.com/astral-sh/uv/issues/12145.
This commit is contained in:
Charlie Marsh 2025-03-13 17:41:44 -07:00 committed by GitHub
parent 40efe6119b
commit e52cd5c7a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 9 deletions

View File

@ -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 {

View File

@ -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
@ -7598,13 +7600,12 @@ fn sync_script() -> Result<()> {
+ iniconfig==2.0.0
");
// Modify the `requires-python`.
// Remove a dependency.
script.write_str(indoc! { r#"
# /// script
# requires-python = ">=3.8, <3.11"
# requires-python = ">=3.11"
# dependencies = [
# "anyio",
# "iniconfig",
# ]
# ///
@ -7612,23 +7613,47 @@ fn sync_script() -> Result<()> {
"#
})?;
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 -----
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",
# ]
# ///
import anyio
"#
})?;
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"

View File

@ -563,6 +563,8 @@ fn tool_install_editable() {
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Audited 1 package in [TIME]
Installed 1 executable: black
"###);
@ -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
"###);
@ -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
"###);