diff --git a/.deepsource.toml b/.deepsource.toml index f090928ffa..a67393d967 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -24,4 +24,4 @@ enabled = true [[analyzers]] name = "shell" -enabled = true \ No newline at end of file +enabled = true diff --git a/.dockerignore b/.dockerignore index 4e1161bfb2..19bbf580ba 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,4 +11,3 @@ coverage.xml *.toml !README.md - diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 9c2dd97bb2..e822461059 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -9,4 +9,4 @@ assignees: '' **Please use MONAI's Discussions tab** For questions relating to MONAI usage, please do not create an issue. -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. \ No newline at end of file +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 --git a/.github/workflows/weekly-preview.yml b/.github/workflows/weekly-preview.yml index 981ca5cdaf..df0b5dd759 100644 --- a/.github/workflows/weekly-preview.yml +++ b/.github/workflows/weekly-preview.yml @@ -43,4 +43,3 @@ jobs: with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..fd6a351d59 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,63 @@ +default_language_version: + python: python3.8 + +ci: + autofix_prs: true + autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions' + autoupdate_schedule: quarterly + # submodules: true + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-yaml + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-toml + - id: check-case-conflict + - id: check-added-large-files + args: ['--maxkb=1024'] + - id: detect-private-key + + #- repo: https://github.com/asottile/pyupgrade + # rev: v2.23.2 + # hooks: + # - id: pyupgrade + # args: [--py36-plus] + # name: Upgrade code + + #- repo: https://github.com/asottile/yesqa + # rev: v1.2.3 + # hooks: + # - id: yesqa + # name: Unused noqa + + #- repo: https://github.com/PyCQA/isort + # rev: 5.9.3 + # hooks: + # - id: isort + # name: Format imports + + - repo: https://github.com/psf/black + rev: 21.7b0 + hooks: + - id: black + name: Format code + + #- repo: https://github.com/executablebooks/mdformat + # rev: 0.7.8 + # hooks: + # - id: mdformat + # additional_dependencies: + # - mdformat-gfm + # - mdformat_frontmatter + # exclude: CHANGELOG.md + + - repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + name: Check PEP8 diff --git a/docs/source/metrics.rst b/docs/source/metrics.rst index e6605065c4..c1ed25831d 100644 --- a/docs/source/metrics.rst +++ b/docs/source/metrics.rst @@ -83,4 +83,4 @@ Metrics `Peak signal to noise ratio` ---------------------------- .. autoclass:: PSNRMetric - :members: \ No newline at end of file + :members: diff --git a/monai/config/type_definitions.py b/monai/config/type_definitions.py index b236467bbc..91ac74961b 100644 --- a/monai/config/type_definitions.py +++ b/monai/config/type_definitions.py @@ -14,69 +14,55 @@ import numpy as np import torch +# Commonly used concepts +# This module provides naming and type specifications for commonly used concepts +# within the MONAI package. The intent is to explicitly identify information +# that should be used consistently throughout the entire MONAI package. +# +# A type would be named as type_definitions.KeysCollection +# which includes a meaningful name for the consent in the name itself. The +# definitions in this file map context meaningful names to the underlying +# object properties that define the expected API. +# +# A conceptual type is represented by a new type name but is also one which +# can be different depending on an environment (i.e. differences for python 3.6 vs 3.9 +# may be implemented). Consistent use of the concept and recorded documentation of +# the rationale and convention behind it lowers the learning curve for new +# developers. For readability, short names are preferred. __all__ = ["KeysCollection", "IndexSelection", "DtypeLike", "NdarrayTensor", "NdarrayOrTensor", "TensorOrList"] -"""Commonly used concepts -This module provides naming and type specifications for commonly used concepts -within the MONAI package. The intent is to explicitly identify information -that should be used consistently throughout the entire MONAI package. - -A type would be named as type_definitions.KeysCollection -which includes a meaningful name for the consent in the name itself. The -definitions in this file map context meaningful names to the underlying -object properties that define the expected API. - -A conceptual type is represented by a new type name but is also one which -can be different depending on an environment (i.e. differences for python 3.6 vs 3.9 -may be implemented). Consistent use of the concept and recorded documentation of -the rationale and convention behind it lowers the learning curve for new -developers. For readability, short names are preferred. -""" +#: KeysCollection +# +# The KeyCollection type is used to for defining variables +# that store a subset of keys to select items from a dictionary. +# The container of keys must contain hashable elements. +# NOTE: `Hashable` is not a collection, but is provided as a +# convenience to end-users. All supplied values will be +# internally converted to a tuple of `Hashable`'s before +# use KeysCollection = Union[Collection[Hashable], Hashable] -"""KeysCollection - -The KeyCollection type is used to for defining variables -that store a subset of keys to select items from a dictionary. -The container of keys must contain hashable elements. -NOTE: `Hashable` is not a collection, but is provided as a - convenience to end-users. All supplied values will be - internally converted to a tuple of `Hashable`'s before - use -""" - +#: IndexSelection +# +# The IndexSelection type is used to for defining variables +# that store a subset of indices to select items from a List or Array like objects. +# The indices must be integers, and if a container of indices is specified, the +# container must be iterable. IndexSelection = Union[Iterable[int], int] -"""IndexSelection - -The IndexSelection type is used to for defining variables -that store a subset of indices to select items from a List or Array like objects. -The indices must be integers, and if a container of indices is specified, the -container must be iterable. -""" - +#: Type of datatypes: Adapted from https://github.com/numpy/numpy/blob/master/numpy/typing/_dtype_like.py DtypeLike = Union[np.dtype, type, None] -"""Type of datatypes - -Adapted from https://github.com/numpy/numpy/blob/master/numpy/typing/_dtype_like.py -""" +#: NdarrayTensor +# +# Generic type which can represent either a numpy.ndarray or a torch.Tensor +# Unlike Union can create a dependence between parameter(s) / return(s) NdarrayTensor = TypeVar("NdarrayTensor", np.ndarray, torch.Tensor) -"""NdarrayTensor -Generic type which can represent either a numpy.ndarray or a torch.Tensor -Unlike Union can create a dependence between parameter(s) / return(s) -""" +#: NdarrayOrTensor: Union of numpy.ndarray and torch.Tensor to be used for typing NdarrayOrTensor = Union[np.ndarray, torch.Tensor] -"""NdarrayOrTensor - -Union of numpy.ndarray and torch.Tensor to be used for typing -""" +#: TensorOrList: The TensorOrList type is used for defining `batch-first Tensor` or `list of channel-first Tensor`. TensorOrList = Union[torch.Tensor, Sequence[torch.Tensor]] -"""TensorOrList - -The TensorOrList type is used for defining `batch-first Tensor` or `list of channel-first Tensor`. -""" diff --git a/monai/csrc/filtering/bilateral/bilateralfilter_cpu.cpp b/monai/csrc/filtering/bilateral/bilateralfilter_cpu.cpp index 474d24b4fa..2e6c7dbe20 100644 --- a/monai/csrc/filtering/bilateral/bilateralfilter_cpu.cpp +++ b/monai/csrc/filtering/bilateral/bilateralfilter_cpu.cpp @@ -164,4 +164,4 @@ torch::Tensor BilateralFilterCpu(torch::Tensor inputTensor, float spatialSigma, })); return outputTensor; -} \ No newline at end of file +} diff --git a/monai/csrc/filtering/filtering.h b/monai/csrc/filtering/filtering.h index 25186b182a..3dcdfc473b 100644 --- a/monai/csrc/filtering/filtering.h +++ b/monai/csrc/filtering/filtering.h @@ -14,4 +14,4 @@ limitations under the License. #pragma once #include "bilateral/bilateral.h" -#include "permutohedral/permutohedral.h" \ No newline at end of file +#include "permutohedral/permutohedral.h" diff --git a/monai/csrc/filtering/permutohedral/hash_table.cuh b/monai/csrc/filtering/permutohedral/hash_table.cuh index f9893dffe2..1acff5f276 100644 --- a/monai/csrc/filtering/permutohedral/hash_table.cuh +++ b/monai/csrc/filtering/permutohedral/hash_table.cuh @@ -257,4 +257,4 @@ __device__ static int hashTableRetrieve(signed short* key) { if (h == table_capacity * 2) h = 0; } -} \ No newline at end of file +} diff --git a/monai/csrc/filtering/permutohedral/permutohedral.h b/monai/csrc/filtering/permutohedral/permutohedral.h index 32ffee83e5..1c9d1a031e 100644 --- a/monai/csrc/filtering/permutohedral/permutohedral.h +++ b/monai/csrc/filtering/permutohedral/permutohedral.h @@ -25,4 +25,4 @@ template void PermutohedralCuda(scalar_t* data, scalar_t* features, int elementCount, bool accurate); #endif -torch::Tensor PermutohedralFilter(torch::Tensor input, torch::Tensor features); \ No newline at end of file +torch::Tensor PermutohedralFilter(torch::Tensor input, torch::Tensor features); diff --git a/monai/csrc/filtering/permutohedral/permutohedral_cpu.cpp b/monai/csrc/filtering/permutohedral/permutohedral_cpu.cpp index 0876997448..8c0dc8e546 100644 --- a/monai/csrc/filtering/permutohedral/permutohedral_cpu.cpp +++ b/monai/csrc/filtering/permutohedral/permutohedral_cpu.cpp @@ -499,4 +499,4 @@ void PermutohedralCPU(scalar_t* data, scalar_t* features, int dataChannels, int } template void PermutohedralCPU(float* data, float* features, int dataChannels, int featureChannels, int elementCount); -template void PermutohedralCPU(double* data, double* features, int dataChannels, int featureChannels, int elementCount); \ No newline at end of file +template void PermutohedralCPU(double* data, double* features, int dataChannels, int featureChannels, int elementCount);