fix: add missing requires_python field to top-level PEX lock structure

- Add requires_python field as Vec<String> to PexLock struct
- Populate with lock file's Python version requirement
- Update test to include the new field
- Fixes PEX parser error: "did not have the expected key 'requires_python'"

Aligns with pants-generated PEX lock format which includes this field
at the root level.

🤖 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:52:37 +00:00
parent a884d5e84f
commit d8cdb7c199

View file

@ -50,6 +50,8 @@ pub struct PexLock {
pub prefer_older_binary: bool,
/// Direct requirements.
pub requirements: Vec<String>,
/// Python version requirements.
pub requires_python: Vec<String>,
/// The resolver version used.
pub resolver_version: String,
/// The style of resolution.
@ -247,6 +249,7 @@ impl PexLock {
pip_version: Self::DEFAULT_PIP_VERSION.to_string(),
prefer_older_binary: false,
requirements,
requires_python: vec![lock.requires_python().to_string()],
resolver_version: "pip-2020-resolver".to_string(),
style: "universal".to_string(),
target_systems: vec!["linux".to_string(), "mac".to_string()],
@ -294,6 +297,7 @@ mod tests {
pip_version: PexLock::DEFAULT_PIP_VERSION.to_string(),
prefer_older_binary: false,
requirements: vec!["requests==2.31.0".to_string()],
requires_python: vec![">=3.8".to_string()],
resolver_version: "pip-2020-resolver".to_string(),
style: "universal".to_string(),
target_systems: vec!["linux".to_string(), "mac".to_string()],