|
1 | 1 |
|
2 | 2 | import errno |
| 3 | +import json |
3 | 4 | import os |
4 | 5 | import shutil |
| 6 | +import tempfile |
| 7 | +import textwrap |
5 | 8 |
|
6 | 9 | from contextlib import contextmanager |
7 | 10 | from functools import wraps |
8 | | -from subprocess import check_call |
| 11 | +from subprocess import check_call, check_output |
9 | 12 |
|
10 | 13 |
|
11 | 14 | SCRIPT_DIR = os.path.dirname(__file__) |
@@ -190,11 +193,36 @@ def build_wheel(python_version, single_wheel=False): |
190 | 193 | print("# Build multiple ITK wheels") |
191 | 194 | print("#") |
192 | 195 |
|
| 196 | + try: |
| 197 | + # Because of python issue #14243, we set "delete=False" and |
| 198 | + # delete manually after process execution. |
| 199 | + script_file = tempfile.NamedTemporaryFile( |
| 200 | + delete=False, suffix=".py") |
| 201 | + script_file.write(bytearray(textwrap.dedent( |
| 202 | + """ |
| 203 | + import json |
| 204 | + from skbuild.platform_specifics.windows import WindowsPlatform |
| 205 | + # Instantiate |
| 206 | + build_platform = WindowsPlatform() |
| 207 | + generator = build_platform.default_generators[0] |
| 208 | + assert generator.name == "Ninja" |
| 209 | + print(json.dumps(generator.env)) |
| 210 | + """ # noqa: E501 |
| 211 | + ), "utf-8")) |
| 212 | + script_file.file.flush() |
| 213 | + output = check_output([python_executable, script_file.name]) |
| 214 | + build_env = json.loads(output.decode("utf-8").strip()) |
| 215 | + finally: |
| 216 | + script_file.close() |
| 217 | + os.remove(script_file.name) |
| 218 | + |
193 | 219 | py_site_packages_path = os.path.join( |
194 | 220 | SCRIPT_DIR, "..", "_skbuild", "cmake-install") |
195 | 221 |
|
196 | 222 | # Build ITK python |
197 | | - with push_dir(directory=build_path, make_directory=True): |
| 223 | + with push_dir(directory=build_path, make_directory=True), \ |
| 224 | + push_env(**build_env): |
| 225 | + |
198 | 226 | check_call([ |
199 | 227 | "cmake", |
200 | 228 | "-DCMAKE_BUILD_TYPE:STRING=%s" % build_type, |
|
0 commit comments