Skip to content

Commit 54cbec6

Browse files
committed
STYLE: Apply pre-commit hook fixes across the repository
Run the full pre-commit suite repo-wide (black, ruff, shfmt, taplo) and resolve shellcheck findings: egrep -> grep -E, guard rm with ${MODULES_DIR:?}, and count wheels with find instead of ls.
1 parent 468e8dc commit 54cbec6

6 files changed

Lines changed: 47 additions & 27 deletions

File tree

Utilities/Hooks/kw-commit-msg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import re
2222
import subprocess
2323
import sys
24-
2524
from pathlib import Path
2625

27-
2826
DEFAULT_LINE_LENGTH: int = 78
2927

3028

@@ -116,7 +114,7 @@ def main():
116114
r"^(Merge|Revert|BUG:|COMP:|DOC:|ENH:|PERF:|STYLE:|WIP:)\s", subject_line
117115
):
118116
die(
119-
f"""Start ITK commit messages with a standard prefix (and a space):
117+
"""Start ITK commit messages with a standard prefix (and a space):
120118
BUG: - fix for runtime crash or incorrect result
121119
COMP: - compiler error or warning fix
122120
DOC: - documentation change

Utilities/Hooks/prepare-commit-msg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#==========================================================================
1919

2020
egrep-q() {
21-
egrep "$@" >/dev/null 2>/dev/null
21+
grep -E "$@" >/dev/null 2>/dev/null
2222
}
2323

2424
# First argument is file containing commit message.
@@ -45,9 +45,9 @@ instructions='#\
4545
# Follow the first line commit summary with an empty line, then a detailed\
4646
# description in one or more paragraphs.\
4747
#' &&
48-
sed '/^# On branch.*$/ a\
48+
sed '/^# On branch.*$/ a\
4949
'"$instructions"'
5050
/^# Not currently on any branch.*$/ a\
5151
'"$instructions"'
52-
' "$commit_msg" > "$commit_msg_tmp" &&
53-
mv "$commit_msg_tmp" "$commit_msg"
52+
' "$commit_msg" >"$commit_msg_tmp" &&
53+
mv "$commit_msg_tmp" "$commit_msg"

Utilities/scripts/build-all-latest-wheels.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,30 @@ IPP_BRANCH="python-build-system"
1919

2020
while [[ $# -gt 0 ]]; do
2121
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 ;;
22+
--platform-env)
23+
PLATFORM_ENV="$2"
24+
shift 2
25+
;;
26+
--itk-ref)
27+
ITK_REF="$2"
28+
shift 2
29+
;;
30+
--itk-repo)
31+
ITK_REPO="$2"
32+
shift 2
33+
;;
34+
--ipp-branch)
35+
IPP_BRANCH="$2"
36+
shift 2
37+
;;
38+
--ipp-repo)
39+
IPP_REPO="$2"
40+
shift 2
41+
;;
42+
*)
43+
echo "Unknown option: $1"
44+
exit 1
45+
;;
2846
esac
2947
done
3048

