You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Admin tasks (for the maintainers)](#admin-tasks)
16
-
*[Releasing a new version](#release-a-new-version)
16
+
-[Releasing a new version](#release-a-new-version)
17
17
18
18
## Introduction
19
19
20
-
21
20
Welcome to Project MONAI! We're excited you're here and want to contribute. This documentation is intended for individuals and institutions interested in contributing to MONAI. MONAI is an open-source project and, as such, its success relies on its community of contributors willing to keep improving it. Your contribution will be a valued addition to the code base; we simply ask that you read this page and understand our contribution process, whether you are a seasoned open-source contributor or whether you are a first-time contributor.
22
21
23
22
### Communicate with us
@@ -30,24 +29,25 @@ MONAI is part of [PyTorch Ecosystem](https://pytorch.org/ecosystem/), and mainly
30
29
31
30
## The contribution process
32
31
33
-
_Pull request early_
32
+
*Pull request early*
34
33
35
34
We encourage you to create pull requests early. It helps us track the contributions under development, whether they are ready to be merged or not. [Create a draft pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request) until it is ready for formal review.
36
35
37
36
Please note that, as per PyTorch, MONAI uses American English spelling. This means classes and variables should be: normali**z**e, visuali**z**e, colo~~u~~r, etc.
38
37
39
38
### Preparing pull requests
39
+
40
40
To ensure the code quality, MONAI relies on several linting tools ([flake8 and its plugins](https://gitlab.com/pycqa/flake8), [black](https://github.com/psf/black), [isort](https://github.com/timothycrosley/isort), [ruff](https://github.com/astral-sh/ruff)),
41
41
static type analysis tools ([mypy](https://github.com/python/mypy), [pytype](https://github.com/google/pytype)), as well as a set of unit/integration tests.
42
42
43
43
This section highlights all the necessary preparation steps required before sending a pull request.
44
44
To collaborate efficiently, please read through this section and follow them.
45
45
46
-
*[Checking the coding style](#checking-the-coding-style)
Full linting and type checking may take some time. If you need a quick check, run
70
+
70
71
```bash
71
72
# run ruff only
72
73
./runtests.sh --ruff
73
74
```
74
75
75
76
#### Licensing information
77
+
76
78
All source code files should start with this paragraph:
77
79
78
80
```
@@ -97,6 +99,7 @@ If you intend for any variables/functions/classes to be available outside of the
97
99
- Add to the `__init__.py` file.
98
100
99
101
#### Unit testing
102
+
100
103
MONAI tests are located under `tests/`.
101
104
102
105
- The unit test's file name currently follows `test_[module_name].py` or `test_[module_name]_dist.py`.
@@ -107,6 +110,7 @@ A bash script (`runtests.sh`) is provided to run all tests locally.
107
110
Please run ``./runtests.sh -h`` to see all options.
108
111
109
112
To run a particular test, for example `tests/losses/test_dice_loss.py`:
113
+
110
114
```
111
115
python -m tests.losses.test_dice_loss
112
116
```
@@ -117,6 +121,7 @@ should pass, by running the following command locally:
117
121
```bash
118
122
./runtests.sh -f -u --net --coverage
119
123
```
124
+
120
125
or (for new features that would not break existing functionality):
121
126
122
127
```bash
@@ -126,17 +131,19 @@ or (for new features that would not break existing functionality):
126
131
It is recommended that the new test `test_[module_name].py` is constructed by using only
127
132
python 3.9+ build-in functions, `torch`, `numpy`, `coverage` (for reporting code coverages) and `parameterized` (for organising test cases) packages.
128
133
If it requires any other external packages, please make sure:
134
+
129
135
- the packages are listed in [`requirements-dev.txt`](requirements-dev.txt)
130
136
- the new test `test_[module_name].py` is added to the `exclude_cases` in [`./tests/min_tests.py`](./tests/min_tests.py) so that
131
137
the minimal CI runner will not execute it.
132
138
133
139
##### Testing data
140
+
134
141
Testing data such as images and binary files should not be placed in the source code repository.
135
142
Please deploy them to a reliable file sharing location (the current preferred one is [https://github.com/Project-MONAI/MONAI-extra-test-data/releases](https://github.com/Project-MONAI/MONAI-extra-test-data/releases)).
136
143
At test time, the URLs within `tests/testing_data/data_config.json` are accessible
137
144
via the APIs provided in `tests.utils`: `tests.utils.testing_data_config` and `tests.utils.download_url_or_skip_test`.
138
145
139
-
_If it's not tested, it's broken_
146
+
*If it's not tested, it's broken*
140
147
141
148
All new functionality should be accompanied by an appropriate set of tests.
142
149
MONAI functionality has plenty of unit tests from which you can draw inspiration,
@@ -145,6 +152,7 @@ and you can reach out to us if you are unsure of how to proceed with testing.
145
152
MONAI's code coverage report is available at [CodeCov](https://codecov.io/gh/Project-MONAI/MONAI).
The above commands build html documentation, they are used to automatically generate [https://docs.monai.io](https://docs.monai.io).
160
169
161
170
The Python code docstring are written in
162
171
[reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) and
163
172
the documentation pages can be in either [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) or [Markdown](https://en.wikipedia.org/wiki/Markdown). In general the Python docstrings follow the [Google style](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings).
164
173
165
174
Before submitting a pull request, it is recommended to:
175
+
166
176
- edit the relevant `.rst` files in [`docs/source`](./docs/source) accordingly.
167
177
- build html documentation locally
168
178
- check the auto-generated documentation (by browsing `./docs/build/html/index.html` with a web browser)
@@ -171,11 +181,13 @@ Before submitting a pull request, it is recommended to:
171
181
Please type `make help` in `docs/` folder for all supported format options.
172
182
173
183
#### Automatic code formatting
184
+
174
185
MONAI provides support of automatic Python code formatting via [a customised GitHub action](https://github.com/Project-MONAI/monai-code-formatter).
175
186
This makes the project's Python coding style consistent and reduces maintenance burdens.
176
187
Commenting a pull request with `/black` triggers the formatting action based on [`psf/Black`](https://github.com/psf/black) (this is implemented with [`slash command dispatch`](https://github.com/marketplace/actions/slash-command-dispatch)).
177
188
178
189
Steps for the formatting process:
190
+
179
191
- After submitting a pull request or push to an existing pull request,
180
192
make a comment to the pull request to trigger the formatting action.
181
193
The first line of the comment must be `/black` so that it will be interpreted by [the comment parser](https://github.com/marketplace/actions/slash-command-dispatch#how-are-comments-parsed-for-slash-commands).
@@ -184,11 +196,13 @@ The first line of the comment must be `/black` so that it will be interpreted by
184
196
- Repeat the above steps if necessary.
185
197
186
198
#### Adding new optional dependencies
199
+
187
200
In addition to the minimal requirements of PyTorch and Numpy, MONAI's core modules are built optionally based on 3rd-party packages.
188
201
The current set of dependencies is listed in [installing dependencies](https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies).
189
202
190
203
To allow for flexible integration of MONAI with other systems and environments,
191
204
the optional dependency APIs are always invoked lazily. For example,
205
+
192
206
```py
193
207
from monai.utils import optional_import
194
208
itk, _ = optional_import("itk", ...)
@@ -198,11 +212,13 @@ class ITKReader(ImageReader):
198
212
defread(self, ...):
199
213
return itk.imread(...)
200
214
```
215
+
201
216
The availability of the external `itk.imread` API is not required unless `monai.data.ITKReader.read` is called by the user.
202
217
Integration tests with minimal requirements are deployed to ensure this strategy.
203
218
204
219
To add new optional dependencies, please communicate with the core team during pull request reviews,
205
220
and add the necessary information (at least) to the following files:
It skips the test cases when `matplotlib.pyplot` APIs are not available.
223
241
224
242
Alternatively, add the test file name to the ``exclude_cases`` in `tests/min_tests.py` to completely skip the test
225
243
cases when running in a minimal setup.
226
244
227
-
228
-
229
245
#### Signing your work
246
+
230
247
MONAI enforces the [Developer Certificate of Origin](https://developercertificate.org/) (DCO) on all pull requests.
231
248
All commit messages should contain the `Signed-off-by` line with an email address. The [GitHub DCO app](https://github.com/apps/dco) is deployed on MONAI. The pull request's status will be `failed` if commits do not contain a valid `Signed-off-by` line.
232
249
233
250
Git has a `-s` (or `--signoff`) command-line option to append this automatically to your commit message:
251
+
234
252
```bash
235
253
git commit -s -m 'a new commit'
236
254
```
255
+
237
256
The commit message will be:
257
+
238
258
```
239
259
a new commit
240
260
241
261
Signed-off-by: Your Name <yourname@example.org>
242
262
```
243
263
244
264
Full text of the DCO:
265
+
245
266
```
246
267
Developer Certificate of Origin
247
268
Version 1.1
@@ -283,24 +304,28 @@ By making a contribution to this project, I certify that:
283
304
```
284
305
285
306
#### Utility functions
307
+
286
308
MONAI provides a set of generic utility functions and frequently used routines.
287
309
These are located in [``monai/utils``](./monai/utils/) and in the module folders such as [``networks/utils.py``](./monai/networks/).
288
310
Users are encouraged to use these common routines to improve code readability and reduce the code maintenance burdens.
289
311
290
312
Notably,
313
+
291
314
-``monai.module.export`` decorator can make the module name shorter when importing,
292
315
for example, ``import monai.transforms.Spacing`` is the equivalent of ``monai.transforms.spatial.array.Spacing`` if
293
316
``class Spacing`` defined in file `monai/transforms/spatial/array.py` is decorated with ``@export("monai.transforms")``.
294
317
295
318
For string definition, [f-string](https://www.python.org/dev/peps/pep-0498/) is recommended to use over `%-print` and `format-print`. So please try to use `f-string` if you need to define any string object.
296
319
297
320
#### Backwards compatibility
321
+
298
322
MONAI in general follows [PyTorch's policy for backward compatibility](https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy).
299
323
Utility functions are provided in `monai.utils.deprecated` to help migrate from the deprecated to new APIs. The use of these utilities is encouraged.
300
324
The pull request [template contains checkboxes](https://github.com/Project-MONAI/MONAI/blame/dev/.github/pull_request_template.md#L11-L12) that
301
325
the contributor should use accordingly to clearly indicate breaking changes.
302
326
303
327
The process of releasing backwards incompatible API changes is as follows:
328
+
304
329
1. discuss the breaking changes during pull requests or in dev meetings with a feature proposal if needed.
305
330
1. add a warning message in the upcoming release (version `X.Y`), the warning message should include a forecast of removing the deprecated API in:
306
331
1.`X+1.0` -- major version `X+1` and minor version `0` the next major version if it's a significant change,
@@ -314,10 +339,10 @@ The process of releasing backwards incompatible API changes is as follows:
314
339
1. collect feedback from the users during the subsequent few releases, and reconsider step 1 if needed.
315
340
1. before each release, review the deprecating APIs and relevant tests, and clean up the removed APIs described in step 2.
316
341
317
-
318
-
319
342
### Submitting pull requests
343
+
320
344
All code changes to the dev branch must be done via [pull requests](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests).
345
+
321
346
1. Create a new ticket or take a known ticket from [the issue list][monai issue list].
322
347
1. Check if there's already a branch dedicated to the task.
323
348
1. If the task has not been taken, [create a new branch in your fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork)
@@ -335,9 +360,10 @@ Ideally, the new branch should be based on the latest `dev` branch.
335
360
336
361
## The code reviewing process
337
362
338
-
339
363
### Reviewing pull requests
364
+
340
365
All code review comments should be specific, constructive, and actionable.
366
+
341
367
1. Check [the CI/CD status of the pull request][github ci], make sure all CI/CD tests passed before reviewing (contact the branch owner if needed).
342
368
1. Read carefully the descriptions of the pull request and the files changed, write comments if needed.
343
369
1. Make in-line comments to specific code segments, [request for changes](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-reviews) if needed.
@@ -350,22 +376,23 @@ All code review comments should be specific, constructive, and actionable.
0 commit comments