Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions misc/build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
The main GitHub workflow where this script is used:
https://github.com/mypyc/mypy_mypyc-wheels/blob/master/.github/workflows/build.yml

This uses cibuildwheel (https://github.com/pypa/cibuildwheel) to
build the wheels.
This uses cibuildwheel (https://github.com/pypa/cibuildwheel) to build the wheels.

Usage:

build_wheel_ci.py --python-version <python-version> \
--output-dir <dir>
build_wheel.py --python-version <python-version> --output-dir <dir>

Wheels for the given Python version will be created in the given directory.
Python version is in form "39".
Expand All @@ -18,9 +16,7 @@

You can test locally by using --extra-opts. macOS example:

mypy/misc/build_wheel_ci.py --python-version 39 --output-dir out --extra-opts="--platform macos"

Other supported values for platform: linux, windows
mypy/misc/build_wheel.py --python-version 39 --output-dir out --extra-opts="--platform macos"
"""

import argparse
Expand All @@ -39,13 +35,13 @@ def create_environ(python_version: str) -> Dict[str, str]:
"""Set up environment variables for cibuildwheel."""
env = os.environ.copy()

env['CIBW_BUILD'] = "cp{}-*".format(python_version)
env['CIBW_BUILD'] = f"cp{python_version}-*"

# Don't build 32-bit wheels
env['CIBW_SKIP'] = "*-manylinux_i686 *-win32"

# Apple Silicon support
# When cross-compiling on Intel, it is not possible to test arm64 and
# When cross-compiling on Intel, it is not possible to test arm64 and
# the arm64 part of a universal2 wheel. Warnings will be silenced with
# following CIBW_TEST_SKIP
env['CIBW_ARCHS_MACOS'] = "x86_64 arm64"
Expand All @@ -56,20 +52,15 @@ def create_environ(python_version: str) -> Dict[str, str]:
# mypy's isolated builds don't specify the requirements mypyc needs, so install
# requirements and don't use isolated builds. we need to use build-requirements.txt
# with recent mypy commits to get stub packages needed for compilation.
#
# TODO: remove use of mypy-requirements.txt once we no longer need to support
# building pre modular typeshed releases
env['CIBW_BEFORE_BUILD'] = """
pip install -r {package}/mypy-requirements.txt &&
(pip install -r {package}/build-requirements.txt || true)
pip install -r {package}/build-requirements.txt
""".replace('\n', ' ')

# download a copy of clang to use to compile on linux. this was probably built in 2018,
# speeds up compilation 2x
env['CIBW_BEFORE_BUILD_LINUX'] = """
(cd / && curl -L %s | tar xzf -) &&
pip install -r {package}/mypy-requirements.txt &&
(pip install -r {package}/build-requirements.txt || true)
pip install -r {package}/build-requirements.txt
""".replace('\n', ' ') % LLVM_URL

# the double negative is counterintuitive, https://github.com/pypa/pip/issues/5735
Expand Down Expand Up @@ -128,8 +119,7 @@ def main() -> None:
output_dir = args.output_dir
extra_opts = args.extra_opts
environ = create_environ(python_version)
script = 'python -m cibuildwheel {} --output-dir {} {}'.format(extra_opts, output_dir,
ROOT_DIR)
script = f'python -m cibuildwheel {extra_opts} --output-dir {output_dir} {ROOT_DIR}'
subprocess.check_call(script, shell=True, env=environ)


Expand Down