Skip to content

Commit

Permalink
Reset the bootstrapped binaries on install (#1317)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zanieb authored Feb 15, 2024
1 parent 06f2b6e commit 1509070
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions scripts/bootstrap/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ def sha256_file(path: Path):
versions_metadata = json.loads(VERSIONS_METADATA_FILE.read_text())
versions = VERSIONS_FILE.read_text().splitlines()

if INSTALL_DIR.exists():
print("Removing existing installations...")
shutil.rmtree(INSTALL_DIR)

# Install each version
for version in versions:
key = f"{INTERPRETER}-{version}-{PLATFORM_MAP.get(PLATFORM, PLATFORM)}-{ARCH_MAP.get(ARCH, ARCH)}"
install_dir = INSTALL_DIR / f"{INTERPRETER}@{version}"
already_exists = False
print(f"Installing {key}")

url = versions_metadata[key]["url"]
Expand All @@ -107,43 +109,39 @@ def sha256_file(path: Path):
sys.exit(1)

filename = url.split("/")[-1]
if not install_dir.exists():
print(f"Downloading {urllib.parse.unquote(filename)}")
download_path = THIS_DIR / filename
with urllib.request.urlopen(url) as response:
with download_path.open("wb") as download_file:
shutil.copyfileobj(response, download_file)

sha = versions_metadata[key]["sha256"]
if not sha:
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")
print(f"Downloading {urllib.parse.unquote(filename)}")
download_path = THIS_DIR / filename
with urllib.request.urlopen(url) as response:
with download_path.open("wb") as download_file:
shutil.copyfileobj(response, download_file)

sha = versions_metadata[key]["sha256"]
if not sha:
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)
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"))
decompress_file(THIS_DIR / filename, install_dir.with_suffix(".tmp"))

# Setup the installation
(install_dir.with_suffix(".tmp") / "python").rename(install_dir)
else:
# We need to update executables even if the version is already downloaded and extracted
# to ensure that changes to the precedence of versions are respected
already_exists = True
print("Already available, skipping download")
# Setup the installation
(install_dir.with_suffix(".tmp") / "python").rename(install_dir)

if PLATFORM == "win32":
executable = install_dir / "install" / "python.exe"
else:
# 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"]
minor = versions_metadata[key]["minor"]
Expand All @@ -164,10 +162,7 @@ def sha256_file(path: Path):
else:
target.symlink_to(executable)

if already_exists:
print(f"Updated executables for python{version}")
else:
print(f"Installed executables for python{version}")
print(f"Installed executables for python{version}")

# Cleanup
install_dir.with_suffix(".tmp").rmdir()
Expand Down

0 comments on commit 1509070

Please sign in to comment.