|
1 |
| -"""Script to build compiled binary wheels that can be uploaded to PyPI. |
2 |
| -
|
3 |
| -The main GitHub workflow where this script is used: |
| 1 | +""" |
| 2 | +The main GitHub workflow where wheels are built: |
4 | 3 | https://github.com/mypyc/mypy_mypyc-wheels/blob/master/.github/workflows/build.yml
|
5 | 4 |
|
6 |
| -This uses cibuildwheel (https://github.com/pypa/cibuildwheel) to build the wheels. |
7 |
| -
|
8 |
| -Usage: |
9 |
| -
|
10 |
| - build_wheel.py --python-version <python-version> --output-dir <dir> |
11 |
| -
|
12 |
| -Wheels for the given Python version will be created in the given directory. |
13 |
| -Python version is in form "39". |
14 |
| -
|
15 |
| -This works on macOS, Windows and Linux. |
16 |
| -
|
17 |
| -You can test locally by using --extra-opts. macOS example: |
| 5 | +The script that builds wheels: |
| 6 | +https://github.com/mypyc/mypy_mypyc-wheels/blob/master/build_wheel.py |
18 | 7 |
|
19 |
| - mypy/misc/build_wheel.py --python-version 39 --output-dir out --extra-opts="--platform macos" |
| 8 | +That script is a light wrapper around cibuildwheel. Now that cibuildwheel has native configuration |
| 9 | +and better support for local builds, we could probably replace the script. |
20 | 10 | """
|
21 | 11 |
|
22 |
| -import argparse |
23 |
| -import os |
24 |
| -import subprocess |
25 |
| -from typing import Dict |
26 |
| - |
27 |
| -# Mypy repository root |
28 |
| -ROOT_DIR = os.path.dirname(os.path.dirname(__file__)) |
29 |
| - |
30 |
| - |
31 |
| -def create_environ(python_version: str) -> Dict[str, str]: |
32 |
| - """Set up environment variables for cibuildwheel.""" |
33 |
| - env = os.environ.copy() |
34 |
| - |
35 |
| - env["CIBW_BUILD"] = f"cp{python_version}-*" |
36 |
| - |
37 |
| - # Don't build 32-bit wheels |
38 |
| - env["CIBW_SKIP"] = "*-manylinux_i686 *-musllinux_i686 *-win32" |
39 |
| - |
40 |
| - # Apple Silicon support |
41 |
| - # When cross-compiling on Intel, it is not possible to test arm64 and |
42 |
| - # the arm64 part of a universal2 wheel. Warnings will be silenced with |
43 |
| - # following CIBW_TEST_SKIP |
44 |
| - env["CIBW_ARCHS_MACOS"] = "x86_64 arm64 universal2" |
45 |
| - env["CIBW_TEST_SKIP"] = "*-macosx_arm64 *_universal2:arm64" |
46 |
| - |
47 |
| - env["CIBW_BUILD_VERBOSITY"] = "1" |
48 |
| - |
49 |
| - # mypy's isolated builds don't specify the requirements mypyc needs, so install |
50 |
| - # requirements and don't use isolated builds. we need to use build-requirements.txt |
51 |
| - # with recent mypy commits to get stub packages needed for compilation. |
52 |
| - env["CIBW_BEFORE_BUILD"] = "pip install -r {package}/build-requirements.txt" |
53 |
| - |
54 |
| - # install clang using available package manager. platform-specific configuration overrides is only possible with |
55 |
| - # pyproject.toml. once project fully transitions, properly adjust cibuildwheel configuration to each platform. |
56 |
| - # https://cibuildwheel.readthedocs.io/en/stable/options/#overrides |
57 |
| - env[ |
58 |
| - "CIBW_BEFORE_ALL_LINUX" |
59 |
| - ] = "command -v yum && yum install -y llvm-toolset-7.0 || apk add --no-cache clang" |
60 |
| - |
61 |
| - # the double negative is counterintuitive, https://github.com/pypa/pip/issues/5735 |
62 |
| - # add llvm paths to environment to eliminate scl usage (like manylinux image does for gcc toolset). |
63 |
| - # specifying redhat paths for musllinux shouldn't harm but is not desired (see overrides-related comment above). |
64 |
| - env["CIBW_ENVIRONMENT"] = "MYPY_USE_MYPYC=1 MYPYC_OPT_LEVEL=3 PIP_NO_BUILD_ISOLATION=no" |
65 |
| - env["CIBW_ENVIRONMENT_LINUX"] = ( |
66 |
| - "MYPY_USE_MYPYC=1 MYPYC_OPT_LEVEL=3 PIP_NO_BUILD_ISOLATION=no " |
67 |
| - + "PATH=$PATH:/opt/rh/llvm-toolset-7.0/root/usr/bin " |
68 |
| - + "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rh/llvm-toolset-7.0/root/usr/lib64 " |
69 |
| - + "CC=clang" |
70 |
| - ) |
71 |
| - env[ |
72 |
| - "CIBW_ENVIRONMENT_WINDOWS" |
73 |
| - ] = "MYPY_USE_MYPYC=1 MYPYC_OPT_LEVEL=2 PIP_NO_BUILD_ISOLATION=no" |
74 |
| - |
75 |
| - # lxml doesn't have a wheel for Python 3.10 on the manylinux image we use. |
76 |
| - # lxml has historically been slow to support new Pythons as well. |
77 |
| - env[ |
78 |
| - "CIBW_BEFORE_TEST" |
79 |
| - ] = """ |
80 |
| - ( |
81 |
| - grep -v lxml {project}/mypy/test-requirements.txt > /tmp/test-requirements.txt |
82 |
| - && cp {project}/mypy/mypy-requirements.txt /tmp/mypy-requirements.txt |
83 |
| - && cp {project}/mypy/build-requirements.txt /tmp/build-requirements.txt |
84 |
| - && pip install -r /tmp/test-requirements.txt |
85 |
| - ) |
86 |
| - """.replace( |
87 |
| - "\n", " " |
88 |
| - ) |
89 |
| - # lxml currently has wheels on Windows and doesn't have grep, so special case |
90 |
| - env["CIBW_BEFORE_TEST_WINDOWS"] = "pip install -r {project}/mypy/test-requirements.txt" |
91 |
| - |
92 |
| - # pytest looks for configuration files in the parent directories of where the tests live. |
93 |
| - # since we are trying to run the tests from their installed location, we copy those into |
94 |
| - # the venv. Ew ew ew. |
95 |
| - # We don't run external mypyc tests since there's some issue with compilation on the |
96 |
| - # manylinux image we use. |
97 |
| - env[ |
98 |
| - "CIBW_TEST_COMMAND" |
99 |
| - ] = """ |
100 |
| - ( |
101 |
| - DIR=$(python -c 'import mypy, os; dn = os.path.dirname; print(dn(dn(mypy.__path__[0])))') |
102 |
| - && cp '{project}/mypy/pytest.ini' '{project}/mypy/conftest.py' $DIR |
103 |
| -
|
104 |
| - && MYPY_TEST_DIR=$(python -c 'import mypy.test; print(mypy.test.__path__[0])') |
105 |
| - && MYPY_TEST_PREFIX='{project}/mypy' pytest $MYPY_TEST_DIR |
106 |
| -
|
107 |
| - && MYPYC_TEST_DIR=$(python -c 'import mypyc.test; print(mypyc.test.__path__[0])') |
108 |
| - && MYPY_TEST_PREFIX='{project}/mypy' pytest $MYPYC_TEST_DIR -k 'not test_external' |
109 |
| - ) |
110 |
| - """.replace( |
111 |
| - "\n", " " |
112 |
| - ) |
113 |
| - |
114 |
| - # i ran into some flaky tests on windows, so only run testcheck. it looks like we |
115 |
| - # previously didn't run any tests on windows wheels, so this is a net win. |
116 |
| - env[ |
117 |
| - "CIBW_TEST_COMMAND_WINDOWS" |
118 |
| - ] = """ |
119 |
| - bash -c " |
120 |
| - ( |
121 |
| - DIR=$(python -c 'import mypy, os; dn = os.path.dirname; print(dn(dn(mypy.__path__[0])))') |
122 |
| - && cp '{project}/mypy/pytest.ini' '{project}/mypy/conftest.py' $DIR |
123 |
| -
|
124 |
| - && MYPY_TEST_DIR=$(python -c 'import mypy.test; print(mypy.test.__path__[0])') |
125 |
| - && MYPY_TEST_PREFIX='{project}/mypy' pytest $MYPY_TEST_DIR/testcheck.py |
126 |
| - ) |
127 |
| - " |
128 |
| - """.replace( |
129 |
| - "\n", " " |
130 |
| - ) |
131 |
| - return env |
132 |
| - |
133 |
| - |
134 |
| -def main() -> None: |
135 |
| - parser = argparse.ArgumentParser() |
136 |
| - parser.add_argument( |
137 |
| - "--python-version", required=True, metavar="XY", help="Python version (e.g. 38 or 39)" |
138 |
| - ) |
139 |
| - parser.add_argument( |
140 |
| - "--output-dir", required=True, metavar="DIR", help="Output directory for created wheels" |
141 |
| - ) |
142 |
| - parser.add_argument( |
143 |
| - "--extra-opts", |
144 |
| - default="", |
145 |
| - metavar="OPTIONS", |
146 |
| - help="Extra options passed to cibuildwheel verbatim", |
147 |
| - ) |
148 |
| - args = parser.parse_args() |
149 |
| - python_version = args.python_version |
150 |
| - output_dir = args.output_dir |
151 |
| - extra_opts = args.extra_opts |
152 |
| - environ = create_environ(python_version) |
153 |
| - script = f"python -m cibuildwheel {extra_opts} --output-dir {output_dir} {ROOT_DIR}" |
154 |
| - subprocess.check_call(script, shell=True, env=environ) |
155 |
| - |
156 |
| - |
157 |
| -if __name__ == "__main__": |
158 |
| - main() |
| 12 | +raise ImportError("This script has been moved back to https://github.com/mypyc/mypy_mypyc-wheels") |
0 commit comments