@@ -63,7 +81,7 @@ for rc in "${WORKDIR}"/ITK/Modules/Remote/*.remote.cmake; do
6381
if [ -d "${MODULES_DIR}/${name}/wrapping" ] && [ -f "${MODULES_DIR}/${name}/pyproject.toml" ]; then
6482
module_list+=("${name}")
6583
else
66-
rm -rf "${MODULES_DIR}/${name}"
84+
rm -rf "${MODULES_DIR:?}/${name}"
6785
fi
6886
else
6987
echo " WARNING: Failed to clone ${name}, skipping"
@@ -111,7 +129,7 @@ done
111129
echo ""
112130
echo "=== Build complete ==="
113131
echo "Wheels: ${DIST_DIR}"
114-
ls -1 "${DIST_DIR}"/*.whl 2>/dev/null | wc -l
132+
find "${DIST_DIR}" -maxdepth 1 -name '*.whl' | wc -l
115133
echo "total wheels produced"
116134

117135
if [ ${#failed_modules[@]} -gt 0 ]; then

Utilities/scripts/build_all_latest_wheels.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ 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, depth: int | None = 1) -> bool:
24+
def clone(
25+
repo: str, dest: Path, branch: str | None = None, depth: int | None = 1
26+
) -> bool:
2527
cmd = ["git", "clone"]
2628
if depth is not None:
2729
cmd += ["--depth", str(depth)]

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ bump_map = { "ENH" = "MINOR", "BUG" = "PATCH", "COMP" = "PATCH", "PERF" = "PATCH
3333
commit_parser = "^(?P<change_type>BUG|COMP|DOC|ENH|PERF|STYLE): (?P<message>.*)"
3434
changelog_pattern = "^(BUG|COMP|DOC|ENH|PERF|STYLE)?(!)?"
3535
change_type_map = { "ENH" = "Enhancements", "BUG" = "Bug Fixes", "COMP" = "Build Fixes", "DOC" = "Documentation", "PERF" = "Performance", "STYLE" = "Style" }
36-
change_type_order = ["Enhancements", "Bug Fixes", "Build Fixes", "Performance", "Documentation", "Style"]
36+
change_type_order = [
37+
"Enhancements",
38+
"Bug Fixes",
39+
"Build Fixes",
40+
"Performance",
41+
"Documentation",
42+
"Style",
43+
]
3744
info = """
3845
ITK commit message convention: PREFIX: Description
3946

scripts/build_python_instance_base.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,7 @@ def _update_module_itk_deps(pyproject_path: Path, itk_version: str) -> bool:
728728
pyproject_data = tomllib.load(f)
729729

730730
# --- Strategy 3: module declares dynamic dependencies -----------------
731-
dynamic_fields = (
732-
pyproject_data.get("project", {}).get("dynamic", [])
733-
)
731+
dynamic_fields = pyproject_data.get("project", {}).get("dynamic", [])
734732
if "dependencies" in dynamic_fields:
735733
# The module has opted into dynamic dependency resolution.
736734
# Set ITK_PACKAGE_VERSION in the environment so the
@@ -739,7 +737,7 @@ def _update_module_itk_deps(pyproject_path: Path, itk_version: str) -> bool:
739737
os.environ["ITK_PACKAGE_VERSION"] = itk_version
740738
print(
741739
f"Strategy 3: {pyproject_path.name} declares "
742-
f"dynamic=[\"dependencies\"]; set ITK_PACKAGE_VERSION="
740+
f'dynamic=["dependencies"]; set ITK_PACKAGE_VERSION='
743741
f"{itk_version} for metadata provider"
744742
)
745743
return False # no file modification needed
@@ -760,9 +758,7 @@ def _update_module_itk_deps(pyproject_path: Path, itk_version: str) -> bool:
760758
"itk-segmentation",
761759
)
762760
_base_pkg_alt = "|".join(re.escape(p) for p in _ITK_BASE_PACKAGES)
763-
pattern = re.compile(
764-
rf'"({_base_pkg_alt})\s*==\s*[\d]+\.[\d]+\.\*"'
765-
)
761+
pattern = re.compile(rf'"({_base_pkg_alt})\s*==\s*[\d]+\.[\d]+\.\*"')
766762

767763
# Warn about pinned remote-module cross-deps that may also need
768764
# attention but should not be auto-rewritten.
@@ -790,6 +786,7 @@ def _update_module_itk_deps(pyproject_path: Path, itk_version: str) -> bool:
790786
min_floor = itk_version
791787

792788
changed = False
789+
793790
def _replace(m: re.Match) -> str:
794791
nonlocal changed
795792
changed = True
@@ -822,9 +819,7 @@ def build_external_module_python_wheel(self):
822819
itk_ver = self.package_env_config.get("ITK_PACKAGE_VERSION", "")
823820
if itk_ver:
824821
shutil.copy2(module_pyproject, pyproject_orig)
825-
deps_rewritten = self._update_module_itk_deps(
826-
module_pyproject, itk_ver
827-
)
822+
deps_rewritten = self._update_module_itk_deps(module_pyproject, itk_ver)
828823

829824
# Ensure venv tools are first in PATH
830825
py_exe = str(self.package_env_config["PYTHON_EXECUTABLE"]) # Python3_EXECUTABLE

0 commit comments

Comments
 (0)