mirror of https://github.com/astral-sh/uv
Create a PackageChangesReport newtype
This commit is contained in:
parent
27c2700810
commit
0136edcd54
|
|
@ -212,7 +212,7 @@ pub(crate) async fn sync(
|
||||||
environment: EnvironmentReport::from(&environment),
|
environment: EnvironmentReport::from(&environment),
|
||||||
action: SyncAction::from(&environment),
|
action: SyncAction::from(&environment),
|
||||||
target: TargetName::from(&target),
|
target: TargetName::from(&target),
|
||||||
changes: Vec::new(),
|
changes: PackageChangesReport::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show the intermediate results if relevant
|
// Show the intermediate results if relevant
|
||||||
|
|
@ -301,7 +301,7 @@ pub(crate) async fn sync(
|
||||||
project: None,
|
project: None,
|
||||||
script: Some(ScriptReport::from(script)),
|
script: Some(ScriptReport::from(script)),
|
||||||
sync: SyncReport {
|
sync: SyncReport {
|
||||||
changes: PackageChangeReport::from_changelog(&changelog),
|
changes: PackageChangesReport::from_changelog(&changelog),
|
||||||
..sync_report
|
..sync_report
|
||||||
},
|
},
|
||||||
lock: None,
|
lock: None,
|
||||||
|
|
@ -435,7 +435,7 @@ pub(crate) async fn sync(
|
||||||
project: target.project().map(ProjectReport::from),
|
project: target.project().map(ProjectReport::from),
|
||||||
script: target.script().map(ScriptReport::from),
|
script: target.script().map(ScriptReport::from),
|
||||||
sync: SyncReport {
|
sync: SyncReport {
|
||||||
changes: PackageChangeReport::from_changelog(&changelog),
|
changes: PackageChangesReport::from_changelog(&changelog),
|
||||||
..sync_report
|
..sync_report
|
||||||
},
|
},
|
||||||
lock: Some(lock_report),
|
lock: Some(lock_report),
|
||||||
|
|
@ -1263,7 +1263,7 @@ struct SyncReport {
|
||||||
action: SyncAction,
|
action: SyncAction,
|
||||||
/// The packages that changed during the sync.
|
/// The packages that changed during the sync.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
changes: Vec<PackageChangeReport>,
|
changes: PackageChangesReport,
|
||||||
|
|
||||||
// We store these fields so the report can format itself self-contained, but the outer
|
// 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
|
// [`Report`] is intended to include these in user-facing output
|
||||||
|
|
@ -1305,6 +1305,35 @@ impl SyncReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A summary of all package changes performed during sync.
|
||||||
|
#[derive(Serialize, Debug, Clone, Default)]
|
||||||
|
struct PackageChangesReport(Vec<PackageChangeReport>);
|
||||||
|
|
||||||
|
impl PackageChangesReport {
|
||||||
|
fn from_changelog(changelog: &Changelog) -> Self {
|
||||||
|
let mut changes: Vec<_> =
|
||||||
|
changelog
|
||||||
|
.uninstalled
|
||||||
|
.iter()
|
||||||
|
.map(|dist| PackageChangeReport::from_dist(dist, PackageChangeAction::Uninstalled))
|
||||||
|
.chain(changelog.installed.iter().map(|dist| {
|
||||||
|
PackageChangeReport::from_dist(dist, PackageChangeAction::Installed)
|
||||||
|
}))
|
||||||
|
.chain(changelog.reinstalled.iter().map(|dist| {
|
||||||
|
PackageChangeReport::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))
|
||||||
|
});
|
||||||
|
Self(changes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A summary of a single package change performed during sync.
|
/// A summary of a single package change performed during sync.
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
struct PackageChangeReport {
|
struct PackageChangeReport {
|
||||||
|
|
@ -1318,34 +1347,6 @@ struct PackageChangeReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PackageChangeReport {
|
impl PackageChangeReport {
|
||||||
fn from_changelog(changelog: &Changelog) -> Vec<Self> {
|
|
||||||
let mut changes: Vec<_> = changelog
|
|
||||||
.uninstalled
|
|
||||||
.iter()
|
|
||||||
.map(|dist| Self::from_dist(dist, PackageChangeAction::Uninstalled))
|
|
||||||
.chain(
|
|
||||||
changelog
|
|
||||||
.installed
|
|
||||||
.iter()
|
|
||||||
.map(|dist| Self::from_dist(dist, PackageChangeAction::Installed)),
|
|
||||||
)
|
|
||||||
.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: &ChangedDist, action: PackageChangeAction) -> Self {
|
fn from_dist(dist: &ChangedDist, action: PackageChangeAction) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: dist.name().clone(),
|
name: dist.name().clone(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue