Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,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"]
Expand All @@ -37,8 +40,33 @@ repos:
^monai/_version.py
)

- repo: https://github.com/hadialqattan/pycln
rev: v2.6.0
- 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
)

- repo: https://github.com/facebook/pyrefly-pre-commit
rev: 1.3.0.dev2 # The pyrefly version to use
hooks:
- id: pycln
args: [--config=pyproject.toml]
- id: pyrefly-check
name: Pyrefly (type checking)
pass_filenames: false
additional_dependencies: ["numpy>=1.24,<3.0"] # omitted "torch>=2.8.0" to fit into venv pre-commit provides
51 changes: 27 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -130,7 +131,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
Comment thread
ericspod marked this conversation as resolved.
]
onnx = ["onnx>=1.13.0", "onnxruntime; python_version <= '3.10'", "onnx_graphsurgeon", "onnxscript"]
openslide = ["openslide-python", "openslide-bin"]
Expand Down Expand Up @@ -161,7 +163,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",
Expand All @@ -170,9 +172,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"
]
Expand Down Expand Up @@ -299,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]
Expand All @@ -334,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
Expand Down
2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down