From c36754d66b4d45b0f38fefeaf7e3a25faa25016e Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:53:43 +0100 Subject: [PATCH 1/8] Adding black and isort hooks Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 25 +++++++++++++++++++++++++ requirements-dev.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2d78b08041..ade7ac1e09 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,11 +13,13 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace + - id: check-ast - id: check-yaml - id: check-docstring-first - id: check-executables-have-shebangs - id: check-toml - id: check-case-conflict + - id: check-illegal-windows-names - id: check-added-large-files args: ['--maxkb=1024'] - id: detect-private-key @@ -42,3 +44,26 @@ repos: hooks: - id: pycln args: [--config=pyproject.toml] + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.5.1 # Black version, keep synced with MONAI requirements + hooks: + - id: black + language_version: python3 + # black will be given individual file names and so will ignore the excludes in pyproject.toml + exclude: | + (?x)( + ^versioneer.py| + ^monai/_version.py + ) + + - repo: https://github.com/pycqa/isort + rev: 8.0.1 # isort version, keep synced with MONAI requirements + hooks: + - id: isort + name: isort (python) + exclude: | + (?x)( + ^versioneer.py| + ^monai/_version.py + ) diff --git a/requirements-dev.txt b/requirements-dev.txt index c46648006b..6dd207fef8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -15,7 +15,7 @@ pep8-naming pycodestyle pyflakes black>=26.3.1 -isort>=5.1, <6, !=6.0.0 +isort>=5.1, !=6.0.0 ruff>=0.14.11,<0.15 pybind11 setuptools<71 # pkg_resources removed in setuptools>=71; needed by MetricsReloaded setup.py From 5a374fd90aec23f8938e2087895e3a0166944d7a Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Tue, 18 Aug 2026 11:57:52 +0100 Subject: [PATCH 2/8] Remove version change temporarily Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 6dd207fef8..c46648006b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -15,7 +15,7 @@ pep8-naming pycodestyle pyflakes black>=26.3.1 -isort>=5.1, !=6.0.0 +isort>=5.1, <6, !=6.0.0 ruff>=0.14.11,<0.15 pybind11 setuptools<71 # pkg_resources removed in setuptools>=71; needed by MetricsReloaded setup.py From 9e45b57c777993d53914634b443f78dc34568c68 Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Tue, 18 Aug 2026 12:16:27 +0100 Subject: [PATCH 3/8] Slight version tweak Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 3 ++- pyproject.toml | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ade7ac1e09..c708fa1835 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,8 +28,9 @@ repos: args: ['--autofix', '--no-sort-keys', '--indent=4'] - id: end-of-file-fixer - id: mixed-line-ending + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.20 + rev: v0.16.3 hooks: - id: ruff-check args: ["--fix"] diff --git a/pyproject.toml b/pyproject.toml index 9c5f892283..52d17cafcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,7 +130,8 @@ mlflow = ["mlflow>=2.12.2,<3.13"] nibabel = ["nibabel"] nni = [ "nni; platform_system == 'Linux' and 'arm' not in platform_machine and 'aarch' not in platform_machine", - "filelock<3.12.0" # https://github.com/microsoft/nni/issues/5523 + "filelock<3.12.0", # https://github.com/microsoft/nni/issues/5523 + "typeguard<3" # https://github.com/microsoft/nni/issues/5457 ] onnx = ["onnx>=1.13.0", "onnxruntime; python_version <= '3.10'", "onnx_graphsurgeon", "onnxscript"] openslide = ["openslide-python", "openslide-bin"] @@ -161,7 +162,7 @@ zarr = ["zarr"] testing = [ "black>=26.3.1", "coverage>=5.5", - "isort>=5.1,<6,!=6.0.0", + "isort>=5.1,!=6.0.0", "mccabe", "packaging", "parameterized", @@ -170,9 +171,8 @@ testing = [ "pycodestyle", "pyflakes", "pyrefly>=1.0.0", - "ruff>=0.14.11,<0.15", + "ruff>=0.14.11", "tomli", # used in print_dependencies.py for Python<3.11 - "typeguard<3", # https://github.com/microsoft/nni/issues/5457 "types-PyYAML", "types-setuptools" ] From bd46ed87f8319f96f85f779952fe0885472f321c Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Tue, 18 Aug 2026 12:26:57 +0100 Subject: [PATCH 4/8] Fix Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 52d17cafcf..1c5b84ce7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,6 +104,7 @@ all = [ "torchvision", "tqdm>=4.47.0", "transformers>=4.53.0, <5.0", + "typeguard<3", # https://github.com/microsoft/nni/issues/5457 "zarr" ] clearml = ["clearml>=1.10.0rc0"] From 2da2d0fd6eb7cf80925f1f66c410507c341e5af1 Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Wed, 19 Aug 2026 10:51:42 +0100 Subject: [PATCH 5/8] replace pycln with ruff F401 Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 6 ------ pyproject.toml | 42 +++++++++++++++++++++-------------------- runtests.sh | 2 +- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c708fa1835..976cbeeb93 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,12 +40,6 @@ repos: ^monai/_version.py ) - - repo: https://github.com/hadialqattan/pycln - rev: v2.6.0 - hooks: - - id: pycln - args: [--config=pyproject.toml] - - repo: https://github.com/psf/black-pre-commit-mirror rev: 26.5.1 # Black version, keep synced with MONAI requirements hooks: diff --git a/pyproject.toml b/pyproject.toml index 1c5b84ce7e..0591374bc4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -300,29 +300,29 @@ target-version = "py310" [tool.ruff.lint] select = [ - "B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b - "C90", # mccabe (complexity) - https://docs.astral.sh/ruff/rules/#mccabe-c90 - "E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e - "F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f - "N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n - "PIE", # flake8-pie - https://docs.astral.sh/ruff/rules/#flake8-pie-pie - "TID", # flake8-tidy-imports - https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid - "W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w - "NPY", # NumPy specific rules - "UP", # pyupgrade - "RUF100", # aka yesqa + "B", # flake8-bugbear - https://docs.astral.sh/ruff/rules/#flake8-bugbear-b + "C90", # mccabe (complexity) - https://docs.astral.sh/ruff/rules/#mccabe-c90 + "E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e + "F", # pyflakes - https://docs.astral.sh/ruff/rules/#pyflakes-f + "N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n + "PIE", # flake8-pie - https://docs.astral.sh/ruff/rules/#flake8-pie-pie + "TID", # flake8-tidy-imports - https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid + "W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w + "NPY", # NumPy specific rules - https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy + "UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up + "RUF100", # aka yesqa - https://docs.astral.sh/ruff/rules/unused-noqa/ + "F401", # unused imports - https://docs.astral.sh/ruff/rules/unused-import/ ] extend-ignore = [ - "E741", # ambiguous variable name - "F401", # unused import + "E741", # ambiguous variable name "NPY002", # numpy-legacy-random - "E203", # whitespace before ':' (pycodestyle) - "E501", # line too long (pycodestyle) - "C408", # unnecessary collection call (flake8-comprehensions) - "N812", # lowercase imported as non lowercase (pep8-naming) - "B023", # function uses loop variable (flake8-bugbear) - "B905", # zip() without an explicit strict= parameter (flake8-bugbear) - "B028", # no explicit stacklevel keyword argument found (flake8-bugbear) + "E203", # whitespace before ':' (pycodestyle) + "E501", # line too long (pycodestyle) + "C408", # unnecessary collection call (flake8-comprehensions) + "N812", # lowercase imported as non lowercase (pep8-naming) + "B023", # function uses loop variable (flake8-bugbear) + "B905", # zip() without an explicit strict= parameter (flake8-bugbear) + "B028", # no explicit stacklevel keyword argument found (flake8-bugbear) ] [tool.ruff.lint.per-file-ignores] @@ -335,6 +335,8 @@ extend-ignore = [ "monai/apps/detection/utils/ATSS_matcher.py" = [ "N999" ] +"__init__.py" = ["F401"] # TODO: change importation in __init__.py files to suit F401 +"monai/bundle/__main__.py" = ["F401"] [tool.ruff.lint.mccabe] max-complexity = 50 # todo lower this treshold when yesqa id replaced with Ruff's RUF100 diff --git a/runtests.sh b/runtests.sh index 73508a093b..0fc18b36ec 100755 --- a/runtests.sh +++ b/runtests.sh @@ -221,7 +221,7 @@ function print_style_fail_msg() { echo "${red}Check failed!${noColor}" if [ "$homedir" = "$currentdir" ] then - echo "Please run auto style fixes: ${green}./runtests.sh --autofix${noColor}" + echo "Please run auto style fixes if necessary: ${green}./runtests.sh --autofix${noColor}" else : fi } From 5924f9155a8f14f5b63d5bb3e593349b3fc8f583 Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:14:04 +0100 Subject: [PATCH 6/8] Adding pyrefly repo Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 976cbeeb93..77d68c97f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,3 +62,11 @@ repos: ^versioneer.py| ^monai/_version.py ) + + - repo: https://github.com/facebook/pyrefly-pre-commit + rev: 1.3.0.dev2 # The pyrefly version to use + hooks: + - id: pyrefly-check + name: Pyrefly (type checking) + pass_filenames: false + additional_dependencies: [ ] # Your project's dependencies From a10bf760e0669fdac921f28c0a2bce696341bb6e Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:50:19 +0100 Subject: [PATCH 7/8] Adding deps Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 77d68c97f8..491a5bca33 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,4 +69,4 @@ repos: - id: pyrefly-check name: Pyrefly (type checking) pass_filenames: false - additional_dependencies: [ ] # Your project's dependencies + additional_dependencies: ["torch>=2.8.0", "numpy>=1.24,<3.0"] From 2f3d6d91e4bb9711f2b696ec0563e6e7ecd8ddd3 Mon Sep 17 00:00:00 2001 From: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Date: Wed, 19 Aug 2026 19:32:21 +0100 Subject: [PATCH 8/8] venv fix Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 491a5bca33..aafc8fd29f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,4 +69,4 @@ repos: - id: pyrefly-check name: Pyrefly (type checking) pass_filenames: false - additional_dependencies: ["torch>=2.8.0", "numpy>=1.24,<3.0"] + additional_dependencies: ["numpy>=1.24,<3.0"] # omitted "torch>=2.8.0" to fit into venv pre-commit provides