Debian Codegraph @

tests/minimext/build_wheels.sh

raw symbols SCIP
1 #!/bin/bash -e
2 # Copyright (C) 2024 Stewart Miles
3 # Licensed to the Python Software Foundation under a contributor agreement.
4 # See LICENSE.txt and CONTRIBUTORS.txt.
5
6 readonly DEFAULT_PYTHON_VERSION="$(python --version |
7 cut -d ' ' -f 2 |
8 cut -d. -f 1,2)"
9 readonly DEFAULT_PYTHON_VERSIONS="2.7 3.5 ${DEFAULT_PYTHON_VERSION}"
10
11
12 help() {
13 echo "\
14 Builds Linux wheels for this package using a range of Python distributions.
15
16 This script requires a Ubuntu distribution and will leave the deadsnakes PPA
17 https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
18 and Python packages used by this script installed.
19
20 $(basename "$0") [-d] [-I] [-S] [-p versions] [-h]
21
22 -d: Enable dry run mode, simply display rather than execute commands.
23 -S: Disable Python PPA installation.
24 -I: Disable Python apt package installation
25 -p: Space separated list of Python versions to install and build wheels for.
26 This defaults to \"${DEFAULT_PYTHON_VERSIONS}\".
27 -h: Display this help.
28 "
29 exit 1
30 }
31
32 main() {
33 readonly THIS_DIRECTORY="$(cd "$(dirname "${0}")"; pwd)"
34 local dryrun=
35 local install_python=1
36 local install_python_ppa=1
37 local selected_python_versions="${DEFAULT_PYTHON_VERSIONS}"
38
39 while getopts "dhISp:" OPTION; do
40 # shellcheck disable=SC2209
41 case "${OPTION}" in
42 d) dryrun=echo
43 ;;
44 I) install_python=0
45 ;;
46 S) install_python_ppa=0
47 ;;
48 p) selected_python_versions="${OPTARG}"
49 ;;
50 h|*) help
51 ;;
52 esac
53 done
54
55 IFS=' ' read -r -a python_versions <<< "${selected_python_versions}"
56
57 if [[ $((install_python_ppa)) -eq 1 ]]; then
58 set -x
59 ${dryrun} sudo add-apt-repository ppa:deadsnakes/ppa
60 set +x
61 fi
62
63 if [[ $((install_python)) -eq 1 ]]; then
64 # shellcheck disable=SC2207
65 readonly -a PYTHON_APT_PACKAGES=(
66 $(for version in "${python_versions[@]}"; do
67 echo "python${version}-dev";
68 done))
69 set -x
70 ${dryrun} sudo apt install "${PYTHON_APT_PACKAGES[@]}"
71 set +x
72 fi
73
74 local wheels_directory="${THIS_DIRECTORY}/wheels"
75 mkdir -p "${wheels_directory}"
76
77 local venv_directory
78 local versioned_python
79 local version
80 for version in "${python_versions[@]}"; do
81 versioned_python="python${version}"
82 venv_directory="${THIS_DIRECTORY}/.venv${version}"
83
84 # Try to bootstrap pip if it isn't found.
85 if ! ${dryrun} "${versioned_python}" -c "import pip" 2> /dev/null; then
86 # shellcheck disable=SC2155
87 local temporary_directory="$(mktemp -d)"
88 local get_pip="${temporary_directory}/get-pip-${version}.py"
89 ${dryrun} curl --output "${get_pip}" \
90 "https://bootstrap.pypa.io/pip/${version}/get-pip.py"
91 ${dryrun} "${versioned_python}" "${get_pip}"
92 rm -rf "${temporary_directory}"
93 fi
94
95 # Install virtualenv as venv isn't available in all Python versions.
96 ${dryrun} "${versioned_python}" -m pip install virtualenv
97 ${dryrun} "${versioned_python}" -m virtualenv "${venv_directory}"
98 (
99 cd "${THIS_DIRECTORY}"
100 ${dryrun} source "${venv_directory}/bin/activate"
101 # Upgrade pip and setuptools.
102 ${dryrun} pip install -U pip
103 ${dryrun} pip install -U setuptools
104 # Build wheels to the wheels subdirectory.
105 for embed_extension_metadata in 0 1; do
106 set -x
107 MINIMEXT_EMBED_EXTENSIONS_METADATA=${embed_extension_metadata} \
108 ${dryrun} pip wheel . -w "${wheels_directory}"
109 set +x
110 done
111 )
112 done
113
114 cp "${wheels_directory}"/*.whl "${THIS_DIRECTORY}/.."
115 }
116
117 main "$@"