Skip to content

Commit ce139f6

Browse files
authored
CI: pre-commit (#2843)
* add pre-commit Signed-off-by: Jirka <jirka.borovec@seznam.cz>
1 parent 1065dad commit ce139f6

File tree

12 files changed

+108
-61
lines changed

12 files changed

+108
-61
lines changed

Diff for: .deepsource.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ enabled = true
2424

2525
[[analyzers]]
2626
name = "shell"
27-
enabled = true
27+
enabled = true

Diff for: .dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ coverage.xml
1111
*.toml
1212

1313
!README.md
14-

Diff for: .github/ISSUE_TEMPLATE/question.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ assignees: ''
99
**Please use MONAI's Discussions tab**
1010
For questions relating to MONAI usage, please do not create an issue.
1111

12-
Instead, use [MONAI's GitHub Discussions tab](https://github.com/Project-MONAI/MONAI/discussions). This can be found next to Issues and Pull Requests along the top of our repository.
12+
Instead, use [MONAI's GitHub Discussions tab](https://github.com/Project-MONAI/MONAI/discussions). This can be found next to Issues and Pull Requests along the top of our repository.

Diff for: .github/workflows/weekly-preview.yml

-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ jobs:
4343
with:
4444
user: __token__
4545
password: ${{ secrets.PYPI_TOKEN }}
46-

Diff for: .pre-commit-config.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.0.1
13+
hooks:
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
16+
- id: check-yaml
17+
- id: check-docstring-first
18+
- id: check-executables-have-shebangs
19+
- id: check-toml
20+
- id: check-case-conflict
21+
- id: check-added-large-files
22+
args: ['--maxkb=1024']
23+
- id: detect-private-key
24+
25+
#- repo: https://github.com/asottile/pyupgrade
26+
# rev: v2.23.2
27+
# hooks:
28+
# - id: pyupgrade
29+
# args: [--py36-plus]
30+
# name: Upgrade code
31+
32+
#- repo: https://github.com/asottile/yesqa
33+
# rev: v1.2.3
34+
# hooks:
35+
# - id: yesqa
36+
# name: Unused noqa
37+
38+
#- repo: https://github.com/PyCQA/isort
39+
# rev: 5.9.3
40+
# hooks:
41+
# - id: isort
42+
# name: Format imports
43+
44+
- repo: https://github.com/psf/black
45+
rev: 21.7b0
46+
hooks:
47+
- id: black
48+
name: Format code
49+
50+
#- repo: https://github.com/executablebooks/mdformat
51+
# rev: 0.7.8
52+
# hooks:
53+
# - id: mdformat
54+
# additional_dependencies:
55+
# - mdformat-gfm
56+
# - mdformat_frontmatter
57+
# exclude: CHANGELOG.md
58+
59+
- repo: https://github.com/PyCQA/flake8
60+
rev: 3.9.2
61+
hooks:
62+
- id: flake8
63+
name: Check PEP8

Diff for: docs/source/metrics.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ Metrics
8383
`Peak signal to noise ratio`
8484
----------------------------
8585
.. autoclass:: PSNRMetric
86-
:members:
86+
:members:

Diff for: monai/config/type_definitions.py

+37-51
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,55 @@
1414
import numpy as np
1515
import torch
1616

17+
# Commonly used concepts
18+
# This module provides naming and type specifications for commonly used concepts
19+
# within the MONAI package. The intent is to explicitly identify information
20+
# that should be used consistently throughout the entire MONAI package.
21+
#
22+
# A type would be named as type_definitions.KeysCollection
23+
# which includes a meaningful name for the consent in the name itself. The
24+
# definitions in this file map context meaningful names to the underlying
25+
# object properties that define the expected API.
26+
#
27+
# A conceptual type is represented by a new type name but is also one which
28+
# can be different depending on an environment (i.e. differences for python 3.6 vs 3.9
29+
# may be implemented). Consistent use of the concept and recorded documentation of
30+
# the rationale and convention behind it lowers the learning curve for new
31+
# developers. For readability, short names are preferred.
1732
__all__ = ["KeysCollection", "IndexSelection", "DtypeLike", "NdarrayTensor", "NdarrayOrTensor", "TensorOrList"]
1833

19-
"""Commonly used concepts
20-
This module provides naming and type specifications for commonly used concepts
21-
within the MONAI package. The intent is to explicitly identify information
22-
that should be used consistently throughout the entire MONAI package.
23-
24-
A type would be named as type_definitions.KeysCollection
25-
which includes a meaningful name for the consent in the name itself. The
26-
definitions in this file map context meaningful names to the underlying
27-
object properties that define the expected API.
28-
29-
A conceptual type is represented by a new type name but is also one which
30-
can be different depending on an environment (i.e. differences for python 3.6 vs 3.9
31-
may be implemented). Consistent use of the concept and recorded documentation of
32-
the rationale and convention behind it lowers the learning curve for new
33-
developers. For readability, short names are preferred.
34-
"""
3534

35+
#: KeysCollection
36+
#
37+
# The KeyCollection type is used to for defining variables
38+
# that store a subset of keys to select items from a dictionary.
39+
# The container of keys must contain hashable elements.
40+
# NOTE: `Hashable` is not a collection, but is provided as a
41+
# convenience to end-users. All supplied values will be
42+
# internally converted to a tuple of `Hashable`'s before
43+
# use
3644
KeysCollection = Union[Collection[Hashable], Hashable]
37-
"""KeysCollection
38-
39-
The KeyCollection type is used to for defining variables
40-
that store a subset of keys to select items from a dictionary.
41-
The container of keys must contain hashable elements.
42-
NOTE: `Hashable` is not a collection, but is provided as a
43-
convenience to end-users. All supplied values will be
44-
internally converted to a tuple of `Hashable`'s before
45-
use
46-
"""
47-
4845

46+
#: IndexSelection
47+
#
48+
# The IndexSelection type is used to for defining variables
49+
# that store a subset of indices to select items from a List or Array like objects.
50+
# The indices must be integers, and if a container of indices is specified, the
51+
# container must be iterable.
4952
IndexSelection = Union[Iterable[int], int]
50-
"""IndexSelection
51-
52-
The IndexSelection type is used to for defining variables
53-
that store a subset of indices to select items from a List or Array like objects.
54-
The indices must be integers, and if a container of indices is specified, the
55-
container must be iterable.
56-
"""
57-
5853

54+
#: Type of datatypes: Adapted from https://github.com/numpy/numpy/blob/master/numpy/typing/_dtype_like.py
5955
DtypeLike = Union[np.dtype, type, None]
60-
"""Type of datatypes
61-
62-
Adapted from https://github.com/numpy/numpy/blob/master/numpy/typing/_dtype_like.py
63-
"""
6456

57+
#: NdarrayTensor
58+
#
59+
# Generic type which can represent either a numpy.ndarray or a torch.Tensor
60+
# Unlike Union can create a dependence between parameter(s) / return(s)
6561
NdarrayTensor = TypeVar("NdarrayTensor", np.ndarray, torch.Tensor)
66-
"""NdarrayTensor
6762

68-
Generic type which can represent either a numpy.ndarray or a torch.Tensor
69-
Unlike Union can create a dependence between parameter(s) / return(s)
70-
"""
7163

64+
#: NdarrayOrTensor: Union of numpy.ndarray and torch.Tensor to be used for typing
7265
NdarrayOrTensor = Union[np.ndarray, torch.Tensor]
73-
"""NdarrayOrTensor
74-
75-
Union of numpy.ndarray and torch.Tensor to be used for typing
76-
"""
7766

67+
#: TensorOrList: The TensorOrList type is used for defining `batch-first Tensor` or `list of channel-first Tensor`.
7868
TensorOrList = Union[torch.Tensor, Sequence[torch.Tensor]]
79-
"""TensorOrList
80-
81-
The TensorOrList type is used for defining `batch-first Tensor` or `list of channel-first Tensor`.
82-
"""

Diff for: monai/csrc/filtering/bilateral/bilateralfilter_cpu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,4 @@ torch::Tensor BilateralFilterCpu(torch::Tensor inputTensor, float spatialSigma,
164164
}));
165165

166166
return outputTensor;
167-
}
167+
}

