-
Notifications
You must be signed in to change notification settings - Fork 409
fix: always add git requirement to the lockfile #5187
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,10 @@ use pixi_record::{LockedGitUrl, PixiRecord}; | |
| use pixi_reporters::{UvReporter, UvReporterOptions}; | ||
| use pixi_uv_conversions::{ | ||
| ConversionError, as_uv_req, configure_insecure_hosts_for_tls_bypass, | ||
| convert_uv_requirements_to_pep508, into_pinned_git_spec, pypi_options_to_build_options, | ||
| pypi_options_to_index_locations, to_exclude_newer, to_index_strategy, to_normalize, | ||
| to_prerelease_mode, to_requirements, to_uv_normalize, to_uv_version, to_version_specifiers, | ||
| convert_uv_requirements_to_pep508, into_pinned_git_spec, into_pixi_reference, | ||
| pypi_options_to_build_options, pypi_options_to_index_locations, to_exclude_newer, | ||
| to_index_strategy, to_normalize, to_prerelease_mode, to_requirements, to_uv_normalize, | ||
| to_uv_version, to_version_specifiers, | ||
| }; | ||
| use pypi_modifiers::{ | ||
| pypi_marker_env::determine_marker_environment, | ||
|
|
@@ -48,8 +49,8 @@ use uv_configuration::{Constraints, Overrides}; | |
| use uv_distribution::DistributionDatabase; | ||
| use uv_distribution_types::{ | ||
| BuiltDist, ConfigSettings, DependencyMetadata, Diagnostic, Dist, FileLocation, HashPolicy, | ||
| IndexCapabilities, IndexUrl, Name, RequirementSource, RequiresPython, Resolution, ResolvedDist, | ||
| SourceDist, ToUrlError, | ||
| IndexCapabilities, IndexUrl, Name, Requirement, RequirementSource, RequiresPython, Resolution, | ||
| ResolvedDist, SourceDist, ToUrlError, | ||
| }; | ||
| use uv_git_types::GitUrl; | ||
| use uv_pep508::VerbatimUrl; | ||
|
|
@@ -355,6 +356,10 @@ pub async fn resolve_pypi( | |
| .collect::<Result<Vec<_>, _>>() | ||
| .into_diagnostic()?; | ||
|
|
||
| // Clone requirements for later use in lock file generation | ||
| // We need this because requirements will be moved into the resolver | ||
| let requirements_for_locking = requirements.clone(); | ||
|
|
||
| // Determine the python interpreter that is installed as part of the conda | ||
| // packages. | ||
| let python_record = locked_pixi_records | ||
|
|
@@ -629,6 +634,8 @@ pub async fn resolve_pypi( | |
| let git_oid = | ||
| uv_git_types::GitOid::from_str(&pinned_git_spec.source.commit.to_string())?; | ||
|
|
||
| // Construct the GitUrl with the reference (branch/tag) from the pinned_git_spec | ||
| // to preserve the branch information in the lock file | ||
| let git_url = GitUrl::try_from(display_safe)?.with_precise(git_oid); | ||
|
|
||
| let constraint_source = RequirementSource::Git { | ||
|
|
@@ -821,6 +828,7 @@ pub async fn resolve_pypi( | |
| &context.capabilities, | ||
| context.concurrency.downloads, | ||
| project_root, | ||
| &requirements_for_locking, | ||
| ) | ||
| .await?; | ||
|
|
||
|
|
@@ -943,6 +951,7 @@ fn get_url_or_path( | |
| } | ||
|
|
||
| /// Create a vector of locked packages from a resolution | ||
| #[allow(clippy::too_many_arguments)] | ||
| async fn lock_pypi_packages( | ||
| conda_python_packages: CondaPythonPackages, | ||
| pixi_build_dispatch: &LazyBuildDispatch<'_>, | ||
|
|
@@ -951,6 +960,7 @@ async fn lock_pypi_packages( | |
| index_capabilities: &IndexCapabilities, | ||
| concurrent_downloads: usize, | ||
| abs_project_root: &Path, | ||
| original_requirements: &[Requirement], | ||
| ) -> miette::Result<Vec<(PypiPackageData, PypiPackageEnvironmentData)>> { | ||
| let mut locked_packages = LockedPypiPackages::with_capacity(resolution.len()); | ||
| let database = | ||
|
|
@@ -1071,7 +1081,22 @@ async fn lock_pypi_packages( | |
| } | ||
| SourceDist::Git(git) => { | ||
| // convert resolved source dist into a pinned git spec | ||
| let pinned_git_spec = into_pinned_git_spec(git.clone()); | ||
| let mut pinned_git_spec = into_pinned_git_spec(git.clone()); | ||
|
|
||
| // Look up the original requirement to get the git reference (branch/tag) | ||
| // It may have resolved the reference to just a commit, losing the branch/tag info | ||
| if let Some(original_req) = original_requirements | ||
| .iter() | ||
| .find(|r| &r.name == dist.name()) | ||
| && let RequirementSource::Git { | ||
| git: original_git, .. | ||
| } = &original_req.source | ||
| { | ||
| // Use the reference from the original requirement instead of what UV resolved | ||
| pinned_git_spec.source.reference = | ||
| into_pixi_reference(original_git.reference().clone()); | ||
|
Contributor
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. This pushes in the actual requirement, is this right? It feels strange that that information is not in the resolved spec. |
||
| } | ||
|
|
||
| ( | ||
| pinned_git_spec.into_locked_git_url().to_url().into(), | ||
| hash, | ||
|
|
||
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.
Do you always want to override the reference? It may be that the reference is already set, maybe we can skip in this case, searching through the original requirements?
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 don't see how to fix this. The reference is default branch but there must be multiple code paths as it sometimes is written without and sometimes with the reference in the url.