Skip to content

Commit

Permalink
Fix support for Pants 2.25.x / Python 3.11 (#426)
Browse files Browse the repository at this point in the history
Fixes #424 

This makes a few adjustments to support running Pants 2.25.0.dev0 and
newer, which run using Python 3.11
(pantsbuild/pants#21528), iterating on #351.
Particularly:

- expanding tools.pex's interpreter constraints to include 3.11 (and
also 3.10, which seems fine)
- add a test (NB. Pants 2.25 cannot run on macOS older than 13 / 14,
depending on platform, so this test is conditional:
pantsbuild/pants#21655)
- hardcoding that 2.25.0.dev0 uses Python 3.11, to use the optimised
"hit the exact URL first time" codepath, instead of having to try all
Python versions:
https://github.com/pantsbuild/scie-pants/blob/d50bd33fd67e944384c9548811a66c1cb03113a5/tools/src/scie_pants/pants_version.py#L239-L252

This thus preps scie-pants release 0.12.1 too, which I'll tag once
merged.
  • Loading branch information
huonw authored Nov 27, 2024
1 parent ca3cc05 commit be453bb
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 0.12.1

Support for Pants 2.25.0.dev0 and newer, which run on Python 3.11 instead of 3.9.

## 0.12.0

Add support for running Pants with newer versions of Python.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
[package]
name = "scie-pants"
description = "Protects your Pants from the elements."
version = "0.12.0"
version = "0.12.1"
edition = "2021"
authors = [
"John Sirois <[email protected]>",
Expand Down
65 changes: 65 additions & 0 deletions package/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ fn decode_output(output: Vec<u8>) -> Result<String> {
String::from_utf8(output).context("Failed to decode Pants output.")
}

/// Returns true if the current platform is a macOS major version that's older than the requested minimums.
///
/// (NB. Running on a non-macOS platform will always return false.)
fn is_macos_thats_too_old(minimum_x86_64: i64, minimum_arm64: i64) -> bool {
let min_major = match *CURRENT_PLATFORM {
Platform::MacOSX86_64 => minimum_x86_64,
Platform::MacOSAarch64 => minimum_arm64,
_ => return false,
};

let version_output = execute(
Command::new("sw_vers")
.arg("-productVersion")
.stdout(Stdio::piped()),
)
.unwrap();
let version_str = decode_output(version_output.stdout).unwrap();

// for this constrained use case, we can just parse the first element, e.g. 10.14 & 10.15 => 10,
// 11.0.1 => 11, etc.
//
// If the distinction between the 10.x "major" versions ends up mattering, feel free to refactor
// this to work with the full version string.
let major: i64 = version_str
.trim()
.split('.')
.next()
.and_then(|s| s.parse().ok())
.unwrap_or_else(|| {
panic!(
"Failed to parse macOS version from `sw_vers -productVersion` output: {}",
version_str
)
});
major < min_major
}

enum ExpectedResult {
Success,
Failure,
Expand Down Expand Up @@ -115,6 +152,7 @@ pub(crate) fn run_integration_tests(
log!(Color::Yellow, "Turning off pantsd for remaining tests.");
env::set_var("PANTS_PANTSD", "False");

test_pants_2_25_using_python_3_11(scie_pants_scie);
test_python_repos_repos(scie_pants_scie);
test_initialize_new_pants_project(scie_pants_scie);
test_set_pants_version(scie_pants_scie);
Expand Down Expand Up @@ -334,6 +372,33 @@ fn test_pants_bootstrap_tools(scie_pants_scie: &Path) {
.unwrap();
}

fn test_pants_2_25_using_python_3_11(scie_pants_scie: &Path) {
integration_test!("Verifying we can run Pants 2.25+, which uses Python 3.11");
// Pants 2.25 is built on macOS 13 (x86-64) and 14 (arm64), and only truly supports those
// versions. See https://github.com/pantsbuild/pants/pull/21655
if is_macos_thats_too_old(13, 14) {
log!(
Color::Yellow,
"Pants 2.25 cannot run on this version of macOS => skipping"
);
return;
}

let pants_version = "2.25.0.dev0";
let output = execute(
Command::new(scie_pants_scie)
.env("PANTS_VERSION", pants_version)
.arg("-V")
.stdout(Stdio::piped()),
)
.unwrap();
let stdout = decode_output(output.stdout).unwrap();
assert!(
stdout.contains(pants_version),
"STDOUT did not contain '{pants_version}':\n{stdout}"
);
}

fn test_python_repos_repos(scie_pants_scie: &Path) {
integration_test!(
"Verifying --python-repos-repos is used prior to Pants 2.13 (no warnings should be \
Expand Down
2 changes: 1 addition & 1 deletion package/src/tools_pex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) fn build_tools_pex(
let requirements = path_as_str(&requirements_path)?;
let test_requirements_path = tools_path.join("test-requirements.txt");
let test_requirements = path_as_str(&test_requirements_path)?;
let interpreter_constraints = ["--interpreter-constraint", "CPython>=3.8,<3.10"];
let interpreter_constraints = ["--interpreter-constraint", "CPython>=3.8,<3.12"];

if update_lock {
build_step!("Updating the scie_jump tools lock file");
Expand Down
2 changes: 1 addition & 1 deletion tools/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"tomlkit"
],
"requires_python": [
"<3.10,>=3.8"
"<3.12,>=3.8"
],
"resolver_version": "pip-2020-resolver",
"style": "universal",
Expand Down
1 change: 1 addition & 0 deletions tools/src/scie_pants/pants_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
PANTS_PYTHON_VERSIONS = [
# Sorted on pants version in descending order. Add a new entry when the python version for a
# particular pants version changes.
{"pants": "2.25.0.dev0", "python": "cp311"},
{"pants": "2.5.0.dev0", "python": "cp39"},
{"pants": "2.0.0.dev0", "python": "cp38"},
]
Expand Down

0 comments on commit be453bb

Please sign in to comment.