Skip to content

Commit e405f21

Browse files
authored
fix: align --locked metadata serializer with lock-write side (#6115)
1 parent 2f345b3 commit e405f21

2 files changed

Lines changed: 44 additions & 17 deletions

File tree

crates/pixi_core/src/lock_file/satisfiability/pypi.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use pixi_spec::Subdirectory;
2020
use pixi_uv_context::UvResolutionContext;
2121
use pixi_uv_conversions::{
2222
configure_insecure_hosts_for_tls_bypass, into_pixi_reference, pypi_options_to_build_options,
23-
pypi_options_to_index_locations, to_index_strategy,
23+
pypi_options_to_index_locations, to_index_strategy, to_requirements,
2424
};
2525
use pypi_modifiers::pypi_marker_env::determine_marker_environment;
2626
use pypi_modifiers::pypi_tags::{get_pypi_tags, is_python_record};
@@ -752,22 +752,16 @@ async fn read_local_package_metadata(
752752
}
753753
};
754754

755-
// A round-trip failure here would be a uv bug, not "static doesn't
756-
// apply", so propagate rather than swallow as `Ok(None)`.
757-
let requires_dist_vec: Vec<pep508_rs::Requirement> = requires_dist
758-
.requires_dist
759-
.iter()
760-
.map(|req| {
761-
req.to_string()
762-
.parse::<pep508_rs::Requirement>()
763-
.map_err(|e| {
764-
PlatformUnsat::FailedToReadLocalMetadata(
765-
package_name.clone(),
766-
format!("Invalid requirement: {e}"),
767-
)
768-
})
769-
})
770-
.collect::<Result<_, _>>()?;
755+
// Match the lockfile-write serializer so both sides of
756+
// `compare_metadata` agree on `[tool.uv.sources]` requirements
757+
// (#6049 follow-up).
758+
let requires_dist_vec: Vec<pep508_rs::Requirement> =
759+
to_requirements(requires_dist.requires_dist.iter()).map_err(|e| {
760+
PlatformUnsat::FailedToReadLocalMetadata(
761+
package_name.clone(),
762+
format!("Invalid requirement: {e}"),
763+
)
764+
})?;
771765

772766
let metadata = pypi_metadata::LocalPackageMetadata {
773767
version,

crates/pixi_uv_conversions/src/conversions.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,4 +839,37 @@ mod tests {
839839
other => panic!("expected a VersionOrUrl::Url, got {other:?}"),
840840
}
841841
}
842+
843+
/// Index-bearing registry sources must serialize without uv's
844+
/// `(index: <url>)` `Display` suffix; `pep508_rs` rejects it (#6049).
845+
#[test]
846+
fn to_requirements_strips_index_suffix_from_registry_source() {
847+
use std::sync::Arc;
848+
use uv_distribution_types::{
849+
IndexFormat, IndexMetadata, IndexUrl, Requirement as UvRequirement, RequirementSource,
850+
};
851+
use uv_pep508::MarkerTree;
852+
853+
let uv_req = UvRequirement {
854+
name: uv_normalize::PackageName::from_str("isaaclab").unwrap(),
855+
extras: Box::new([]),
856+
groups: Box::new([]),
857+
marker: MarkerTree::TRUE,
858+
source: RequirementSource::Registry {
859+
specifier: uv_pep440::VersionSpecifiers::empty(),
860+
index: Some(IndexMetadata {
861+
url: IndexUrl::Url(Arc::new(uv_pep508::VerbatimUrl::from_url(
862+
DisplaySafeUrl::parse("https://pypi.nvidia.com/simple/").unwrap(),
863+
))),
864+
format: IndexFormat::Simple,
865+
}),
866+
conflict: None,
867+
},
868+
origin: None,
869+
};
870+
assert!(uv_req.to_string().contains("(index:"));
871+
872+
let converted = to_requirements(std::iter::once(&uv_req)).unwrap();
873+
assert_eq!(converted[0].to_string(), "isaaclab");
874+
}
842875
}

0 commit comments

Comments
 (0)