-
Notifications
You must be signed in to change notification settings - Fork 3k
Refresh lockfile when --refresh is provided (#15991)
#15994
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ use owo_colors::OwoColorize; | |
| use rustc_hash::{FxBuildHasher, FxHashMap}; | ||
| use tracing::debug; | ||
|
|
||
| use uv_cache::Cache; | ||
| use uv_cache::{Cache, Refresh}; | ||
| use uv_client::{BaseClientBuilder, FlatIndexClient, RegistryClientBuilder}; | ||
| use uv_configuration::{ | ||
| Concurrency, Constraints, DependencyGroupsWithDefaults, DryRun, ExtrasSpecification, Reinstall, | ||
|
|
@@ -84,6 +84,7 @@ pub(crate) async fn lock( | |
| locked: bool, | ||
| frozen: bool, | ||
| dry_run: DryRun, | ||
| refresh: Refresh, | ||
| python: Option<String>, | ||
| install_mirrors: PythonInstallMirrors, | ||
| settings: ResolverSettings, | ||
|
|
@@ -201,20 +202,25 @@ pub(crate) async fn lock( | |
| printer, | ||
| preview, | ||
| ) | ||
| .with_refresh(&refresh) | ||
| .execute(target) | ||
| .await | ||
| { | ||
| Ok(lock) => { | ||
| if dry_run.enabled() { | ||
| // In `--dry-run` mode, show all changes. | ||
| let mut changed = false; | ||
| if let LockResult::Changed(previous, lock) = &lock { | ||
| let mut changed = false; | ||
| for event in LockEvent::detect_changes(previous.as_ref(), lock, dry_run) { | ||
| changed = true; | ||
| writeln!(printer.stderr(), "{event}")?; | ||
| } | ||
| } | ||
| if !changed { | ||
|
|
||
| // If we didn't report any version changes, but the lockfile changed, report back. | ||
| if !changed { | ||
| writeln!(printer.stderr(), "{}", "Lockfile changes detected".bold())?; | ||
| } | ||
|
Member
Author
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. I changed this because |
||
| } else { | ||
| writeln!( | ||
| printer.stderr(), | ||
| "{}", | ||
|
|
@@ -260,6 +266,7 @@ pub(super) enum LockMode<'env> { | |
| pub(super) struct LockOperation<'env> { | ||
| mode: LockMode<'env>, | ||
| constraints: Vec<NameRequirementSpecification>, | ||
| refresh: Option<&'env Refresh>, | ||
| settings: &'env ResolverSettings, | ||
| client_builder: &'env BaseClientBuilder<'env>, | ||
| state: &'env UniversalState, | ||
|
|
@@ -288,6 +295,7 @@ impl<'env> LockOperation<'env> { | |
| Self { | ||
| mode, | ||
| constraints: vec![], | ||
| refresh: None, | ||
| settings, | ||
| client_builder, | ||
| state, | ||
|
|
@@ -310,6 +318,13 @@ impl<'env> LockOperation<'env> { | |
| self | ||
| } | ||
|
|
||
| /// Set the refresh strategy for the [`LockOperation`]. | ||
| #[must_use] | ||
| pub(super) fn with_refresh(mut self, refresh: &'env Refresh) -> Self { | ||
| self.refresh = Some(refresh); | ||
| self | ||
| } | ||
|
|
||
| /// Perform a [`LockOperation`]. | ||
| pub(super) async fn execute(self, target: LockTarget<'_>) -> Result<LockResult, ProjectError> { | ||
| match self.mode { | ||
|
|
@@ -334,6 +349,7 @@ impl<'env> LockOperation<'env> { | |
| interpreter, | ||
| Some(existing), | ||
| self.constraints, | ||
| self.refresh, | ||
| self.settings, | ||
| self.client_builder, | ||
| self.state, | ||
|
|
@@ -376,6 +392,7 @@ impl<'env> LockOperation<'env> { | |
| interpreter, | ||
| existing, | ||
| self.constraints, | ||
| self.refresh, | ||
| self.settings, | ||
| self.client_builder, | ||
| self.state, | ||
|
|
@@ -407,6 +424,7 @@ async fn do_lock( | |
| interpreter: &Interpreter, | ||
| existing_lock: Option<Lock>, | ||
| external: Vec<NameRequirementSpecification>, | ||
| refresh: Option<&Refresh>, | ||
| settings: &ResolverSettings, | ||
| client_builder: &BaseClientBuilder<'_>, | ||
| state: &UniversalState, | ||
|
|
@@ -743,6 +761,7 @@ async fn do_lock( | |
| &requires_python, | ||
| index_locations, | ||
| upgrade, | ||
| refresh, | ||
| &options, | ||
| &hasher, | ||
| state.index(), | ||
|
|
@@ -917,7 +936,11 @@ async fn do_lock( | |
| .unwrap_or_default(), | ||
| ); | ||
|
|
||
| Ok(LockResult::Changed(previous, lock)) | ||
| if previous.as_ref().is_some_and(|previous| *previous == lock) { | ||
| Ok(LockResult::Unchanged(lock)) | ||
| } else { | ||
| Ok(LockResult::Changed(previous, lock)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -957,6 +980,7 @@ impl ValidatedLock { | |
| requires_python: &RequiresPython, | ||
| index_locations: &IndexLocations, | ||
| upgrade: &Upgrade, | ||
| refresh: Option<&Refresh>, | ||
| options: &Options, | ||
| hasher: &HashStrategy, | ||
| index: &InMemoryIndex, | ||
|
|
@@ -1142,6 +1166,12 @@ impl ValidatedLock { | |
| return Ok(Self::Versions(lock)); | ||
| } | ||
|
|
||
| // If the user specified `--refresh`, then we have to re-resolve. | ||
| if matches!(refresh, Some(Refresh::All(..) | Refresh::Packages(..))) { | ||
| debug!("Resolving despite existing lockfile due to `--refresh`"); | ||
| return Ok(Self::Preferable(lock)); | ||
| } | ||
|
|
||
| // If the user provided at least one index URL (from the command line, or from a configuration | ||
| // file), don't use the existing lockfile if it references any registries that are no longer | ||
| // included in the current configuration. | ||
|
|
||
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.
I think this is not necessary because we simplify the markers when comparing? I ran through the test cases from the linked PR (https://github.com/astral-sh/uv/pull/13635/files#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957) and they still pass.
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.
\cc @Gankra