Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/scie-pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ args = [
"--github-api-bearer-token",
"{scie.env.PANTS_BOOTSTRAP_GITHUB_API_BEARER_TOKEN}",
"--pants-bootstrap-urls",
"{scie.lift}",
"--pants-bootstrap-urls",
"{scie.env.PANTS_BOOTSTRAP_URLS}",
"{scie.bindings}",
]
Expand Down
6 changes: 3 additions & 3 deletions tools/src/scie_pants/configure_pants.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main() -> NoReturn:
)
parser.add_argument(
"--pants-bootstrap-urls",
type=str,
action="append",
help="The path to the JSON file containing alternate URLs for downloaded artifacts.",
)
parser.add_argument("base_dir", nargs=1, help="The base directory to create Pants venvs in.")
Expand All @@ -91,7 +91,7 @@ def main() -> NoReturn:
pants_version=options.pants_version,
find_links_dir=find_links_dir,
github_api_bearer_token=options.github_api_bearer_token,
bootstrap_urls_path=options.pants_bootstrap_urls,
bootstrap_urls_paths=options.pants_bootstrap_urls,
)
else:
if pants_config:
Expand All @@ -109,7 +109,7 @@ def main() -> NoReturn:
pants_config=pants_config,
find_links_dir=find_links_dir,
github_api_bearer_token=options.github_api_bearer_token,
bootstrap_urls_path=options.pants_bootstrap_urls,
bootstrap_urls_paths=tuple(options.pants_bootstrap_urls),
)
finalizers.append(configure_version)

Expand Down
52 changes: 33 additions & 19 deletions tools/src/scie_pants/pants_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import urllib.parse
import urllib.request
from collections.abc import Iterable
from dataclasses import dataclass
from pathlib import Path
from subprocess import CalledProcessError
Expand Down Expand Up @@ -90,7 +91,7 @@ def determine_tag_version(
pants_version: str,
find_links_dir: Path,
github_api_bearer_token: str | None,
bootstrap_urls_path: str | None,
bootstrap_urls_paths: Iterable[str],
) -> ResolveInfo:
version = Version(pants_version)
if version.base_version.count(".") < 2:
Expand All @@ -101,7 +102,7 @@ def determine_tag_version(
)

if version >= PANTS_PEX_GITHUB_RELEASE_VERSION:
pex_url, python = determine_pex_url_and_python_id(ptex, version, bootstrap_urls_path)
pex_url, python = determine_pex_url_and_python_id(ptex, version, bootstrap_urls_paths)
return ResolveInfo(version=version, python=python, pex_url=pex_url)

tag = f"release_{pants_version}"
Expand Down Expand Up @@ -157,7 +158,7 @@ def determine_latest_stable_version(
pants_config: Path,
find_links_dir: Path,
github_api_bearer_token: str | None,
bootstrap_urls_path: str | None,
bootstrap_urls_paths: Iterable[str],
) -> tuple[Callable[[], None], ResolveInfo]:
info(f"Fetching latest stable Pants version since none is configured")

Expand Down Expand Up @@ -197,48 +198,61 @@ def configure_version():
pants_config.write_text(tomlkit.dumps(config))

return configure_version, determine_tag_version(
ptex, pants_version, find_links_dir, github_api_bearer_token, bootstrap_urls_path
ptex, pants_version, find_links_dir, github_api_bearer_token, bootstrap_urls_paths
)


def determine_pex_url_and_python_id(
ptex: Ptex,
version: Version,
bootstrap_urls_path: str | None,
bootstrap_urls_paths: Iterable[str],
) -> tuple[str, str]:
uname = os.uname()
platform = f"{uname.sysname.lower()}_{uname.machine.lower()}"
pex_url, python = get_pex_url_and_python_id(ptex, version, platform, bootstrap_urls_path)
pex_url, python = get_pex_url_and_python_id(ptex, version, platform, bootstrap_urls_paths)
if python not in PYTHON_IDS:
# Should not happen... but if we mess up, this is a nicer error message rather than blowing up.
fatal(f"This version of scie-pants does not support {python!r}.")
return pex_url, PYTHON_IDS[python]


def get_bootstrap_urls(bootstrap_urls_path: str | None) -> dict[str, str] | None:
if not bootstrap_urls_path:
def get_bootstrap_urls(bootstrap_urls_paths: Iterable[str]) -> dict[str, str] | None:
if not bootstrap_urls_paths:
return None

bootstrap_urls = json.loads(Path(bootstrap_urls_path).read_text())
ptex_urls = bootstrap_urls.get("ptex")
if ptex_urls is None:
raise ValueError(f"Missing 'ptex' key in PANTS_BOOTSTRAP_URLS file: {bootstrap_urls_path}")
for key, url in ptex_urls.items():
if not isinstance(url, str):
raise TypeError(
f"The value for the key '{key}' in PANTS_BOOTSTRAP_URLS file: '{bootstrap_urls_path}' "
f"under the 'ptex' key was expected to be a string. Got a {type(url).__name__}"
ptex_urls: dict[str, str] = {}
for bootstrap_urls_path in bootstrap_urls_paths:
try:
bootstrap_urls = json.loads(Path(bootstrap_urls_path).read_text())
except json.decoder.JSONDecodeError as e:
raise ValueError(
f"Failed to parse JSON from PANTS_BOOTSTRAP_URLS file `{bootstrap_urls_path}`: {e}"
)

candidate_ptex_urls = bootstrap_urls.get("ptex")
if candidate_ptex_urls is None:
raise ValueError(
f"Missing 'ptex' key in PANTS_BOOTSTRAP_URLS file: {bootstrap_urls_path}"
)

for key, url in candidate_ptex_urls.items():
if not isinstance(url, str):
raise TypeError(
f"The value for the key '{key}' in PANTS_BOOTSTRAP_URLS file: '{bootstrap_urls_path}' "
f"under the 'ptex' key was expected to be a string. Got a {type(url).__name__}"
)
ptex_urls.update(candidate_ptex_urls)

return ptex_urls


def get_pex_url_and_python_id(
ptex: Ptex,
version: Version,
platform: str,
bootstrap_urls_path: str | None,
bootstrap_urls_paths: Iterable[str],
) -> tuple[str, str]:
ptex_urls = get_bootstrap_urls(bootstrap_urls_path)
ptex_urls = get_bootstrap_urls(bootstrap_urls_paths)
py = get_python_id_for_pants_version(version)
error: str | None = None
if py:
Expand Down
Loading