-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add package change summaries to uv sync json output
#16660
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
Draft
terror
wants to merge
3
commits into
astral-sh:main
Choose a base branch
from
terror:package-sync-install-summary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,8 @@ use uv_configuration::{ | |
| use uv_dispatch::BuildDispatch; | ||
| use uv_distribution::LoweredExtraBuildDependencies; | ||
| use uv_distribution_types::{ | ||
| DirectorySourceDist, Dist, Index, Requirement, Resolution, ResolvedDist, SourceDist, | ||
| DirectorySourceDist, Dist, Index, InstalledMetadata, LocalDist, Name, Requirement, Resolution, | ||
| ResolvedDist, SourceDist, | ||
| }; | ||
| use uv_fs::{PortablePathBuf, Simplified}; | ||
| use uv_installer::{InstallationStrategy, SitePackages}; | ||
|
|
@@ -37,16 +38,16 @@ use uv_workspace::pyproject::Source; | |
| use uv_workspace::{DiscoveryOptions, MemberDiscovery, VirtualProject, Workspace, WorkspaceCache}; | ||
|
|
||
| use crate::commands::pip::loggers::{DefaultInstallLogger, DefaultResolveLogger, InstallLogger}; | ||
| use crate::commands::pip::operations::Modifications; | ||
| use crate::commands::pip::operations::{Changelog, Modifications}; | ||
| use crate::commands::pip::resolution_markers; | ||
| use crate::commands::pip::{operations, resolution_tags}; | ||
| use crate::commands::project::install_target::InstallTarget; | ||
| use crate::commands::project::lock::{LockMode, LockOperation, LockResult}; | ||
| use crate::commands::project::lock_target::LockTarget; | ||
| use crate::commands::project::{ | ||
| PlatformState, ProjectEnvironment, ProjectError, ScriptEnvironment, UniversalState, | ||
| default_dependency_groups, detect_conflicts, script_extra_build_requires, script_specification, | ||
| update_environment, | ||
| EnvironmentUpdate, PlatformState, ProjectEnvironment, ProjectError, ScriptEnvironment, | ||
| UniversalState, default_dependency_groups, detect_conflicts, script_extra_build_requires, | ||
| script_specification, update_environment, | ||
| }; | ||
| use crate::commands::{ExitStatus, diagnostics}; | ||
| use crate::printer::Printer; | ||
|
|
@@ -212,6 +213,7 @@ pub(crate) async fn sync( | |
| environment: EnvironmentReport::from(&environment), | ||
| action: SyncAction::from(&environment), | ||
| target: TargetName::from(&target), | ||
| packages: Vec::new(), | ||
| }; | ||
|
|
||
| // Show the intermediate results if relevant | ||
|
|
@@ -283,14 +285,17 @@ pub(crate) async fn sync( | |
| ) | ||
| .await | ||
| { | ||
| Ok(..) => { | ||
| Ok(EnvironmentUpdate { changelog, .. }) => { | ||
| // Generate a report for the script without a lockfile | ||
| let report = Report { | ||
| schema: SchemaReport::default(), | ||
| target: TargetName::from(&target), | ||
| project: None, | ||
| script: Some(ScriptReport::from(script)), | ||
| sync: sync_report, | ||
| sync: SyncReport { | ||
| packages: PackageChangeReport::from_changelog(&changelog), | ||
| ..sync_report | ||
| }, | ||
| lock: None, | ||
| dry_run: dry_run.enabled(), | ||
| }; | ||
|
|
@@ -378,27 +383,13 @@ pub(crate) async fn sync( | |
| writeln!(printer.stderr(), "{message}")?; | ||
| } | ||
|
|
||
| let report = Report { | ||
| schema: SchemaReport::default(), | ||
| target: TargetName::from(&target), | ||
| project: target.project().map(ProjectReport::from), | ||
| script: target.script().map(ScriptReport::from), | ||
| sync: sync_report, | ||
| lock: Some(lock_report), | ||
| dry_run: dry_run.enabled(), | ||
| }; | ||
|
|
||
| if let Some(output) = report.format(output_format) { | ||
| writeln!(printer.stdout_important(), "{output}")?; | ||
| } | ||
|
|
||
| // Identify the installation target. | ||
| let sync_target = identify_installation_target(&target, outcome.lock(), all_packages, &package); | ||
|
|
||
| let state = state.fork(); | ||
|
|
||
| // Perform the sync operation. | ||
| match do_sync( | ||
| let changelog = match do_sync( | ||
| sync_target, | ||
| &environment, | ||
| &extras, | ||
|
|
@@ -421,13 +412,30 @@ pub(crate) async fn sync( | |
| ) | ||
| .await | ||
| { | ||
| Ok(()) => {} | ||
| Ok(changelog) => changelog, | ||
| Err(ProjectError::Operation(err)) => { | ||
| return diagnostics::OperationDiagnostic::native_tls(client_builder.is_native_tls()) | ||
| .report(err) | ||
| .map_or(Ok(ExitStatus::Failure), |err| Err(err.into())); | ||
| } | ||
| Err(err) => return Err(err.into()), | ||
| }; | ||
|
|
||
| let report = Report { | ||
| schema: SchemaReport::default(), | ||
| target: TargetName::from(&target), | ||
| project: target.project().map(ProjectReport::from), | ||
| script: target.script().map(ScriptReport::from), | ||
| sync: SyncReport { | ||
| packages: PackageChangeReport::from_changelog(&changelog), | ||
| ..sync_report | ||
| }, | ||
| lock: Some(lock_report), | ||
| dry_run: dry_run.enabled(), | ||
| }; | ||
|
|
||
| if let Some(output) = report.format(output_format) { | ||
| writeln!(printer.stdout_important(), "{output}")?; | ||
| } | ||
|
|
||
| match outcome { | ||
|
|
@@ -605,7 +613,7 @@ pub(super) async fn do_sync( | |
| dry_run: DryRun, | ||
| printer: Printer, | ||
| preview: Preview, | ||
| ) -> Result<(), ProjectError> { | ||
| ) -> Result<Changelog, ProjectError> { | ||
| // Extract the project settings. | ||
| let InstallerSettingsRef { | ||
| index_locations, | ||
|
|
@@ -811,7 +819,7 @@ pub(super) async fn do_sync( | |
| let site_packages = SitePackages::from_environment(venv)?; | ||
|
|
||
| // Sync the environment. | ||
| operations::install( | ||
| let changelog = operations::install( | ||
| &resolution, | ||
| site_packages, | ||
| InstallationStrategy::Strict, | ||
|
|
@@ -836,7 +844,7 @@ pub(super) async fn do_sync( | |
| ) | ||
| .await?; | ||
|
|
||
| Ok(()) | ||
| Ok(changelog) | ||
| } | ||
|
|
||
| /// Filter out any virtual workspace members. | ||
|
|
@@ -1240,6 +1248,9 @@ struct SyncReport { | |
| environment: EnvironmentReport, | ||
| /// The action performed during the sync, e.g., what was done to the environment. | ||
| action: SyncAction, | ||
| /// The packages that changed during the sync. | ||
| #[serde(default)] | ||
| packages: Vec<PackageChangeReport>, | ||
|
|
||
| // We store these fields so the report can format itself self-contained, but the outer | ||
| // [`Report`] is intended to include these in user-facing output | ||
|
|
@@ -1262,6 +1273,7 @@ impl SyncReport { | |
| let Self { | ||
| environment, | ||
| action, | ||
| packages: _, | ||
| dry_run, | ||
| target, | ||
| } = self; | ||
|
|
@@ -1280,6 +1292,80 @@ impl SyncReport { | |
| } | ||
| } | ||
|
|
||
| /// A summary of a single package change performed during sync. | ||
| #[derive(Serialize, Debug, Clone)] | ||
| struct PackageChangeReport { | ||
| /// The normalized package name. | ||
| name: String, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| /// The resolved version of the package. | ||
| version: String, | ||
| /// The source for URL-based requirements. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| source: Option<PackageChangeSourceReport>, | ||
| /// The action that was taken for the package. | ||
| action: PackageChangeAction, | ||
| } | ||
|
|
||
| impl PackageChangeReport { | ||
| fn from_changelog(changelog: &Changelog) -> Vec<Self> { | ||
| let mut changes: Vec<_> = changelog | ||
| .uninstalled | ||
| .iter() | ||
| .map(|dist| Self::from_dist(dist, PackageChangeAction::Removed)) | ||
| .chain( | ||
| changelog | ||
| .installed | ||
| .iter() | ||
| .map(|dist| Self::from_dist(dist, PackageChangeAction::Added)), | ||
| ) | ||
| .chain( | ||
| changelog | ||
| .reinstalled | ||
| .iter() | ||
| .map(|dist| Self::from_dist(dist, PackageChangeAction::Reinstalled)), | ||
| ) | ||
| .collect(); | ||
|
|
||
| changes.sort_by(|a, b| { | ||
| a.name | ||
| .cmp(&b.name) | ||
| .then_with(|| a.action.cmp(&b.action)) | ||
| .then_with(|| a.version.cmp(&b.version)) | ||
| }); | ||
| changes | ||
| } | ||
|
|
||
| fn from_dist(dist: &LocalDist, action: PackageChangeAction) -> Self { | ||
| let installed_version = dist.installed_version(); | ||
|
|
||
| Self { | ||
| name: dist.name().to_string(), | ||
| version: installed_version.version().to_string(), | ||
| source: installed_version | ||
| .url() | ||
| .map(|url| PackageChangeSourceReport { | ||
| url: url.to_string(), | ||
| }), | ||
| action, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The action taken on an individual package during sync. | ||
| #[derive(Serialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
| #[serde(rename_all = "snake_case")] | ||
| enum PackageChangeAction { | ||
| Removed, | ||
| Added, | ||
| Reinstalled, | ||
| } | ||
|
|
||
| /// The source for a package change, when it originated from a URL requirement. | ||
| #[derive(Serialize, Debug, Clone)] | ||
| struct PackageChangeSourceReport { | ||
| url: String, | ||
| } | ||
|
|
||
| /// The report for a lock operation. | ||
| #[derive(Debug, Serialize)] | ||
| struct LockReport { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at it... I wonder if we should call it
changes? I worrypackagescould be confusing because it doesn't imply it's only the packages that changedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we also want to enumerate all the packages that are unchanged here, with
action: check... hm.