Repository navigation
Expand file tree
/
Copy pathwindows_build_python_instance.py
More file actions
150 lines (130 loc) · 5.1 KB
/
Copy pathwindows_build_python_instance.py
File metadata and controls
150 lines (130 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from __future__ import annotations
from pathlib import Path
from build_python_instance_base import BuildPythonInstanceBase
from scripts.wheel_builder_utils import echo_check_call, _which
class WindowsBuildPythonInstance(BuildPythonInstanceBase):
def prepare_build_env(self) -> None:
# Windows
# Install required tools into each venv
(
python_executable,
_python_include_dir,
_python_library,
pip,
self._ninja_executable,
_path,
venv_dir,
) = self.venv_paths()
# python_version = self.py_env
# python_dir = Path(f"C:/Python{python_version}")
# if not python_dir.exists():
# raise FileNotFoundError(
# f"Aborting. python_dir [{python_dir}] does not exist."
# )
#
# virtualenv_exe = python_dir / "Scripts" / "virtualenv.exe"
# venv_dir = self.IPP_SOURCE_DIR / f"venv-{python_version}"
# if not venv_dir.exists():
# print(f"Creating python virtual environment: {venv_dir}")
# echo_check_call([str(virtualenv_exe), str(venv_dir)])
# pip = str(venv_dir / "Scripts" / "pip.exe")
self._pip_uninstall_itk_wildcard(pip)
echo_check_call([pip, "install", "--upgrade", "pip"])
echo_check_call(
[
pip,
"install",
"--upgrade",
"build",
"ninja",
"numpy",
"scikit-build-core",
# os-specific tools below
"delvewheel",
"pkginfo",
]
)
# #############################################
# ### Setup build tools
self._build_type = "Release"
self._use_tbb: str = "ON"
self._tbb_dir = self.IPP_SOURCE_DIR / "oneTBB-prefix" / "lib" / "cmake" / "TBB"
self._cmake_executable = "cmake.exe"
ninja_executable_path = venv_dir / "Scripts" / "ninja.exe"
if ninja_executable_path.exists():
ninja_executable = ninja_executable_path
else:
ninja_executable = _which("ninja.exe") or str(ninja_executable_path)
print(f"NINJA_EXECUTABLE:{ninja_executable}")
def post_build_fixup(self) -> None:
# append the oneTBB-prefix\\bin directory for fixing wheels built with local oneTBB
search_lib_paths = (
[s for s in str(self.windows_extra_lib_paths[0]).rstrip(";") if s]
if self.windows_extra_lib_paths
else []
)
search_lib_paths.append(str(self.IPP_SOURCE_DIR / "oneTBB-prefix" / "bin"))
search_lib_paths_str: str = ";".join(map(str, search_lib_paths))
self.fixup_wheels(search_lib_paths_str)
def final_import_test(self) -> None:
self._final_import_test_fn(self.py_env, Path(self.dist_dir))
def fixup_wheel(self, filepath, lib_paths: str = "") -> None:
# Windows fixup_wheel
lib_paths = lib_paths.strip()
lib_paths = (
lib_paths + ";" if lib_paths else ""
) + "C:/P/IPP/oneTBB-prefix/bin"
print(f"Library paths for fixup: {lib_paths}")
delve_wheel = (
self.IPP_SOURCE_DIR / f"venv-{self.py_env}" / "Scripts" / "delvewheel.exe"
)
cmd = [
str(delve_wheel),
"repair",
"--no-mangle-all",
"--add-path",
lib_paths,
"--ignore-in-wheel",
"-w",
str(self.IPP_SOURCE_DIR / "dist"),
str(filepath),
]
echo_check_call(cmd)
def venv_paths(self) -> tuple[str, str, str, str, str, str, Path]:
# Create venv related paths
venv_executable = f"C:/Python{self.py_env}/Scripts/virtualenv.exe"
venv_dir = Path(self.ITK_SOURCE_DIR) / f"venv-{self.py_env}"
echo_check_call([venv_executable, str(venv_dir)])
python_executable = venv_dir / "Scripts" / "python.exe"
python_include_dir = f"C:/Python{self.py_env}/include"
# XXX It should be possible to query skbuild for the library dir associated
# with a given interpreter.
xy_ver = self.py_env.split("-")[0]
if int(self.py_env.split("-")[0][1:]) >= 11:
# Stable ABI
python_library = f"C:/Python{self.py_env}/libs/python3.lib"
else:
python_library = f"C:/Python{self.py_env}/libs/python{xy_ver}.lib"
pip = venv_dir / "Scripts" / "pip.exe"
# Update PATH
path = venv_dir / "Scripts"
return (
str(python_executable),
python_include_dir,
python_library,
str(pip),
self._ninja_executable,
str(path),
venv_dir,
)
def discover_python_venvs(
self, platform_os_name: str, platform_architechure: str
) -> list[str]:
default_py_envs = [
f"39-{platform_architechure}",
f"310-{platform_architechure}",
f"311-{platform_architechure}",
]
return default_py_envs
def _final_import_test_fn(self, py_env, param):
pass