Skip to content

Commit 6792acf

Browse files
committed
REF: Standardize formatting and improve readability across build and utility scripts
1 parent b411eae commit 6792acf

4 files changed

Lines changed: 104 additions & 45 deletions

File tree

‎scripts/build_python_instance_base.py‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(
122122
self.cmake_itk_source_build_configurations.update(
123123
# ITK wrapping options
124124
{
125-
"ITK_SOURCE_DIR:PATH": f"{self.package_env_config["ITK_SOURCE_DIR"]}",
125+
"ITK_SOURCE_DIR:PATH": f"{self.package_env_config['ITK_SOURCE_DIR']}",
126126
"BUILD_TESTING:BOOL": "OFF",
127127
"ITK_WRAP_unsigned_short:BOOL": "ON",
128128
"ITK_WRAP_double:BOOL": "ON",
@@ -200,7 +200,7 @@ def run(self) -> None:
200200
] = self.build_external_module_python_wheel
201201
if self.build_itk_tarball_cache:
202202
python_package_build_steps[
203-
f"07_build_itk_tarball_cache_{self.package_env_config["OS_NAME"]}_{self.package_env_config["ARCH"]}"
203+
f"07_build_itk_tarball_cache_{self.package_env_config['OS_NAME']}_{self.package_env_config['ARCH']}"
204204
] = self.build_tarball
205205

206206
self.dist_dir.mkdir(parents=True, exist_ok=True)
@@ -265,7 +265,9 @@ def build_superbuild_support_components(self):
265265
def fixup_wheels(self, lib_paths: str = ""):
266266
# TBB library fix-up (applies to itk_core wheel)
267267
tbb_wheel = "itk_core"
268-
for wheel in (self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob(f"{tbb_wheel}*.whl"):
268+
for wheel in (self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob(
269+
f"{tbb_wheel}*.whl"
270+
):
269271
self.fixup_wheel(str(wheel), lib_paths)
270272

271273
def final_wheel_import_test(self, installed_dist_dir: Path):
@@ -301,7 +303,12 @@ def final_wheel_import_test(self, installed_dist_dir: Path):
301303
echo_check_call(
302304
[
303305
self.venv_info_dict["python_executable"],
304-
str(self.package_env_config["IPP_SOURCE_DIR"] / "docs" / "code" / "test.py"),
306+
str(
307+
self.package_env_config["IPP_SOURCE_DIR"]
308+
/ "docs"
309+
/ "code"
310+
/ "test.py"
311+
),
305312
]
306313
)
307314
print("Documentation tests passed.")
@@ -544,7 +551,9 @@ def build_itk_python_wheels(self):
544551
with push_env(
545552
PATH=f"{self.venv_info_dict['venv_bin_path']}{pathsep}{environ['PATH']}"
546553
):
547-
pyproject_configure = self.package_env_config["SCRIPT_DIR"] / "pyproject_configure.py"
554+
pyproject_configure = (
555+
self.package_env_config["SCRIPT_DIR"] / "pyproject_configure.py"
556+
)
548557

549558
# Build wheels
550559
for wheel_name in self.wheel_names:
@@ -559,7 +568,8 @@ def build_itk_python_wheels(self):
559568
"--env-file",
560569
self.package_env_config.get("PACKAGE_ENV_FILE"),
561570
"--output-dir",
562-
self.package_env_config["IPP_SOURCE_DIR"] / "BuildWheelsSupport",
571+
self.package_env_config["IPP_SOURCE_DIR"]
572+
/ "BuildWheelsSupport",
563573
wheel_name,
564574
]
565575
)
@@ -602,7 +612,9 @@ def build_itk_python_wheels(self):
602612
)
603613
# Append all cmake.define entries
604614
cmd += scikitbuild_cmdline_args.getPythonBuildCommandLineArguments()
605-
cmd += [self.package_env_config["IPP_SOURCE_DIR"] / "BuildWheelsSupport"]
615+
cmd += [
616+
self.package_env_config["IPP_SOURCE_DIR"] / "BuildWheelsSupport"
617+
]
606618
echo_check_call(cmd)
607619

608620
# Remove unnecessary files for building against ITK
@@ -806,8 +818,10 @@ def create_posix_tarball(self):
806818
Mirrors the historical scripts/*-build-tarball.sh behavior:
807819
- zstd compress with options (-10 -T6 --long=31)
808820
"""
809-
arch_postfix = f"-{self.package_env_config["ARCH"]}"
810-
tar_name = f"ITKPythonBuilds-{self.package_env_config["OS_NAME"]}{arch_postfix}.tar"
821+
arch_postfix = f"-{self.package_env_config['ARCH']}"
822+
tar_name = (
823+
f"ITKPythonBuilds-{self.package_env_config['OS_NAME']}{arch_postfix}.tar"
824+
)
811825
tar_path = self.package_env_config["IPP_SOURCE_DIR"].parent / tar_name
812826
zst_path = self.package_env_config["IPP_SOURCE_DIR"].parent / f"{tar_name}.zst"
813827

@@ -816,7 +830,7 @@ def create_posix_tarball(self):
816830
cache_directory_paths: list[Path] = [
817831
p
818832
for p in self.package_env_config["IPP_SOURCE_DIR"].glob(
819-
f"ITK-*-{self.package_env_config["OS_NAME"]}_{self.package_env_config["ARCH"]}"
833+
f"ITK-*-{self.package_env_config['OS_NAME']}_{self.package_env_config['ARCH']}"
820834
)
821835
]
822836
# oneTBB
@@ -827,7 +841,9 @@ def create_posix_tarball(self):
827841
self.package_env_config["IPP_SUPERBUILD_BINARY_DIR"]
828842
)
829843
# venvs directory
830-
cache_directory_paths.append(self.package_env_config["IPP_SOURCE_DIR"] / "venvs")
844+
cache_directory_paths.append(
845+
self.package_env_config["IPP_SOURCE_DIR"] / "venvs"
846+
)
831847

832848
# requirements-dev.txt
833849
req = self.package_env_config["IPP_SOURCE_DIR"] / "requirements-dev.txt"
@@ -846,7 +862,9 @@ def create_posix_tarball(self):
846862

847863
# scripts directory
848864
if (self.package_env_config["IPP_SOURCE_DIR"] / "scripts").exists():
849-
tarball_include_paths.append(str(self.package_env_config["IPP_SOURCE_DIR"] / "scripts"))
865+
tarball_include_paths.append(
866+
str(self.package_env_config["IPP_SOURCE_DIR"] / "scripts")
867+
)
850868

851869
# Create tar
852870
echo_check_call(

‎scripts/linux_build_python_instance.py‎

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from linux_venv_utils import create_linux_venvs
99
import shutil
1010

11-
from wheel_builder_utils import echo_check_call, push_dir, _remove_tree
11+
from wheel_builder_utils import echo_check_call, _remove_tree
1212

1313

1414
class LinuxBuildPythonInstance(BuildPythonInstanceBase):
@@ -25,7 +25,13 @@ def prepare_build_env(self) -> None:
2525
# ### Setup build tools
2626
self._build_type = "Release"
2727
self._use_tbb: str = "ON"
28-
self._tbb_dir = self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "lib" / "cmake" / "TBB"
28+
self._tbb_dir = (
29+
self.package_env_config["IPP_SOURCE_DIR"]
30+
/ "oneTBB-prefix"
31+
/ "lib"
32+
/ "cmake"
33+
/ "TBB"
34+
)
2935
self._cmake_executable = "cmake"
3036
# manylinux: the interpreter is provided; ensure basic tools are available
3137
self.venv_paths()
@@ -40,35 +46,24 @@ def prepare_build_env(self) -> None:
4046
elif self.package_env_config["ARCH"] == "x86":
4147
target_triple = "i686-linux-gnu"
4248
else:
43-
target_triple = f"{self.package_env_config["ARCH"]}-linux-gnu"
49+
target_triple = f"{self.package_env_config['ARCH']}-linux-gnu"
4450
self.cmake_compiler_configurations.set(
4551
"CMAKE_CXX_COMPILER_TARGET:STRING", target_triple
4652
)
4753
itk_binary_build_name: str = (
48-
f"ITK-{self.py_env}-linux_{self.package_env_config["ARCH"]}"
54+
f"ITK-{self.py_env}-linux_{self.package_env_config['ARCH']}"
4955
)
5056
manylinux_ver = self.package_env_config.get("MANYLINUX_VERSION", "")
5157
if len(manylinux_ver) > 0:
5258
itk_binary_build_name: str = (
53-
f"ITK-{self.py_env}-manylinux{manylinux_ver}_{self.package_env_config["ARCH"]}"
59+
f"ITK-{self.py_env}-manylinux{manylinux_ver}_{self.package_env_config['ARCH']}"
5460
)
5561

5662
self.cmake_itk_source_build_configurations.set(
5763
"ITK_BINARY_DIR:PATH",
5864
str(self.package_env_config["IPP_SOURCE_DIR"] / itk_binary_build_name),
5965
)
6066

61-
if self.package_env_config["ARCH"] == "x64":
62-
target_triple = "x86_64-linux-gnu"
63-
elif self.package_env_config["ARCH"] in ("aarch64", "arm64"):
64-
target_triple = "aarch64-linux-gnu"
65-
elif self.package_env_config["ARCH"] == "x86":
66-
target_triple = "i686-linux-gnu"
67-
else:
68-
target_triple = f"{self.package_env_config["ARCH"]}-linux-gnu"
69-
self.cmake_compiler_configurations.set(
70-
"CMAKE_CXX_COMPILER_TARGET:STRING", target_triple
71-
)
7267
# Keep values consistent with prior quoting behavior
7368
self.cmake_compiler_configurations.set("CMAKE_CXX_FLAGS:STRING", "-O3 -DNDEBUG")
7469
self.cmake_compiler_configurations.set("CMAKE_C_FLAGS:STRING", "-O3 -DNDEBUG")
@@ -81,11 +76,19 @@ def post_build_fixup(self) -> None:
8176
manylinux_ver = self.package_env_config.get("MANYLINUX_VERSION", "")
8277
if manylinux_ver:
8378
for whl in list(
84-
(self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob("itk-*linux_*.whl")
85-
) + list((self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob("itk_*linux_*.whl")):
79+
(self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob(
80+
"itk-*linux_*.whl"
81+
)
82+
) + list(
83+
(self.package_env_config["IPP_SOURCE_DIR"] / "dist").glob(
84+
"itk_*linux_*.whl"
85+
)
86+
):
8687
# Unpack, edit WHEEL tag, repack
8788
metawheel_dir = self.package_env_config["IPP_SOURCE_DIR"] / "metawheel"
88-
metawheel_dist = self.package_env_config["IPP_SOURCE_DIR"] / "metawheel-dist"
89+
metawheel_dist = (
90+
self.package_env_config["IPP_SOURCE_DIR"] / "metawheel-dist"
91+
)
8992
echo_check_call(
9093
[
9194
self.venv_info_dict["python_executable"],
@@ -126,7 +129,11 @@ def post_build_fixup(self) -> None:
126129
# Move and clean
127130
for new_whl in metawheel_dist.glob("*.whl"):
128131
shutil.move(
129-
str(new_whl), str((self.package_env_config["IPP_SOURCE_DIR"] / "dist") / new_whl.name)
132+
str(new_whl),
133+
str(
134+
(self.package_env_config["IPP_SOURCE_DIR"] / "dist")
135+
/ new_whl.name
136+
),
130137
)
131138
# Remove old and temp
132139
try:
@@ -154,9 +161,15 @@ def fixup_wheel(self, filepath, lib_paths: str = "") -> None:
154161
]
155162
if plat:
156163
cmd += ["--plat", plat]
157-
cmd += [str(filepath), "-w", str(self.package_env_config["IPP_SOURCE_DIR"] / "dist")]
164+
cmd += [
165+
str(filepath),
166+
"-w",
167+
str(self.package_env_config["IPP_SOURCE_DIR"] / "dist"),
168+
]
158169
# Provide LD_LIBRARY_PATH for oneTBB and common system paths
159-
extra_lib = str(self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "lib")
170+
extra_lib = str(
171+
self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "lib"
172+
)
160173
env = dict(self.package_env_config)
161174
env["LD_LIBRARY_PATH"] = ":".join(
162175
[
@@ -185,9 +198,9 @@ def post_build_cleanup(self) -> None:
185198
base = Path(self.package_env_config["IPP_SOURCE_DIR"])
186199

187200
# Helper to remove arbitrary paths (files/dirs) quietly
188-
def rm(p: Path):
201+
def rm(tree_path: Path):
189202
try:
190-
_remove_tree(p)
203+
_remove_tree(tree_path)
191204
except Exception:
192205
pass
193206

‎scripts/macos_build_python_instance.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ def prepare_build_env(self) -> None:
2424
# ### Setup build tools
2525
self._build_type = "Release"
2626
self._use_tbb: str = "OFF"
27-
self._tbb_dir = self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "lib" / "cmake" / "TBB"
27+
self._tbb_dir = (
28+
self.package_env_config["IPP_SOURCE_DIR"]
29+
/ "oneTBB-prefix"
30+
/ "lib"
31+
/ "cmake"
32+
/ "TBB"
33+
)
2834
self._cmake_executable = "cmake"
2935
# macOS: Assume venv already exists under IPP_SOURCE_DIR/venvs/<name>
3036
# Install required tools into each venv
@@ -45,7 +51,10 @@ def prepare_build_env(self) -> None:
4551
)
4652
self.cmake_itk_source_build_configurations.set(
4753
"ITK_BINARY_DIR:PATH",
48-
str(self.package_env_config["IPP_SOURCE_DIR"] / f"ITK-{self.py_env}-macosx_{osx_arch}"),
54+
str(
55+
self.package_env_config["IPP_SOURCE_DIR"]
56+
/ f"ITK-{self.py_env}-macosx_{osx_arch}"
57+
),
4958
)
5059

5160
def post_build_fixup(self) -> None:
@@ -134,7 +143,9 @@ def build_tarball(self):
134143
def remove_apple_double_files(self):
135144
try:
136145
# Optional: clean AppleDouble files if tool is available
137-
echo_check_call(["dot_clean", str(self.package_env_config["IPP_SOURCE_DIR"].name)])
146+
echo_check_call(
147+
["dot_clean", str(self.package_env_config["IPP_SOURCE_DIR"].name)]
148+
)
138149
except Exception:
139150
# dot_clean may not be available; continue without it
140151
pass

‎scripts/windows_build_python_instance.py‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ def prepare_build_env(self) -> None:
2525
# ### Setup build tools
2626
self._build_type = "Release"
2727
self._use_tbb: str = "ON"
28-
self._tbb_dir = self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "lib" / "cmake" / "TBB"
28+
self._tbb_dir = (
29+
self.package_env_config["IPP_SOURCE_DIR"]
30+
/ "oneTBB-prefix"
31+
/ "lib"
32+
/ "cmake"
33+
/ "TBB"
34+
)
2935
self._cmake_executable = "cmake.exe"
3036
self.venv_paths()
3137
self.update_venv_itk_build_configurations()
@@ -35,7 +41,8 @@ def prepare_build_env(self) -> None:
3541
}
3642
)
3743
self.cmake_itk_source_build_configurations.set(
38-
"ITK_BINARY_DIR:PATH", str(self.package_env_config["IPP_SOURCE_DIR"] / f"ITK-win_{self.py_env}")
44+
"ITK_BINARY_DIR:PATH",
45+
str(self.package_env_config["IPP_SOURCE_DIR"] / f"ITK-win_{self.py_env}"),
3946
)
4047

4148
def post_build_fixup(self) -> None:
@@ -45,7 +52,9 @@ def post_build_fixup(self) -> None:
4552
if self.windows_extra_lib_paths
4653
else []
4754
)
48-
search_lib_paths.append(str(self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "bin"))
55+
search_lib_paths.append(
56+
str(self.package_env_config["IPP_SOURCE_DIR"] / "oneTBB-prefix" / "bin")
57+
)
4958
search_lib_paths_str: str = ";".join(map(str, search_lib_paths))
5059
self.fixup_wheels(search_lib_paths_str)
5160

@@ -121,7 +130,10 @@ def fixup_wheel(self, filepath, lib_paths: str = "") -> None:
121130
print(f"Library paths for fixup: {lib_paths}")
122131

123132
delve_wheel = (
124-
self.package_env_config["IPP_SOURCE_DIR"] / f"venv-{self.py_env}" / "Scripts" / "delvewheel.exe"
133+
self.package_env_config["IPP_SOURCE_DIR"]
134+
/ f"venv-{self.py_env}"
135+
/ "Scripts"
136+
/ "delvewheel.exe"
125137
)
126138
cmd = [
127139
str(delve_wheel),
@@ -139,7 +151,9 @@ def fixup_wheel(self, filepath, lib_paths: str = "") -> None:
139151
def venv_paths(self) -> None:
140152
# Create venv related paths
141153
venv_executable = f"C:/Python{self.py_env}/Scripts/virtualenv.exe"
142-
venv_base_dir = Path(self.package_env_config["ITK_SOURCE_DIR"]) / f"venv-{self.py_env}"
154+
venv_base_dir = (
155+
Path(self.package_env_config["ITK_SOURCE_DIR"]) / f"venv-{self.py_env}"
156+
)
143157
if not venv_base_dir.exists():
144158
echo_check_call([venv_executable, str(venv_base_dir)])
145159
local_pip_executable = venv_base_dir / "Scripts" / "pip.exe"
@@ -169,7 +183,10 @@ def venv_paths(self) -> None:
169183
"install",
170184
"--upgrade",
171185
"-r",
172-
str(self.package_env_config["IPP_SOURCE_DIR"] / "requirements-dev.txt"),
186+
str(
187+
self.package_env_config["IPP_SOURCE_DIR"]
188+
/ "requirements-dev.txt"
189+
),
173190
]
174191
)
175192

0 commit comments

Comments
 (0)