Skip to content

Commit 86c9a68

Browse files
hjmjohnsonclaude
andcommitted
ENH: Allow specifying ITK branch, tag, or hash for build-all scripts
Add --itk-ref option to both shell and Python build-all-latest-wheels scripts. Defaults to "main" but accepts any git ref (branch name, tag like v6.0b02, or commit hash). The ITK clone is now a full clone (not shallow) to support arbitrary refs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eb28193 commit 86c9a68

2 files changed

Lines changed: 49 additions & 16 deletions

File tree

scripts/build-all-latest-wheels.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
#!/bin/bash
2-
# Build ITK + all remote module Python wheels from latest main branches.
3-
# Usage: ./scripts/build-all-latest-wheels.sh [platform-env]
4-
# Example: ./scripts/build-all-latest-wheels.sh linux-py311
2+
# Build ITK + all remote module Python wheels.
3+
# Usage: ./scripts/build-all-latest-wheels.sh [options]
4+
# --platform-env ENV Pixi environment (default: linux-py311)
5+
# --itk-ref REF ITK branch, tag, or commit hash (default: main)
6+
# --itk-repo URL ITK git URL
7+
# --ipp-branch BRANCH ITKPythonPackage branch (default: python-build-system)
8+
# --ipp-repo URL ITKPythonPackage git URL
9+
# Example:
10+
# ./scripts/build-all-latest-wheels.sh --itk-ref v6.0b02 --platform-env linux-py311
511
set -euo pipefail
612

7-
PLATFORM_ENV="${1:-linux-py311}"
8-
TIMESTAMP=$(date +%Y%m%d%H%M%S)
9-
WORKDIR="/tmp/${TIMESTAMP}_LatestITKPython"
10-
DIST_DIR="${WORKDIR}/dist"
13+
# Defaults
14+
PLATFORM_ENV="linux-py311"
15+
ITK_REF="main"
1116
ITK_REPO="https://github.com/InsightSoftwareConsortium/ITK.git"
1217
IPP_REPO="https://github.com/BRAINSia/ITKPythonPackage.git"
1318
IPP_BRANCH="python-build-system"
1419

20+
while [[ $# -gt 0 ]]; do
21+
case "$1" in
22+
--platform-env) PLATFORM_ENV="$2"; shift 2 ;;
23+
--itk-ref) ITK_REF="$2"; shift 2 ;;
24+
--itk-repo) ITK_REPO="$2"; shift 2 ;;
25+
--ipp-branch) IPP_BRANCH="$2"; shift 2 ;;
26+
--ipp-repo) IPP_REPO="$2"; shift 2 ;;
27+
*) echo "Unknown option: $1"; exit 1 ;;
28+
esac
29+
done
30+
31+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
32+
WORKDIR="/tmp/${TIMESTAMP}_LatestITKPython"
33+
DIST_DIR="${WORKDIR}/dist"
34+
1535
mkdir -p "${DIST_DIR}"
1636
echo "=== Build directory: ${WORKDIR}"
1737
echo "=== Platform: ${PLATFORM_ENV}"
38+
echo "=== ITK ref: ${ITK_REF}"
1839

1940
# 1) Clone ITK
20-
echo "=== Cloning ITK (main)..."
21-
git clone --depth 1 --branch main "${ITK_REPO}" "${WORKDIR}/ITK"
41+
echo "=== Cloning ITK (${ITK_REF})..."
42+
git clone "${ITK_REPO}" "${WORKDIR}/ITK"
43+
git -C "${WORKDIR}/ITK" checkout "${ITK_REF}"
2244

2345
# 2) Clone ITKPythonPackage
2446
echo "=== Cloning ITKPythonPackage (${IPP_BRANCH})..."
@@ -70,7 +92,7 @@ for name in "${module_list[@]}"; do
7092
echo "=== Building ${name}..."
7193
if pixi run -e "${PLATFORM_ENV}" -- python scripts/build_wheels.py \
7294
--platform-env "${PLATFORM_ENV}" \
73-
--itk-git-tag main \
95+
--itk-git-tag "${ITK_REF}" \
7496
--itk-source-dir "${WORKDIR}/ITK" \
7597
--module-source-dir "${MODULES_DIR}/${name}" \
7698
--no-build-itk-tarball-cache \

scripts/build_all_latest_wheels.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ def run(cmd: list[str], **kwargs) -> subprocess.CompletedProcess:
2121
return subprocess.run(cmd, check=True, **kwargs)
2222

2323

24-
def clone(repo: str, dest: Path, branch: str | None = None) -> bool:
25-
cmd = ["git", "clone", "--depth", "1"]
24+
def clone(repo: str, dest: Path, branch: str | None = None, depth: int | None = 1) -> bool:
25+
cmd = ["git", "clone"]
26+
if depth is not None:
27+
cmd += ["--depth", str(depth)]
2628
if branch:
2729
cmd += ["--branch", branch]
2830
cmd += [repo, str(dest)]
@@ -50,6 +52,7 @@ def build_wheels(
5052
platform_env: str,
5153
build_dir: Path,
5254
itk_source: Path,
55+
itk_ref: str = "main",
5356
module_source: Path | None = None,
5457
skip_itk: bool = False,
5558
) -> bool:
@@ -64,7 +67,7 @@ def build_wheels(
6467
"--platform-env",
6568
platform_env,
6669
"--itk-git-tag",
67-
"main",
70+
itk_ref,
6871
"--itk-source-dir",
6972
str(itk_source),
7073
"--no-build-itk-tarball-cache",
@@ -104,6 +107,11 @@ def main():
104107
default="https://github.com/InsightSoftwareConsortium/ITK.git",
105108
help="ITK git URL",
106109
)
110+
parser.add_argument(
111+
"--itk-ref",
112+
default="main",
113+
help="ITK branch, tag, or commit hash (default: main)",
114+
)
107115
args = parser.parse_args()
108116

109117
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
@@ -114,11 +122,13 @@ def main():
114122

115123
print(f"=== Build directory: {workdir}")
116124
print(f"=== Platform: {args.platform_env}")
125+
print(f"=== ITK ref: {args.itk_ref}")
117126

118127
# 1) Clone ITK
119-
print("=== Cloning ITK (main)...")
128+
print(f"=== Cloning ITK ({args.itk_ref})...")
120129
itk_dir = workdir / "ITK"
121-
clone(args.itk_repo, itk_dir, branch="main")
130+
clone(args.itk_repo, itk_dir, depth=None)
131+
run(["git", "checkout", args.itk_ref], cwd=itk_dir)
122132

123133
# 2) Clone ITKPythonPackage
124134
print(f"=== Cloning ITKPythonPackage ({args.ipp_branch})...")
@@ -147,7 +157,7 @@ def main():
147157

148158
# 4) Build ITK wheels
149159
print("=== Building ITK Python wheels...")
150-
if not build_wheels(ipp_dir, args.platform_env, build_dir, itk_dir):
160+
if not build_wheels(ipp_dir, args.platform_env, build_dir, itk_dir, args.itk_ref):
151161
print("FATAL: ITK wheel build failed")
152162
sys.exit(1)
153163

@@ -165,6 +175,7 @@ def main():
165175
args.platform_env,
166176
build_dir,
167177
itk_dir,
178+
args.itk_ref,
168179
module_source=mod_dir,
169180
skip_itk=True,
170181
):

0 commit comments

Comments
 (0)