Reset the bootstrapped binaries on install (#1317)

There was not much benefit to avoiding the new download (and it was
broken in some Windows compatibility work) and this ensures there are
_only_ the versions we specified
This commit is contained in:
Zanie Blue 2024-02-15 12:08:38 -06:00 committed by GitHub
parent 06f2b6eee2
commit 1509070316
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 35 deletions

View File

@ -92,12 +92,14 @@ def sha256_file(path: Path):
versions_metadata = json.loads(VERSIONS_METADATA_FILE.read_text()) versions_metadata = json.loads(VERSIONS_METADATA_FILE.read_text())
versions = VERSIONS_FILE.read_text().splitlines() versions = VERSIONS_FILE.read_text().splitlines()
if INSTALL_DIR.exists():
print("Removing existing installations...")
shutil.rmtree(INSTALL_DIR)
# Install each version # Install each version
for version in versions: for version in versions:
key = f"{INTERPRETER}-{version}-{PLATFORM_MAP.get(PLATFORM, PLATFORM)}-{ARCH_MAP.get(ARCH, ARCH)}" key = f"{INTERPRETER}-{version}-{PLATFORM_MAP.get(PLATFORM, PLATFORM)}-{ARCH_MAP.get(ARCH, ARCH)}"
install_dir = INSTALL_DIR / f"{INTERPRETER}@{version}" install_dir = INSTALL_DIR / f"{INTERPRETER}@{version}"
already_exists = False
print(f"Installing {key}") print(f"Installing {key}")
url = versions_metadata[key]["url"] url = versions_metadata[key]["url"]
@ -107,43 +109,39 @@ for version in versions:
sys.exit(1) sys.exit(1)
filename = url.split("/")[-1] filename = url.split("/")[-1]
if not install_dir.exists(): print(f"Downloading {urllib.parse.unquote(filename)}")
print(f"Downloading {urllib.parse.unquote(filename)}") download_path = THIS_DIR / filename
download_path = THIS_DIR / filename with urllib.request.urlopen(url) as response:
with urllib.request.urlopen(url) as response: with download_path.open("wb") as download_file:
with download_path.open("wb") as download_file: shutil.copyfileobj(response, download_file)
shutil.copyfileobj(response, download_file)
sha = versions_metadata[key]["sha256"] sha = versions_metadata[key]["sha256"]
if not sha: if not sha:
print(f"WARNING: no checksum for {key}") print(f"WARNING: no checksum for {key}")
else:
print("Verifying checksum...", end="")
if sha256_file(download_path) != sha:
print(" FAILED!")
sys.exit(1)
print(" OK")
if install_dir.exists():
shutil.rmtree(install_dir)
print("Extracting to", install_dir)
install_dir.parent.mkdir(parents=True, exist_ok=True)
decompress_file(THIS_DIR / filename, install_dir.with_suffix(".tmp"))
# Setup the installation
(install_dir.with_suffix(".tmp") / "python").rename(install_dir)
else: else:
# We need to update executables even if the version is already downloaded and extracted print("Verifying checksum...", end="")
# to ensure that changes to the precedence of versions are respected if sha256_file(download_path) != sha:
already_exists = True print(" FAILED!")
print("Already available, skipping download") sys.exit(1)
print(" OK")
if install_dir.exists():
shutil.rmtree(install_dir)
print("Extracting to", install_dir)
install_dir.parent.mkdir(parents=True, exist_ok=True)
decompress_file(THIS_DIR / filename, install_dir.with_suffix(".tmp"))
# Setup the installation
(install_dir.with_suffix(".tmp") / "python").rename(install_dir)
if PLATFORM == "win32": if PLATFORM == "win32":
executable = install_dir / "install" / "python.exe" executable = install_dir / "install" / "python.exe"
else: else:
# Use relative paths for links so if the bin is moved they don't break # Use relative paths for links so if the bin is moved they don't break
executable = "." / install_dir.relative_to(BIN_DIR) / "install" / "bin" / "python3" executable = (
"." / install_dir.relative_to(BIN_DIR) / "install" / "bin" / "python3"
)
major = versions_metadata[key]["major"] major = versions_metadata[key]["major"]
minor = versions_metadata[key]["minor"] minor = versions_metadata[key]["minor"]
@ -164,10 +162,7 @@ for version in versions:
else: else:
target.symlink_to(executable) target.symlink_to(executable)
if already_exists: print(f"Installed executables for python{version}")
print(f"Updated executables for python{version}")
else:
print(f"Installed executables for python{version}")
# Cleanup # Cleanup
install_dir.with_suffix(".tmp").rmdir() install_dir.with_suffix(".tmp").rmdir()