-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Treat already-installed base environment packages as preferences in uv run --with
#13284
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
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 |
|---|---|---|
|
|
@@ -35,8 +35,8 @@ use uv_python::{ | |
| use uv_requirements::upgrade::{read_lock_requirements, LockedRequirements}; | ||
| use uv_requirements::{NamedRequirementsResolver, RequirementsSpecification}; | ||
| use uv_resolver::{ | ||
| FlatIndex, Lock, OptionsBuilder, PythonRequirement, RequiresPython, ResolverEnvironment, | ||
| ResolverOutput, | ||
| FlatIndex, Lock, OptionsBuilder, Preference, PythonRequirement, RequiresPython, | ||
| ResolverEnvironment, ResolverOutput, | ||
| }; | ||
| use uv_scripts::Pep723ItemRef; | ||
| use uv_settings::PythonInstallMirrors; | ||
|
|
@@ -1632,27 +1632,42 @@ pub(crate) async fn resolve_names( | |
| Ok(requirements) | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub(crate) enum PreferenceSource<'lock> { | ||
| /// The preferences should be extracted from a lockfile. | ||
| Lock { | ||
| lock: &'lock Lock, | ||
| install_path: &'lock Path, | ||
| }, | ||
| /// The preferences will be provided directly as [`Preference`] entries. | ||
| Entries(Vec<Preference>), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct EnvironmentSpecification<'lock> { | ||
| /// The requirements to include in the environment. | ||
| requirements: RequirementsSpecification, | ||
| /// The lockfile from which to extract preferences, along with the install path. | ||
| lock: Option<(&'lock Lock, &'lock Path)>, | ||
| /// The preferences to respect when resolving. | ||
| preferences: Option<PreferenceSource<'lock>>, | ||
| } | ||
|
|
||
| impl From<RequirementsSpecification> for EnvironmentSpecification<'_> { | ||
| fn from(requirements: RequirementsSpecification) -> Self { | ||
| Self { | ||
| requirements, | ||
| lock: None, | ||
| preferences: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<'lock> EnvironmentSpecification<'lock> { | ||
| /// Set the [`PreferenceSource`] for the specification. | ||
| #[must_use] | ||
| pub(crate) fn with_lock(self, lock: Option<(&'lock Lock, &'lock Path)>) -> Self { | ||
| Self { lock, ..self } | ||
| pub(crate) fn with_preferences(self, preferences: PreferenceSource<'lock>) -> Self { | ||
| Self { | ||
| preferences: Some(preferences), | ||
| ..self | ||
| } | ||
|
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. nit: Should those two be a single method? Otherwise it's hard to spot that one overwrites the other.
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. Good call. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -1765,17 +1780,22 @@ pub(crate) async fn resolve_environment( | |
| let upgrade = Upgrade::default(); | ||
|
|
||
| // If an existing lockfile exists, build up a set of preferences. | ||
| let LockedRequirements { preferences, git } = spec | ||
| .lock | ||
| .map(|(lock, install_path)| read_lock_requirements(lock, install_path, &upgrade)) | ||
| .transpose()? | ||
| .unwrap_or_default(); | ||
|
|
||
| // Populate the Git resolver. | ||
| for ResolvedRepositoryReference { reference, sha } in git { | ||
| debug!("Inserting Git reference into resolver: `{reference:?}` at `{sha}`"); | ||
| state.git().insert(reference, sha); | ||
| } | ||
| let preferences = match spec.preferences { | ||
| Some(PreferenceSource::Lock { lock, install_path }) => { | ||
| let LockedRequirements { preferences, git } = | ||
| read_lock_requirements(lock, install_path, &upgrade)?; | ||
|
|
||
| // Populate the Git resolver. | ||
| for ResolvedRepositoryReference { reference, sha } in git { | ||
| debug!("Inserting Git reference into resolver: `{reference:?}` at `{sha}`"); | ||
| state.git().insert(reference, sha); | ||
| } | ||
|
|
||
| preferences | ||
| } | ||
| Some(PreferenceSource::Entries(entries)) => entries, | ||
| None => vec![], | ||
| }; | ||
|
|
||
| // Resolve the flat indexes from `--find-links`. | ||
| let flat_index = { | ||
|
|
||
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
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.
Note from reviewing: We need this separately from the
InstalledPackagesProviderinCandidateSelectorto have a shared preferences type between preferences from lock and preferences from installed.