Skip to content

Commit 7dd7e79

Browse files
authored
Pass --python-repos-find-links always, and deprecate PANTS_SHA (#250)
Currently, the `scie-pants` launcher sometimes needs to pass an additional argument to the underlying pants invocation, to be able to support `PANTS_SHA` and its custom wheel location. Effectively turning an invocation like `pants goal --arg` into `pants --pants-repos-find-links=+["..."] goal --arg` when appropriate: https://github.com/pantsbuild/scie-pants/blob/0a204c5ac816ad24d74b55ecf7424397a07b3c2a/package/scie-pants.toml#L57-L60 However, when not using `PANTS_SHA`, the pants command becomes `pants "" goal --arg`, and the spurious empty string results in some commands failing, e.g. `pants "" tailor --check` thinks `--check` is a global argument, and this is ambiguous. To fix this issue, this PR does two things: 1. avoid passing an empty string, via a no-op workaround: always set the `PANTS_SHA_FIND_LINKS` variable (to a no-op like `--python-repos-find-links=-[]`), so that scie-pants never passes an empty variable to the pants command, since that makes commands like `pants tailor --check ::` explode: 2. deprecates `PANTS_SHA`, so that the hack above doesn't feel so bad: we're on the way to removing the need for `PANTS_SHA_FIND_LINKS` entirely, thus sidestepping the limitation and the need for the workaround (2) This could also be fixed via a-scie/jump#130. Fixes #249
1 parent 0a204c5 commit 7dd7e79

File tree

6 files changed

+46
-13
lines changed

6 files changed

+46
-13
lines changed

CHANGES.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Release Notes
22

3+
## 0.10.0
4+
5+
This release deprecates support for running against an arbitrary Pants commit using
6+
`PANTS_SHA=abc123... pants ...`. Pants no longer
7+
publishes the artifacts required for this for new commits, and so this is becoming less and less
8+
useful. To replace use of `PANTS_SHA`, do one of:
9+
10+
- Use a released version of Pants.
11+
- Run pants from sources (for example: `PANTS_SOURCE=/path/to/pants-checkout pants ...`).
12+
- If these are not appropriate, [let us know what you're using it for](https://www.pantsbuild.org/docs/getting-help).
13+
14+
15+
This release also fixes scie-pants running commands like `pants tailor --check ...` with Pants
16+
2.18.0.dev5 and newer (releases that use the new "per-platform" PEX).
17+
318
## 0.9.3
419

520
This release propagates the version of the `scie-pants` into the invocation of pants, so that Pants

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

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

src/main.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,27 @@ fn get_pants_process() -> Result<Process> {
173173

174174
let env_pants_sha = env_version("PANTS_SHA")?;
175175
let env_pants_version = env_version("PANTS_VERSION")?;
176-
if let (Some(pants_sha), Some(pants_version)) = (&env_pants_sha, &env_pants_version) {
177-
bail!(
178-
"Both PANTS_SHA={pants_sha} and PANTS_VERSION={pants_version} were set. \
179-
Please choose one.",
180-
)
176+
if let Some(pants_sha) = &env_pants_sha {
177+
// when support for PANTS_SHA is fully removed, PANTS_SHA_FIND_LINKS can be removed too
178+
eprintln!(
179+
"\
180+
DEPRECATED: Support for PANTS_SHA=... will be removed in a future version of the `pants` launcher.
181+
182+
The artifacts for PANTS_SHA are no longer published for new commits. This invocation set PANTS_SHA={pants_sha}.
183+
184+
To resolve, do one of:
185+
- Use a released version of Pants.
186+
- Run pants from sources (for example: `PANTS_SOURCE=/path/to/pants-checkout pants ...`).
187+
- If these are not appropriate, let us know what you're using it for: <https://www.pantsbuild.org/docs/getting-help>.
188+
"
189+
);
190+
191+
if let Some(pants_version) = &env_pants_version {
192+
bail!(
193+
"Both PANTS_SHA={pants_sha} and PANTS_VERSION={pants_version} were set. \
194+
Please choose one.",
195+
)
196+
}
181197
}
182198

183199
let pants_version = if let Some(env_version) = env_pants_version {

tools/src/scie_pants/configure_pants.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def main() -> NoReturn:
125125
with open(env_file, "a") as fp:
126126
if resolve_info.find_links:
127127
print(f"FIND_LINKS={resolve_info.find_links}", file=fp)
128-
print(f"PANTS_SHA_FIND_LINKS={resolve_info.pants_find_links_option(version)}", file=fp)
128+
# This can be removed once we stop supporting PANTS_SHA:
129+
# NB. this is added unconditionally because it gets set as an argument
130+
print(f"PANTS_SHA_FIND_LINKS={resolve_info.pants_find_links_option(version)}", file=fp)
129131
if newly_created_build_root:
130132
print(f"PANTS_BUILDROOT_OVERRIDE={newly_created_build_root}", file=fp)
131133
print(f"PANTS_VERSION={version}", file=fp)

tools/src/scie_pants/pants_version.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ class ResolveInfo:
3838
find_links: str | None
3939

4040
def pants_find_links_option(self, pants_version_selected: Version) -> str:
41-
assert (
42-
self.find_links is not None
43-
), "pants_find_links_option shouldn't be called if find_links is None"
44-
4541
# We only want to add the find-links repo for PANTS_SHA invocations so that plugins can
4642
# resolve Pants the only place it can be found in that case - our ~private
4743
# binaries.pantsbuild.org S3 find-links bucket.
@@ -51,7 +47,11 @@ def pants_find_links_option(self, pants_version_selected: Version) -> str:
5147
if self.stable_version in SpecifierSet("<2.14.0", prereleases=True)
5248
else "find-links"
5349
)
54-
return f"--python-repos-{option_name}={operator}['{self.find_links}']"
50+
value = f"'{self.find_links}'" if self.find_links else ""
51+
52+
# we usually pass a no-op, e.g. --python-repos-find-links=-[], because this is only used for
53+
# PANTS_SHA support that is now deprecated and will be removed
54+
return f"--python-repos-{option_name}={operator}[{value}]"
5555

5656

5757
def determine_find_links(

0 commit comments

Comments
 (0)