Skip to content

Commit 89981cd

Browse files
kaoshuonw
andauthored
Prep support for running Pants with Python 3.10 or 3.11. (#351)
~Look at the Python tag in the Pants PEX filename~ Cycle through all supported Python versions and check the PEX download URL using HEAD for each one to infer the Python version to use when installing Pants, when using a version of Pants that we don't already know which version of Python to use. ~Drop support for `PANTS_SHA`.~ Done in #376. ~Silence the install step, capturing the output to a `pants-install.log` file in the science cache.~ Done in #375. --------- Co-authored-by: Huon Wilson <[email protected]>
1 parent bdf97a9 commit 89981cd

File tree

13 files changed

+248
-382
lines changed

13 files changed

+248
-382
lines changed

.github/workflows/release.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ on:
66
workflow_dispatch:
77
inputs:
88
tag:
9-
description: The tag to manually run a deploy for.
9+
description: The tag to manually run a deploy for. (example tag `v1.2.3`)
10+
required: true
11+
prerelease:
12+
description: |
13+
Is this for a prerelease?
14+
(for internal testing, not announced nor published to our brew tap)
15+
(example tag `v1.2.3-beta.0`)
16+
type: boolean
17+
default: false
1018
required: true
1119
env:
1220
CARGO_TERM_COLOR: always
@@ -25,20 +33,24 @@ jobs:
2533
outputs:
2634
release-tag: ${{ steps.determine-tag.outputs.release-tag }}
2735
release-version: ${{ steps.determine-tag.outputs.release-version }}
36+
prerelease: ${{ steps.determine-tag.outputs.prerelease }}
2837
steps:
2938
- name: Determine Tag
3039
id: determine-tag
3140
run: |
3241
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
3342
RELEASE_TAG=${{ github.event.inputs.tag }}
43+
PRERELEASE=${{ github.event.inputs.prerelease }}
3444
else
3545
RELEASE_TAG=${GITHUB_REF#refs/tags/}
46+
PRERELEASE=false
3647
fi
37-
if [[ "${RELEASE_TAG}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]]; then
48+
if [[ "${RELEASE_TAG}" =~ ^v[0-9]+.[0-9]+.[0-9]+$ ]] || [[ "${PRERELEASE}" == true ]]; then
3849
echo "release-tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
3950
echo "release-version=${RELEASE_TAG#v}" >> $GITHUB_OUTPUT
51+
echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT
4052
else
41-
echo "::error::Release tag '${RELEASE_TAG}' must match 'v\d+.\d+.\d+'."
53+
echo "::error::Release tag '${RELEASE_TAG}' must match 'v\d+.\d+.\d+' when not doing a pre-release."
4254
exit 1
4355
fi
4456
github-release:
@@ -87,7 +99,7 @@ jobs:
8799
name: scie-pants ${{ needs.determine-tag.outputs.release-version }}
88100
body_path: ${{ steps.prepare-changelog.outputs.changelog-file }}
89101
draft: false
90-
prerelease: false
102+
prerelease: ${{ needs.determine-tag.outputs.prerelease }}
91103
files: dist/scie-pants-*
92104
fail_on_unmatched_files: true
93105
discussion_category_name: Announcements
@@ -113,6 +125,7 @@ jobs:
113125
runs-on: ubuntu-22.04
114126
steps:
115127
- name: Post Release Announcement to Pants Slack `#announce`
128+
if: ${{ needs.determine-tag.outputs.prerelease != 'true' }}
116129
id: slack
117130
uses: slackapi/[email protected]
118131
with:
@@ -148,6 +161,7 @@ jobs:
148161
runs-on: ubuntu-22.04
149162
steps:
150163
- name: Bump `scie-pants` version in Casks/pants.rb to ${{ needs.determine-tag.outputs.release-tag }}
164+
if: ${{ needs.determine-tag.outputs.prerelease != 'true' }}
151165
uses: actions/github-script@v6
152166
with:
153167
github-token: ${{ secrets.TAP_TOKEN }}

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.0
4+
5+
Add support for running Pants with newer versions of Python.
6+
37
## 0.11.0
48

59
Drop support for `PANTS_SHA` which was deprecated in `0.10.0`.

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.11.0"
9+
version = "0.12.0"
1010
edition = "2021"
1111
authors = [
1212
"John Sirois <[email protected]>",

package/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ In the course of development you'll probably only be interested in two invocatio
4242
The primary goal of the package crate as build system is to support development of the `scie-pants`
4343
binary with an install of Rust as the ~only requirement (CMake is currently needed as well). This
4444
necessitates dogfooding the same scie mechanism the final `scie-pants` binary uses in production in
45-
order to bootstrap a [Python tool chain](pbt.lift.json). This is used build the [`tools.pex`](
45+
order to bootstrap a [Python tool chain](pbt.toml). This is used to build the [`tools.pex`](
4646
../tools/README.md) embedded in the final `scie-pants` for use in all the slow-path / high-logic
4747
steps like Pants configuration, Pants installation and self-update.
4848

@@ -53,9 +53,9 @@ src/main.rs):
5353
1. A [`ptex` binary](https://github.com/a-scie/ptex) is built via `cargo install`. This bootstraps
5454
the ability to fetch further requirements.
5555
2. The current production pins of `ptex` and `scie-jump` are fetched and checksum-verified.
56-
3. A [`pbt`](pbt.lift.json) scie binary is built to facilitate running Python, Pip and Pex tools.
56+
3. A [`pbt`](pbt.toml) scie binary is built to facilitate running Python, Pip and Pex tools.
5757
4. The [tools.pex](../tools) is built.
58-
5. The `scie-pants` scie binary is built.
58+
5. The [`scie-pants`](scie-pants.toml) scie binary is built.
5959
6. The `scie-pants` binary is used to run Pants against the Python tools codebase and then to run a
6060
series of integration tests exercising the ability to install different Pants vintages and
6161
configure new Pants projects.

package/scie-pants.toml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,28 @@ release = "20240107"
2828
lazy = true
2929
version = "3.9.18"
3030

31+
[[lift.interpreters]]
32+
id = "cpython310"
33+
provider = "PythonBuildStandalone"
34+
release = "20240415"
35+
lazy = true
36+
version = "3.10.14"
37+
38+
[[lift.interpreters]]
39+
id = "cpython311"
40+
provider = "PythonBuildStandalone"
41+
release = "20240415"
42+
lazy = true
43+
version = "3.11.9"
44+
3145
[[lift.interpreter_groups]]
3246
id = "cpython"
3347
selector = "{scie.bindings.configure:PYTHON}"
3448
members = [
3549
"cpython38",
3650
"cpython39",
51+
"cpython310",
52+
"cpython311",
3753
]
3854

3955
[[lift.files]]
@@ -183,6 +199,8 @@ args = [
183199
"{scie.env.PANTS_TOML}",
184200
"--github-api-bearer-token",
185201
"{scie.env.PANTS_BOOTSTRAP_GITHUB_API_BEARER_TOKEN}",
202+
"--pants-bootstrap-urls",
203+
"{scie.env.PANTS_BOOTSTRAP_URLS}",
186204
"{scie.bindings}",
187205
]
188206
env.remove_re = [
@@ -209,14 +227,14 @@ args = [
209227
"install-pants",
210228
"--pants-version",
211229
"{scie.bindings.configure:PANTS_VERSION}",
230+
"--pants-pex-url",
231+
"{scie.bindings.configure:PANTS_PEX_URL}",
212232
"--find-links",
213233
"{scie.bindings.configure:FIND_LINKS}",
214234
"--debug",
215235
"{scie.env.PANTS_DEBUG}",
216236
"--debugpy-requirement",
217237
"{scie.env.PANTS_DEBUGPY_VERSION}",
218-
"--pants-bootstrap-urls",
219-
"{scie.env.PANTS_BOOTSTRAP_URLS}",
220238
"--ptex-path",
221239
"{ptex}",
222240
"{scie.bindings}",

package/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::utils::fs::{base_name, canonicalize, copy, ensure_directory};
2929

3030
const BINARY: &str = "scie-pants";
3131

32+
// The version of a-scie/lift to use by default.
3233
const SCIENCE_TAG: &str = "v0.3.1";
3334

3435
#[derive(Clone)]
@@ -127,7 +128,7 @@ struct Args {
127128
long,
128129
help = format!(
129130
"Instead of using the released {SCIENCE_TAG} science, package science from the science \
130-
project repo at this directory."
131+
project repo (github.com/a-scie/lift) at this directory."
131132
)
132133
)]
133134
science: Option<PathBuf>,

package/src/test.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn test_pants_from_bad_pex_version(scie_pants_scie: &Path) {
440440

441441
let tmpdir = create_tempdir().unwrap();
442442

443-
let pants_release = "2.18";
443+
let pants_release = "2.19";
444444
let pants_toml_content = format!(
445445
r#"
446446
[GLOBAL]
@@ -459,8 +459,11 @@ fn test_pants_from_bad_pex_version(scie_pants_scie: &Path) {
459459
.unwrap_err();
460460

461461
let error_text = err.to_string();
462-
assert!(error_text.contains("Wasn't able to fetch the Pants PEX at"));
463-
assert!(error_text.contains("Pants version format not recognized. Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`"));
462+
assert!(error_text
463+
.contains("Pants version must be a full version, including patch level, got: `2.19`."));
464+
assert!(error_text.contains(
465+
"Please add `.<patch_version>` to the end of the version. For example: `2.18` -> `2.18.0`."
466+
));
464467
}
465468

466469
fn test_use_in_repo_with_pants_script(scie_pants_scie: &Path, clone_root: &TempDir) {
@@ -1201,7 +1204,10 @@ fn test_pants_bootstrap_urls(scie_pants_scie: &Path) {
12011204

12021205
assert_stderr_output(
12031206
&mut command,
1204-
vec![&format!("Failed to fetch {doesnt_exist_pex_url}")],
1207+
vec![
1208+
&format!("Failed to determine release URL for Pants: {pants_release}: pants.{pants_release}-cp3"),
1209+
&format!(".pex: URL check failed, from PANTS_BOOTSTRAP_URLS: {doesnt_exist_pex_url}: <urlopen error [Errno 2] No such file or directory: "),
1210+
],
12051211
ExpectedResult::Failure,
12061212
);
12071213

tools/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ quickly.
2828
One is the ability to fetch binaries check-summed in advance just in time and exactly once.
2929
It does this with a `"ptex"` configuration described [here](
3030
https://github.com/a-scie/ptex/blob/main/README.md#how-ptex-works) and employed in both the [`pbt`](
31-
../package/pbt.lift.json) binary and the [`scie-jump`](../package/scie-pants.lift.json) itself. This
31+
../package/pbt.toml) binary and the [`scie-pants`](../package/scie-pants.toml) itself. This
3232
allows the `scie-pants` to ship as a small binary that lazily fetches a Python distribution to run
3333
the tools with / install Pants with. This also gives Python tools code access to a `ptex` binary
3434
to use when fetching content from the internet. Although the Python code can always reach out to
@@ -39,9 +39,9 @@ The other useful feature of a scie is the ability to run pre-requisite binding c
3939
steps needed to support user-facing commands. These commands will only ever run once and they can
4040
record result information in the form of `<key>=<value>` pairs for future invocations to learn the
4141
one-time binding results. The `"pants"` command in the `scie-pants` binary depends on an `install`
42-
binding to learn the Path of the Pants venv and that in turn depends on a `configuration` binding
43-
to learn the Pants version to install and the find-links repo needed to support that install. In
44-
turn, both of these bindings depend on Python distributions fetched by the `ptex` fetch mechanism.
42+
binding to learn the Path of the Pants venv and that in turn depends on a `configuration` binding to
43+
learn the Pants version to install. In turn, both of these bindings depend on Python distributions
44+
fetched by the `ptex` fetch mechanism.
4545

4646
All such dependencies are expressed with `{scie.*}` placeholders in the values of command `"exe"`,
4747
`"args"` and `"env"` values in the scie lift manifest. To follow the flow of a top-level command,
@@ -67,4 +67,4 @@ python {tools.pex} <console script name> <arguments> ...
6767
Tools may have all of their arguments defined in the lift manifest, or they may take additional
6868
arguments from the user. If they take additional arguments, it's a good idea to suppress displaying
6969
help for the arguments defined in the lift manifest since the user can not change those and should
70-
probably not be concerned with their (hidden) existence.
70+
probably not be concerned with their (hidden) existence.

tools/src/scie_pants/configure_pants.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def main() -> NoReturn:
6363
parser.add_argument(
6464
"--github-api-bearer-token", help="The GITHUB_TOKEN to use if running in CI context."
6565
)
66+
parser.add_argument(
67+
"--pants-bootstrap-urls",
68+
type=str,
69+
help="The path to the JSON file containing alternate URLs for downloaded artifacts.",
70+
)
6671
parser.add_argument("base_dir", nargs=1, help="The base directory to create Pants venvs in.")
6772
options = parser.parse_args()
6873

@@ -86,8 +91,8 @@ def main() -> NoReturn:
8691
pants_version=options.pants_version,
8792
find_links_dir=find_links_dir,
8893
github_api_bearer_token=options.github_api_bearer_token,
94+
bootstrap_urls_path=options.pants_bootstrap_urls,
8995
)
90-
version = resolve_info.stable_version
9196
else:
9297
if pants_config:
9398
if not prompt_for_pants_version(options.pants_config):
@@ -104,23 +109,22 @@ def main() -> NoReturn:
104109
pants_config=pants_config,
105110
find_links_dir=find_links_dir,
106111
github_api_bearer_token=options.github_api_bearer_token,
112+
bootstrap_urls_path=options.pants_bootstrap_urls,
107113
)
108114
finalizers.append(configure_version)
109-
version = resolve_info.stable_version
110-
111-
# N.B.: These values must match the lift TOML interpreter ids.
112-
python = "cpython38" if version < Version("2.5") else "cpython39"
113115

114116
for finalizer in finalizers:
115117
finalizer()
116118

117119
with open(env_file, "a") as fp:
120+
print(f"PANTS_VERSION={resolve_info.version}", file=fp)
121+
print(f"PYTHON={resolve_info.python}", file=fp)
122+
if resolve_info.pex_url:
123+
print(f"PANTS_PEX_URL={resolve_info.pex_url}", file=fp)
118124
if resolve_info.find_links:
119125
print(f"FIND_LINKS={resolve_info.find_links}", file=fp)
120126
if newly_created_build_root:
121127
print(f"PANTS_BUILDROOT_OVERRIDE={newly_created_build_root}", file=fp)
122-
print(f"PANTS_VERSION={version}", file=fp)
123-
print(f"PYTHON={python}", file=fp)
124128

125129
sys.exit(0)
126130

0 commit comments

Comments
 (0)