Skip to content

Commit c225977

Browse files
hjmjohnsonclaude
andcommitted
ENH: Branch between Strategy 3 and Strategy 1 for ITK dep resolution
When a remote module declares dynamic = ["dependencies"] in its [project] table, skip the pyproject.toml rewrite (Strategy 1) and instead set ITK_PACKAGE_VERSION in the environment for the scikit-build-core metadata provider to pick up (Strategy 3). Modules that have not yet opted into dynamic dependencies continue to use the build-time rewrite fallback, so both approaches coexist during the transition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3292325 commit c225977

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

scripts/build_python_instance_base.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,32 @@ def _update_module_itk_deps(pyproject_path: Path, itk_version: str) -> bool:
778778
"""
779779
import re
780780

781+
try:
782+
import tomllib
783+
except ModuleNotFoundError:
784+
import tomli as tomllib # Python < 3.11
785+
786+
with open(pyproject_path, "rb") as f:
787+
pyproject_data = tomllib.load(f)
788+
789+
# --- Strategy 3: module declares dynamic dependencies -----------------
790+
dynamic_fields = (
791+
pyproject_data.get("project", {}).get("dynamic", [])
792+
)
793+
if "dependencies" in dynamic_fields:
794+
# The module has opted into dynamic dependency resolution.
795+
# Set ITK_PACKAGE_VERSION in the environment so the
796+
# scikit-build-core metadata provider (itk-build-metadata)
797+
# can emit the correct Requires-Dist at build time.
798+
os.environ["ITK_PACKAGE_VERSION"] = itk_version
799+
print(
800+
f"Strategy 3: {pyproject_path.name} declares "
801+
f"dynamic=[\"dependencies\"]; set ITK_PACKAGE_VERSION="
802+
f"{itk_version} for metadata provider"
803+
)
804+
return False # no file modification needed
805+
806+
# --- Strategy 1: build-time rewrite (fallback) ------------------------
781807
text = pyproject_path.read_text(encoding="utf-8")
782808
# Match lines like: "itk-core == 5.4.*" or "itk-filtering==5.4.*"
783809
pattern = re.compile(
@@ -804,7 +830,7 @@ def _replace(m: re.Match) -> str:
804830
if changed:
805831
pyproject_path.write_text(new_text, encoding="utf-8")
806832
print(
807-
f"Updated ITK dependency pins in {pyproject_path} "
833+
f"Strategy 1: Updated ITK dependency pins in {pyproject_path} "
808834
f"(>= {min_floor} for ITK {itk_version})"
809835
)
810836
return changed

0 commit comments

Comments
 (0)