Files
cibuildwheel/bin/update_dependencies.py
T

142 lines
5.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2021-04-25 03:45:27 -04:00
from __future__ import annotations
import configparser
import os
import shutil
import subprocess
import sys
2021-04-25 03:45:27 -04:00
from typing import NamedTuple
import requests
os.chdir(os.path.dirname(__file__))
2021-05-03 11:45:43 -04:00
os.chdir("..")
2020-03-17 20:28:53 +00:00
# CUSTOM_COMPILE_COMMAND is a pip-compile option that tells users how to
# regenerate the constraints files
2021-05-03 11:45:43 -04:00
os.environ["CUSTOM_COMPILE_COMMAND"] = "bin/update_dependencies.py"
2021-02-14 20:44:20 +01:00
PYTHON_VERSIONS = ["36", "37", "38", "39"]
2021-05-03 11:45:43 -04:00
if "--no-docker" in sys.argv:
for python_version in PYTHON_VERSIONS:
2021-04-30 17:56:34 -04:00
subprocess.run(
[
2021-05-03 11:45:43 -04:00
f"./env{python_version}/bin/pip-compile",
"--allow-unsafe",
"--upgrade",
"cibuildwheel/resources/constraints.in",
2021-05-07 18:16:47 -04:00
f"--output-file=cibuildwheel/resources/constraints-python{python_version}.txt",
2021-04-30 17:56:34 -04:00
],
check=True,
)
else:
2021-02-14 20:44:20 +01:00
image_runner = "quay.io/pypa/manylinux2010_x86_64:latest"
2021-05-03 11:45:43 -04:00
subprocess.run(["docker", "pull", image_runner], check=True)
for python_version in PYTHON_VERSIONS:
2021-05-03 11:45:43 -04:00
abi_flags = "" if int(python_version) >= 38 else "m"
python_path = f"/opt/python/cp{python_version}-cp{python_version}{abi_flags}/bin/"
command = (
2021-05-03 11:45:43 -04:00
f"{python_path}pip install pip-tools && "
2021-05-07 18:16:47 -04:00
f"{python_path}pip-compile --allow-unsafe --upgrade "
2021-05-03 11:45:43 -04:00
"cibuildwheel/resources/constraints.in "
f"--output-file cibuildwheel/resources/constraints-python{python_version}.txt"
)
2021-04-30 17:56:34 -04:00
subprocess.run(
[
2021-05-03 11:45:43 -04:00
"docker",
"run",
"--rm",
"--env=CUSTOM_COMPILE_COMMAND",
2021-05-07 18:16:47 -04:00
f"--volume={os.getcwd()}:/volume",
2021-05-03 11:45:43 -04:00
"--workdir=/volume",
2021-04-30 17:56:34 -04:00
image_runner,
2021-05-03 11:45:43 -04:00
"bash",
"-c",
2021-04-30 17:56:34 -04:00
command,
],
check=True,
)
# default constraints.txt
2021-04-30 17:56:34 -04:00
shutil.copyfile(
2021-05-03 11:45:43 -04:00
f"cibuildwheel/resources/constraints-python{PYTHON_VERSIONS[-1]}.txt",
"cibuildwheel/resources/constraints.txt",
2021-04-30 17:56:34 -04:00
)
2021-04-25 03:45:27 -04:00
class Image(NamedTuple):
manylinux_version: str
platform: str
image_name: str
tag: str | None
images = [
2021-05-03 11:45:43 -04:00
Image("manylinux1", "x86_64", "quay.io/pypa/manylinux1_x86_64", None),
Image("manylinux1", "i686", "quay.io/pypa/manylinux1_i686", None),
2021-02-14 20:44:20 +01:00
# 2010 images
Image("manylinux2010", "x86_64", "quay.io/pypa/manylinux2010_x86_64", None),
Image("manylinux2010", "i686", "quay.io/pypa/manylinux2010_i686", None),
2021-05-03 11:45:43 -04:00
Image("manylinux2010", "pypy_x86_64", "pypywheels/manylinux2010-pypy_x86_64", None),
2021-04-25 03:45:27 -04:00
# 2014 images
2021-05-03 11:45:43 -04:00
Image("manylinux2014", "x86_64", "quay.io/pypa/manylinux2014_x86_64", None),
Image("manylinux2014", "i686", "quay.io/pypa/manylinux2014_i686", None),
Image("manylinux2014", "aarch64", "quay.io/pypa/manylinux2014_aarch64", None),
Image("manylinux2014", "ppc64le", "quay.io/pypa/manylinux2014_ppc64le", None),
Image("manylinux2014", "s390x", "quay.io/pypa/manylinux2014_s390x", None),
2021-04-25 03:45:27 -04:00
# 2_24 images
2021-05-03 11:45:43 -04:00
Image("manylinux_2_24", "x86_64", "quay.io/pypa/manylinux_2_24_x86_64", None),
Image("manylinux_2_24", "i686", "quay.io/pypa/manylinux_2_24_i686", None),
Image("manylinux_2_24", "aarch64", "quay.io/pypa/manylinux_2_24_aarch64", None),
Image("manylinux_2_24", "ppc64le", "quay.io/pypa/manylinux_2_24_ppc64le", None),
Image("manylinux_2_24", "s390x", "quay.io/pypa/manylinux_2_24_s390x", None),
]
config = configparser.ConfigParser()
for image in images:
# get the tag name whose digest matches 'latest'
if image.tag is not None:
# image has been pinned, do not update
tag_name = image.tag
2021-05-03 11:45:43 -04:00
elif image.image_name.startswith("quay.io/"):
_, _, repository_name = image.image_name.partition("/")
response = requests.get(
2021-05-03 11:45:43 -04:00
f"https://quay.io/api/v1/repository/{repository_name}?includeTags=true"
)
response.raise_for_status()
repo_info = response.json()
2021-05-03 11:45:43 -04:00
tags_dict = repo_info["tags"]
2021-05-03 11:45:43 -04:00
latest_tag = tags_dict.pop("latest")
# find the tag whose manifest matches 'latest'
tag_name = next(
name
for (name, info) in tags_dict.items()
2021-05-03 11:45:43 -04:00
if info["manifest_digest"] == latest_tag["manifest_digest"]
)
else:
2021-05-03 11:45:43 -04:00
response = requests.get(f"https://hub.docker.com/v2/repositories/{image.image_name}/tags")
response.raise_for_status()
2021-05-03 11:45:43 -04:00
tags = response.json()["results"]
2021-05-03 11:45:43 -04:00
latest_tag = next(tag for tag in tags if tag["name"] == "latest")
# i don't know what it would mean to have multiple images per tag
2021-05-03 11:45:43 -04:00
assert len(latest_tag["images"]) == 1
digest = latest_tag["images"][0]["digest"]
pinned_tag = next(
2021-05-03 11:45:43 -04:00
tag for tag in tags if tag != latest_tag and tag["images"][0]["digest"] == digest
)
2021-05-03 11:45:43 -04:00
tag_name = pinned_tag["name"]
if not config.has_section(image.platform):
config[image.platform] = {}
2021-05-03 11:45:43 -04:00
config[image.platform][image.manylinux_version] = f"{image.image_name}:{tag_name}"
2021-05-03 11:45:43 -04:00
with open("cibuildwheel/resources/pinned_docker_images.cfg", "w") as f:
config.write(f)