Diff for: monai/csrc/filtering/filtering.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ limitations under the License.
1414
#pragma once
1515

1616
#include "bilateral/bilateral.h"
17-
#include "permutohedral/permutohedral.h"
17+
#include "permutohedral/permutohedral.h"

Diff for: monai/csrc/filtering/permutohedral/hash_table.cuh

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,4 @@ __device__ static int hashTableRetrieve(signed short* key) {
257257
if (h == table_capacity * 2)
258258
h = 0;
259259
}
260-
}
260+
}

Diff for: monai/csrc/filtering/permutohedral/permutohedral.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ template <typename scalar_t, int dc, int fc>
2525
void PermutohedralCuda(scalar_t* data, scalar_t* features, int elementCount, bool accurate);
2626
#endif
2727

28-
torch::Tensor PermutohedralFilter(torch::Tensor input, torch::Tensor features);
28+
torch::Tensor PermutohedralFilter(torch::Tensor input, torch::Tensor features);

Diff for: monai/csrc/filtering/permutohedral/permutohedral_cpu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,4 @@ void PermutohedralCPU(scalar_t* data, scalar_t* features, int dataChannels, int
499499
}
500500

501501
template void PermutohedralCPU(float* data, float* features, int dataChannels, int featureChannels, int elementCount);
502-
template void PermutohedralCPU(double* data, double* features, int dataChannels, int featureChannels, int elementCount);
502+
template void PermutohedralCPU(double* data, double* features, int dataChannels, int featureChannels, int elementCount);

0 commit comments

Comments
 (0)