|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Script to download all required wheels (including dependencies) of the ddtrace |
| 4 | +Python package for relevant Python versions (+ abis), C library platforms and |
| 5 | +architectures and merge them into a "megawheel" directory. |
| 6 | +
|
| 7 | +This directory provides a portable installation of ddtrace which can be used |
| 8 | +on multiple platforms and architectures. |
| 9 | +
|
| 10 | +Currently the only OS supported is Linux. |
| 11 | +
|
| 12 | +This script has been tested with 21.0.0 and is confirmed to not work with |
| 13 | +20.0.2. |
| 14 | +
|
| 15 | +Usage: |
| 16 | + ./dl_megawheel.py --help |
| 17 | +
|
| 18 | +
|
| 19 | +The downloaded wheels can then be installed locally using: |
| 20 | + pip install --no-index --find-links <dir_of_downloaded_wheels> ddtrace |
| 21 | +""" |
| 22 | +import argparse |
| 23 | +import itertools |
| 24 | +import os |
| 25 | +import subprocess |
| 26 | +import sys |
| 27 | + |
| 28 | +import packaging.version |
| 29 | + |
| 30 | + |
| 31 | +# Do a check on the pip version since older versions are known to be |
| 32 | +# incompatible. |
| 33 | +MIN_PIP_VERSION = packaging.version.parse("21.0") |
| 34 | +cmd = [sys.executable, "-m", "pip", "--version"] |
| 35 | +res = subprocess.run(cmd, capture_output=True) |
| 36 | +out = res.stdout.decode().split(" ")[1] |
| 37 | +pip_version = packaging.version.parse(out) |
| 38 | +if pip_version < MIN_PIP_VERSION: |
| 39 | + print( |
| 40 | + "WARNING: using known incompatible version, %r, of pip. The minimum compatible pip version is %r" |
| 41 | + % (pip_version, MIN_PIP_VERSION) |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +supported_pythons = ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] |
| 46 | +supported_arches = ["aarch64", "x86_64", "i686"] |
| 47 | +supported_platforms = ["musllinux_1_1", "manylinux2014"] |
| 48 | + |
| 49 | +parser = argparse.ArgumentParser(description=__doc__) |
| 50 | +parser.add_argument( |
| 51 | + "--python-version", |
| 52 | + choices=supported_pythons, |
| 53 | + action="append", |
| 54 | + required=True, |
| 55 | +) |
| 56 | +parser.add_argument( |
| 57 | + "--arch", |
| 58 | + choices=supported_arches, |
| 59 | + action="append", |
| 60 | + required=True, |
| 61 | +) |
| 62 | +parser.add_argument( |
| 63 | + "--platform", |
| 64 | + choices=supported_platforms, |
| 65 | + action="append", |
| 66 | + required=True, |
| 67 | +) |
| 68 | +parser.add_argument("--ddtrace-version", type=str, required=True) |
| 69 | +parser.add_argument("--output-dir", type=str, required=True) |
| 70 | +parser.add_argument("--dry-run", action="store_true") |
| 71 | +parser.add_argument("--verbose", action="store_true") |
| 72 | +args = parser.parse_args() |
| 73 | + |
| 74 | +dl_dir = args.output_dir |
| 75 | +print("saving wheels to %s" % dl_dir) |
| 76 | + |
| 77 | +for python_version, arch, platform in itertools.product(args.python_version, args.arch, args.platform): |
| 78 | + print("Downloading %s %s %s wheel" % (python_version, arch, platform)) |
| 79 | + abi = "cp%s" % python_version.replace(".", "") |
| 80 | + # Have to special-case these versions of Python for some reason. |
| 81 | + if python_version in ["2.7", "3.5", "3.6", "3.7"]: |
| 82 | + abi += "m" |
| 83 | + |
| 84 | + # See the docs for an explanation of all the options used: |
| 85 | + # https://pip.pypa.io/en/stable/cli/pip_download/ |
| 86 | + # only-binary=:all: is specified to ensure we get all the dependencies of ddtrace as well. |
| 87 | + cmd = [ |
| 88 | + sys.executable, |
| 89 | + "-m", |
| 90 | + "pip", |
| 91 | + "download", |
| 92 | + "ddtrace==%s" % args.ddtrace_version, |
| 93 | + "--platform", |
| 94 | + "%s_%s" % (platform, arch), |
| 95 | + "--python-version", |
| 96 | + python_version, |
| 97 | + "--abi", |
| 98 | + abi, |
| 99 | + "--only-binary=:all:", |
| 100 | + "--dest", |
| 101 | + dl_dir, |
| 102 | + ] |
| 103 | + if args.verbose: |
| 104 | + print(" ".join(cmd)) |
| 105 | + |
| 106 | + if not args.dry_run: |
| 107 | + subprocess.run(cmd, capture_output=not args.verbose, check=True) |
| 108 | + |
| 109 | + # Unzip all the wheels into the output directory |
| 110 | + wheel_files = [f for f in os.listdir(dl_dir) if f.endswith(".whl")] |
| 111 | + for whl in wheel_files: |
| 112 | + wheel_file = os.path.join(dl_dir, whl) |
| 113 | + # -q for quieter output, else we get all of the files being unzipped. |
| 114 | + subprocess.run(["unzip", "-q", "-o", wheel_file, "-d", dl_dir]) |
| 115 | + # Remove the wheel as it has been unpacked |
| 116 | + os.remove(wheel_file) |
0 commit comments