diff --git a/scripts/bootstrap/install.py b/scripts/bootstrap/install.py index 037dafc02f4b..a79d8554a66c 100644 --- a/scripts/bootstrap/install.py +++ b/scripts/bootstrap/install.py @@ -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"] @@ -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"] @@ -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()