Skip to content

Commit be453bb

Browse files
authored
Fix support for Pants 2.25.x / Python 3.11 (#426)
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.
1 parent ca3cc05 commit be453bb

File tree

7 files changed

+74
-4
lines changed

7 files changed

+74
-4
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 0.12.1
4+
5+
Support for Pants 2.25.0.dev0 and newer, which run on Python 3.11 instead of 3.9.
6+
37
## 0.12.0
48

59
Add support for running Pants with newer versions of Python.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
[package]
77
name = "scie-pants"
88
description = "Protects your Pants from the elements."
9-
version = "0.12.0"
9+
version = "0.12.1"
1010
edition = "2021"
1111
authors = [
1212
"John Sirois <[email protected]>",

package/src/test.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ fn decode_output(output: Vec<u8>) -> Result<String> {
4646
String::from_utf8(output).context("Failed to decode Pants output.")
4747
}
4848

49+
/// Returns true if the current platform is a macOS major version that's older than the requested minimums.
50+
///
51+
/// (NB. Running on a non-macOS platform will always return false.)
52+
fn is_macos_thats_too_old(minimum_x86_64: i64, minimum_arm64: i64) -> bool {
53+
let min_major = match *CURRENT_PLATFORM {
54+
Platform::MacOSX86_64 => minimum_x86_64,
55+
Platform::MacOSAarch64 => minimum_arm64,
56+
_ => return false,
57+
};
58+
59+
let version_output = execute(
60+
Command::new("sw_vers")
61+
.arg("-productVersion")
62+
.stdout(Stdio::piped()),
63+
)
64+
.unwrap();
65+
let version_str = decode_output(version_output.stdout).unwrap();
66+
67+
// for this constrained use case, we can just parse the first element, e.g. 10.14 & 10.15 => 10,
68+
// 11.0.1 => 11, etc.
69+
//
70+
// If the distinction between the 10.x "major" versions ends up mattering, feel free to refactor
71+
// this to work with the full version string.
72+
let major: i64 = version_str
73+
.trim()
74+
.split('.')
75+
.next()
76+
.and_then(|s| s.parse().ok())
77+
.unwrap_or_else(|| {
78+
panic!(
79+
"Failed to parse macOS version from `sw_vers -productVersion` output: {}",
80+
version_str
81+
)
82+
});
83+
major < min_major
84+
}
85+
4986
enum ExpectedResult {
5087
Success,
5188
Failure,
@@ -115,6 +152,7 @@ pub(crate) fn run_integration_tests(
115152
log!(Color::Yellow, "Turning off pantsd for remaining tests.");
116153
env::set_var("PANTS_PANTSD", "False");
117154

155+
test_pants_2_25_using_python_3_11(scie_pants_scie);
118156
test_python_repos_repos(scie_pants_scie);
119157
test_initialize_new_pants_project(scie_pants_scie);
120158
test_set_pants_version(scie_pants_scie);
@@ -334,6 +372,33 @@ fn test_pants_bootstrap_tools(scie_pants_scie: &Path) {
334372
.unwrap();
335373
}
336374

375+
fn test_pants_2_25_using_python_3_11(scie_pants_scie: &Path) {
376+
integration_test!("Verifying we can run Pants 2.25+, which uses Python 3.11");
377+
// Pants 2.25 is built on macOS 13 (x86-64) and 14 (arm64), and only truly supports those
378+
// versions. See https://github.com/pantsbuild/pants/pull/21655
379+
if is_macos_thats_too_old(13, 14) {
380+
log!(
381+
Color::Yellow,
382+
"Pants 2.25 cannot run on this version of macOS => skipping"
383+
);
384+
return;
385+
}
386+
387+
let pants_version = "2.25.0.dev0";
388+
let output = execute(
389+
Command::new(scie_pants_scie)
390+
.env("PANTS_VERSION", pants_version)
391+
.arg("-V")
392+
.stdout(Stdio::piped()),
393+
)
394+
.unwrap();
395+
let stdout = decode_output(output.stdout).unwrap();
396+
assert!(
397+
stdout.contains(pants_version),
398+
"STDOUT did not contain '{pants_version}':\n{stdout}"
399+
);
400+
}
401+
337402
fn test_python_repos_repos(scie_pants_scie: &Path) {
338403
integration_test!(
339404
"Verifying --python-repos-repos is used prior to Pants 2.13 (no warnings should be \

package/src/tools_pex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) fn build_tools_pex(
4545
let requirements = path_as_str(&requirements_path)?;
4646
let test_requirements_path = tools_path.join("test-requirements.txt");
4747
let test_requirements = path_as_str(&test_requirements_path)?;
48-
let interpreter_constraints = ["--interpreter-constraint", "CPython>=3.8,<3.10"];
48+
let interpreter_constraints = ["--interpreter-constraint", "CPython>=3.8,<3.12"];
4949

5050
if update_lock {
5151
build_step!("Updating the scie_jump tools lock file");

tools/lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
"tomlkit"
242242
],
243243
"requires_python": [
244-
"<3.10,>=3.8"
244+
"<3.12,>=3.8"
245245
],
246246
"resolver_version": "pip-2020-resolver",
247247
"style": "universal",

tools/src/scie_pants/pants_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
PANTS_PYTHON_VERSIONS = [
2828
# Sorted on pants version in descending order. Add a new entry when the python version for a
2929
# particular pants version changes.
30+
{"pants": "2.25.0.dev0", "python": "cp311"},
3031
{"pants": "2.5.0.dev0", "python": "cp39"},
3132
{"pants": "2.0.0.dev0", "python": "cp38"},
3233
]

0 commit comments

Comments
 (0)