mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-30 22:11:12 +00:00
Always show lock updates in uv lock
(#5413)
## Summary Closes https://github.com/astral-sh/uv/issues/5412.
This commit is contained in:
parent
3d36b71ab1
commit
22db997240
7 changed files with 56 additions and 41 deletions
|
@ -244,7 +244,7 @@ pub(crate) async fn add(
|
|||
project::sync::do_sync(
|
||||
&VirtualProject::Project(project),
|
||||
&venv,
|
||||
&lock,
|
||||
&lock.lock,
|
||||
&extras,
|
||||
dev,
|
||||
Modifications::Sufficient,
|
||||
|
|
|
@ -32,6 +32,15 @@ use crate::commands::{pip, ExitStatus};
|
|||
use crate::printer::Printer;
|
||||
use crate::settings::{ResolverSettings, ResolverSettingsRef};
|
||||
|
||||
/// The result of running a lock operation.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct LockResult {
|
||||
/// The previous lock, if any.
|
||||
pub(crate) previous: Option<Lock>,
|
||||
/// The updated lock.
|
||||
pub(crate) lock: Lock,
|
||||
}
|
||||
|
||||
/// Resolve the project requirements into a lockfile.
|
||||
pub(crate) async fn lock(
|
||||
locked: bool,
|
||||
|
@ -86,7 +95,12 @@ pub(crate) async fn lock(
|
|||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(ExitStatus::Success),
|
||||
Ok(lock) => {
|
||||
if let Some(previous) = lock.previous.as_ref() {
|
||||
report_upgrades(previous, &lock.lock, printer)?;
|
||||
}
|
||||
Ok(ExitStatus::Success)
|
||||
}
|
||||
Err(ProjectError::Operation(pip::operations::Error::Resolve(
|
||||
uv_resolver::ResolveError::NoSolution(err),
|
||||
))) => {
|
||||
|
@ -112,12 +126,16 @@ pub(super) async fn do_safe_lock(
|
|||
native_tls: bool,
|
||||
cache: &Cache,
|
||||
printer: Printer,
|
||||
) -> Result<Lock, ProjectError> {
|
||||
) -> Result<LockResult, ProjectError> {
|
||||
if frozen {
|
||||
// Read the existing lockfile, but don't attempt to lock the project.
|
||||
read(workspace)
|
||||
let existing = read(workspace)
|
||||
.await?
|
||||
.ok_or_else(|| ProjectError::MissingLockfile)
|
||||
.ok_or_else(|| ProjectError::MissingLockfile)?;
|
||||
Ok(LockResult {
|
||||
previous: None,
|
||||
lock: existing,
|
||||
})
|
||||
} else if locked {
|
||||
// Read the existing lockfile.
|
||||
let existing = read(workspace)
|
||||
|
@ -145,7 +163,10 @@ pub(super) async fn do_safe_lock(
|
|||
return Err(ProjectError::LockMismatch);
|
||||
}
|
||||
|
||||
Ok(lock)
|
||||
Ok(LockResult {
|
||||
previous: Some(existing),
|
||||
lock,
|
||||
})
|
||||
} else {
|
||||
// Read the existing lockfile.
|
||||
let existing = read(workspace).await?;
|
||||
|
@ -166,16 +187,19 @@ pub(super) async fn do_safe_lock(
|
|||
)
|
||||
.await?;
|
||||
|
||||
if !existing.is_some_and(|existing| existing == lock) {
|
||||
if !existing.as_ref().is_some_and(|existing| *existing == lock) {
|
||||
commit(&lock, workspace).await?;
|
||||
}
|
||||
|
||||
Ok(lock)
|
||||
Ok(LockResult {
|
||||
previous: existing,
|
||||
lock,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Lock the project requirements into a lockfile.
|
||||
pub(super) async fn do_lock(
|
||||
async fn do_lock(
|
||||
workspace: &Workspace,
|
||||
interpreter: &Interpreter,
|
||||
existing_lock: Option<&Lock>,
|
||||
|
@ -506,16 +530,7 @@ pub(super) async fn do_lock(
|
|||
// Notify the user of any resolution diagnostics.
|
||||
pip::operations::diagnose_resolution(resolution.diagnostics(), printer)?;
|
||||
|
||||
let new_lock = Lock::from_resolution_graph(&resolution)?;
|
||||
|
||||
// Notify the user of any dependency updates
|
||||
if !upgrade.is_none() {
|
||||
if let Some(existing_lock) = existing_lock {
|
||||
report_upgrades(existing_lock, &new_lock, printer)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(new_lock)
|
||||
Ok(Lock::from_resolution_graph(&resolution)?)
|
||||
}
|
||||
|
||||
/// Write the lockfile to disk.
|
||||
|
|
|
@ -131,7 +131,7 @@ pub(crate) async fn remove(
|
|||
project::sync::do_sync(
|
||||
&VirtualProject::Project(project),
|
||||
&venv,
|
||||
&lock,
|
||||
&lock.lock,
|
||||
&extras,
|
||||
dev,
|
||||
Modifications::Exact,
|
||||
|
|
|
@ -238,7 +238,7 @@ pub(crate) async fn run(
|
|||
project::sync::do_sync(
|
||||
&project,
|
||||
&venv,
|
||||
&lock,
|
||||
&lock.lock,
|
||||
&extras,
|
||||
dev,
|
||||
Modifications::Sufficient,
|
||||
|
|
|
@ -95,7 +95,7 @@ pub(crate) async fn sync(
|
|||
do_sync(
|
||||
&project,
|
||||
&venv,
|
||||
&lock,
|
||||
&lock.lock,
|
||||
&extras,
|
||||
dev,
|
||||
modifications,
|
||||
|
|
|
@ -83,7 +83,7 @@ pub(crate) async fn tree(
|
|||
|
||||
// Read packages from the lockfile.
|
||||
let mut packages: IndexMap<_, Vec<_>> = IndexMap::new();
|
||||
for dist in lock.into_distributions() {
|
||||
for dist in lock.lock.into_distributions() {
|
||||
let name = dist.name().clone();
|
||||
let metadata = dist.to_metadata(workspace.install_path())?;
|
||||
packages.entry(name).or_default().push(metadata);
|
||||
|
|
|
@ -3569,7 +3569,6 @@ fn lock_new_extras() -> Result<()> {
|
|||
"#,
|
||||
)?;
|
||||
|
||||
deterministic! { context =>
|
||||
uv_snapshot!(context.filters(), context.lock().arg("--preview"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
|
@ -3577,6 +3576,7 @@ fn lock_new_extras() -> Result<()> {
|
|||
|
||||
----- stderr -----
|
||||
Resolved 7 packages in [TIME]
|
||||
Added pysocks v1.7.1
|
||||
"###);
|
||||
|
||||
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
|
||||
|
@ -3680,7 +3680,6 @@ fn lock_new_extras() -> Result<()> {
|
|||
"###
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3871,6 +3870,7 @@ fn lock_resolution_mode() -> Result<()> {
|
|||
warning: `uv lock` is experimental and may change without warning
|
||||
Ignoring existing lockfile due to change in resolution mode: `highest` vs. `lowest-direct`
|
||||
Resolved 4 packages in [TIME]
|
||||
Updated anyio v4.3.0 -> v3.0.0
|
||||
"###);
|
||||
|
||||
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue