Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 3d8bac6

Browse files
authored
Update tests, CI and pre-commit (#193)
* Add initial runtests.sh * Duplicate utils to remove necessity to clone MONAI in order to run tests * Add note * [WIP] Add tests runners * Update min_tests list and reduce tests scope * Use all environments tested in monai core * Update pre-commit and requirements for tests * Remove duplicated tqdm and move lpips to dev * Remove test_latent_diffusion_inferer.py from min tests * Try to fix requirements for min tests * Fix dependencies * Add test_diffusion_inferer to excluded min-tests * Update CONTRIBUTING.md * Fix typos, remove formatting from unit tests and add black and isort to pre-commit Signed-off-by: Walter Hugo Lopez Pinaya <[email protected]>
1 parent 7ef9d8e commit 3d8bac6

15 files changed

+2260
-43
lines changed

.clang-format

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 120
39+
CommentPragmas: '^ IWYU pragma:'
40+
CompactNamespaces: false
41+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
42+
ConstructorInitializerIndentWidth: 4
43+
ContinuationIndentWidth: 4
44+
Cpp11BracedListStyle: true
45+
DerivePointerAlignment: false
46+
DisableFormat: false
47+
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
48+
IncludeCategories:
49+
- Regex: '^<.*\.h(pp)?>'
50+
Priority: 1
51+
- Regex: '^<.*'
52+
Priority: 2
53+
- Regex: '.*'
54+
Priority: 3
55+
IndentCaseLabels: true
56+
IndentWidth: 2
57+
IndentWrappedFunctionNames: false
58+
KeepEmptyLinesAtTheStartOfBlocks: false
59+
MacroBlockBegin: ''
60+
MacroBlockEnd: ''
61+
MaxEmptyLinesToKeep: 1
62+
NamespaceIndentation: None
63+
ObjCBlockIndentWidth: 2
64+
ObjCSpaceAfterProperty: false
65+
ObjCSpaceBeforeProtocolList: false
66+
PenaltyBreakBeforeFirstCallParameter: 1
67+
PenaltyBreakComment: 300
68+
PenaltyBreakFirstLessLess: 120
69+
PenaltyBreakString: 1000
70+
PenaltyExcessCharacter: 1000000
71+
PenaltyReturnTypeOnItsOwnLine: 2000000
72+
PointerAlignment: Left
73+
ReflowComments: true
74+
SortIncludes: true
75+
SpaceAfterCStyleCast: false
76+
SpaceBeforeAssignmentOperators: true
77+
SpaceBeforeParens: ControlStatements
78+
SpaceInEmptyParentheses: false
79+
SpacesBeforeTrailingComments: 1
80+
SpacesInAngles: false
81+
SpacesInContainerLiterals: true
82+
SpacesInCStyleCastParentheses: false
83+
SpacesInParentheses: false
84+
SpacesInSquareBrackets: false
85+
Standard: Cpp11
86+
TabWidth: 8
87+
UseTab: Never
88+
...

.deepsource.toml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version = 1
2+
3+
test_patterns = ["tests/**"]
4+
5+
[[analyzers]]
6+
name = "python"
7+
enabled = true
8+
9+
[analyzers.meta]
10+
runtime_version = "3.x.x"
11+
12+
[[analyzers]]
13+
name = "test-coverage"
14+
enabled = true
15+
16+
[[analyzers]]
17+
name = "docker"
18+
enabled = true
19+
20+
[[analyzers]]
21+
name = "shell"
22+
enabled = true

.github/workflows/pythonapp-min.yml

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Jenkinsfile.monai-premerge
2+
name: premerge-min
3+
4+
on:
5+
# quick tests for pull requests and the releasing branches
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
concurrency:
12+
# automatically cancel the previously triggered workflows when there's a newer version
13+
group: build-min-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
# caching of these jobs:
18+
# - docker-py3-pip- (shared)
19+
# - ubuntu py37 pip-
20+
# - os-latest-pip- (shared)
21+
min-dep-os: # min dependencies installed tests for different OS
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [windows-latest, macOS-latest, ubuntu-latest]
27+
timeout-minutes: 40
28+
steps:
29+
- uses: actions/checkout@v3
30+
- name: Set up Python 3.8
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.8'
34+
- name: Prepare pip wheel
35+
run: |
36+
which python
37+
python -m pip install --upgrade pip wheel
38+
- name: cache weekly timestamp
39+
id: pip-cache
40+
run: |
41+
echo "datew=$(date '+%Y-%V')" >> $GITHUB_OUTPUT
42+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
43+
shell: bash
44+
- name: cache for pip
45+
uses: actions/cache@v3
46+
id: cache
47+
with:
48+
path: ${{ steps.pip-cache.outputs.dir }}
49+
key: ${{ matrix.os }}-latest-pip-${{ steps.pip-cache.outputs.datew }}
50+
- if: runner.os == 'windows'
51+
name: Install torch cpu from pytorch.org (Windows only)
52+
run: |
53+
python -m pip install torch==1.13.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
54+
- name: Install the dependencies
55+
run: |
56+
# min. requirements
57+
python -m pip install torch==1.13.1
58+
python -m pip install -r requirements-min.txt
59+
python -m pip list
60+
BUILD_MONAI=0 python setup.py develop # no compile of extensions
61+
shell: bash
62+
- name: Run quick tests (CPU ${{ runner.os }})
63+
run: |
64+
python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))'
65+
python -c "import monai; monai.config.print_config()"
66+
./runtests.sh --min
67+
shell: bash
68+
env:
69+
QUICKTEST: True
70+
71+
min-dep-py3: # min dependencies installed tests for different python
72+
runs-on: ubuntu-latest
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
77+
timeout-minutes: 40
78+
steps:
79+
- uses: actions/checkout@v3
80+
- name: Set up Python ${{ matrix.python-version }}
81+
uses: actions/setup-python@v4
82+
with:
83+
python-version: ${{ matrix.python-version }}
84+
- name: Prepare pip wheel
85+
run: |
86+
which python
87+
python -m pip install --user --upgrade pip setuptools wheel
88+
- name: cache weekly timestamp
89+
id: pip-cache
90+
run: |
91+
echo "datew=$(date '+%Y-%V')" >> $GITHUB_OUTPUT
92+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
93+
shell: bash
94+
- name: cache for pip
95+
uses: actions/cache@v3
96+
id: cache
97+
with:
98+
path: ${{ steps.pip-cache.outputs.dir }}
99+
key: ubuntu-latest-latest-pip-${{ steps.pip-cache.outputs.datew }}
100+
- name: Install the dependencies
101+
run: |
102+
# min. requirements
103+
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
104+
python -m pip install -r requirements-min.txt
105+
python -m pip list
106+
BUILD_MONAI=0 python setup.py develop # no compile of extensions
107+
shell: bash
108+
- name: Run quick tests (CPU ${{ runner.os }})
109+
run: |
110+
python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))'
111+
python -c "import monai; monai.config.print_config()"
112+
./runtests.sh --min
113+
env:
114+
QUICKTEST: True
115+
116+
min-dep-pytorch: # min dependencies installed tests for different pytorch
117+
runs-on: ubuntu-latest
118+
strategy:
119+
fail-fast: false
120+
matrix:
121+
pytorch-version: ['1.8.2', '1.9.1', '1.10.2', '1.11.0', '1.12.1', 'latest']
122+
timeout-minutes: 40
123+
steps:
124+
- uses: actions/checkout@v3
125+
- name: Set up Python 3.8
126+
uses: actions/setup-python@v4
127+
with:
128+
python-version: '3.8'
129+
- name: Prepare pip wheel
130+
run: |
131+
which python
132+
python -m pip install --user --upgrade pip setuptools wheel
133+
- name: cache weekly timestamp
134+
id: pip-cache
135+
run: |
136+
echo "datew=$(date '+%Y-%V')" >> $GITHUB_OUTPUT
137+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
138+
shell: bash
139+
- name: cache for pip
140+
uses: actions/cache@v3
141+
id: cache
142+
with:
143+
path: ${{ steps.pip-cache.outputs.dir }}
144+
key: ubuntu-latest-latest-pip-${{ steps.pip-cache.outputs.datew }}
145+
- name: Install the dependencies
146+
run: |
147+
# min. requirements
148+
if [ ${{ matrix.pytorch-version }} == "latest" ]; then
149+
python -m pip install torch
150+
elif [ ${{ matrix.pytorch-version }} == "1.8.2" ]; then
151+
python -m pip install torch==1.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
152+
elif [ ${{ matrix.pytorch-version }} == "1.9.1" ]; then
153+
python -m pip install torch==1.9.1
154+
elif [ ${{ matrix.pytorch-version }} == "1.10.2" ]; then
155+
python -m pip install torch==1.10.2
156+
elif [ ${{ matrix.pytorch-version }} == "1.11.0" ]; then
157+
python -m pip install torch==1.11.0
158+
elif [ ${{ matrix.pytorch-version }} == "1.12.1" ]; then
159+
python -m pip install torch==1.12.1
160+
fi
161+
python -m pip install -r requirements-min.txt
162+
python -m pip list
163+
BUILD_MONAI=0 python setup.py develop # no compile of extensions
164+
shell: bash
165+
- name: Run quick tests (pytorch ${{ matrix.pytorch-version }})
166+
run: |
167+
python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))'
168+
python -c "import monai; monai.config.print_config()"
169+
./runtests.sh --min
170+
env:
171+
QUICKTEST: True

.pre-commit-config.yaml

+48-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
default_language_version:
2+
python: python3.8
3+
4+
ci:
5+
autofix_prs: true
6+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
7+
autoupdate_schedule: quarterly
8+
# submodules: true
9+
110
repos:
211
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
12+
rev: v4.4.0
413
hooks:
514
- id: end-of-file-fixer
615
- id: trailing-whitespace
@@ -17,24 +26,49 @@ repos:
1726
args: ['--autofix', '--no-sort-keys', '--indent=4']
1827
- id: end-of-file-fixer
1928
- id: mixed-line-ending
29+
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: v3.3.1
32+
hooks:
33+
- id: pyupgrade
34+
args: [--py37-plus]
35+
name: Upgrade code
36+
exclude: |
37+
(?x)^(
38+
versioneer.py|
39+
monai/_version.py
40+
)$
41+
42+
- repo: https://github.com/asottile/yesqa
43+
rev: v1.4.0
44+
hooks:
45+
- id: yesqa
46+
name: Unused noqa
47+
additional_dependencies:
48+
- flake8>=3.8.1
49+
- flake8-bugbear
50+
- flake8-comprehensions
51+
- flake8-executable
52+
- flake8-pyi
53+
- pep8-naming
54+
exclude: |
55+
(?x)^(
56+
generative/__init__.py|
57+
docs/source/conf.py
58+
)$
59+
60+
- repo: https://github.com/hadialqattan/pycln
61+
rev: v2.1.2
62+
hooks:
63+
- id: pycln
64+
args: [--config=pyproject.toml]
65+
2066
- repo: https://github.com/psf/black
2167
rev: 22.3.0
2268
hooks:
2369
- id: black
70+
2471
- repo: https://github.com/PyCQA/isort
2572
rev: 5.9.3
2673
hooks:
2774
- id: isort
28-
- repo: https://github.com/PyCQA/flake8
29-
rev: 3.9.2
30-
hooks:
31-
- id: flake8
32-
args: # arguments to configure flake8
33-
# these are errors that will be ignored by flake8
34-
# check out their meaning here
35-
# https://flake8.pycqa.org/en/latest/user/error-codes.html
36-
- "--ignore=E203,E266,E501,W503,E731,F541,F841"
37-
# Adding args to work with black format
38-
- "--max-line-length=120"
39-
- "--max-complexity=18"
40-
- "--per-file-ignores=__init__.py:F401"

0 commit comments

Comments
 (0)