fix: exclude packages without artifacts from PEX lock file

- Add validation to only include packages with at least one artifact
- Skip packages that have no downloadable wheels or source distributions
- Prevents PEX parser error: "expected to have at least one artifact"

This ensures all locked requirements have valid downloadable artifacts
as required by the PEX specification.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alessandro De Maria 2025-07-05 23:34:50 +00:00
parent f0a5b64b33
commit a884d5e84f

View file

@ -199,26 +199,29 @@ impl PexLock {
} }
if let Some(version) = &package.id.version { if let Some(version) = &package.id.version {
// Collect dependencies for this package // Only include packages that have at least one artifact
let mut requires_dists = Vec::new(); if !artifacts.is_empty() {
for dep in &package.dependencies { // Collect dependencies for this package
if let Some(dep_version) = lock let mut requires_dists = Vec::new();
.packages() for dep in &package.dependencies {
.iter() if let Some(dep_version) = lock
.find(|pkg| pkg.id.name == dep.package_id.name) .packages()
.and_then(|pkg| pkg.id.version.as_ref()) .iter()
{ .find(|pkg| pkg.id.name == dep.package_id.name)
requires_dists.push(format!("{}=={}", dep.package_id.name, dep_version)); .and_then(|pkg| pkg.id.version.as_ref())
{
requires_dists.push(format!("{}=={}", dep.package_id.name, dep_version));
}
} }
}
locked_requirements.push(PexLockedRequirement { locked_requirements.push(PexLockedRequirement {
artifacts, artifacts,
project_name: package.id.name.to_string(), project_name: package.id.name.to_string(),
requires_dists, requires_dists,
requires_python: lock.requires_python().to_string(), requires_python: lock.requires_python().to_string(),
version: version.to_string(), version: version.to_string(),
}); });
}
} }
} }