Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79723ca

Browse files
Adds ruff precommit autofixes (Project-MONAI#6402)
### Description https://github.com/charliermarsh/ruff ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 05dbc86 commit 79723ca

7 files changed

Lines changed: 18 additions & 39 deletions

File tree

.pre-commit-config.yaml

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ repos:
2626
args: ['--autofix', '--no-sort-keys', '--indent=4']
2727
- id: end-of-file-fixer
2828
- id: mixed-line-ending
29+
- repo: https://github.com/charliermarsh/ruff-pre-commit
30+
rev: v0.0.261
31+
hooks:
32+
- id: ruff
33+
args:
34+
- --fix
2935

3036
- repo: https://github.com/asottile/pyupgrade
3137
rev: v3.3.1
@@ -53,8 +59,6 @@ repos:
5359
- flake8>=3.8.1
5460
- flake8-bugbear
5561
- flake8-comprehensions
56-
- flake8-executable
57-
- flake8-pyi
5862
- pep8-naming
5963
exclude: |
6064
(?x)^(
@@ -68,30 +72,3 @@ repos:
6872
hooks:
6973
- id: pycln
7074
args: [--config=pyproject.toml]
71-
72-
#- repo: https://github.com/PyCQA/isort
73-
# rev: 5.9.3
74-
# hooks:
75-
# - id: isort
76-
# name: Format imports
77-
78-
# - repo: https://github.com/psf/black
79-
# rev: 21.7b0
80-
# hooks:
81-
# - id: black
82-
# name: Format code
83-
84-
#- repo: https://github.com/executablebooks/mdformat
85-
# rev: 0.7.8
86-
# hooks:
87-
# - id: mdformat
88-
# additional_dependencies:
89-
# - mdformat-gfm
90-
# - mdformat_frontmatter
91-
# exclude: CHANGELOG.md
92-
93-
# - repo: https://github.com/PyCQA/flake8
94-
# rev: 3.9.2
95-
# hooks:
96-
# - id: flake8
97-
# name: Check PEP8

monai/networks/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
logger = get_logger(module_name=__name__)
6666

67-
global _has_nvfuser
6867
_has_nvfuser = None
6968

7069

@@ -914,7 +913,7 @@ def convert_to_trt(
914913
if not dynamic_batchsize:
915914
warnings.warn(f"There is no dynamic batch range. The converted model only takes {input_shape} shape input.")
916915

917-
if (not (dynamic_batchsize is None)) and (len(dynamic_batchsize) != 3):
916+
if (dynamic_batchsize is not None) and (len(dynamic_batchsize) != 3):
918917
warnings.warn(f"The dynamic batch range sequence should have 3 elements, but got {dynamic_batchsize} elements.")
919918

920919
device = device if device else 0

monai/transforms/utility/array.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,13 +1640,11 @@ def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter
16401640
raise ValueError("`filter_size` should be a single uneven integer.")
16411641
if filter not in self.supported_filters:
16421642
raise NotImplementedError(f"{filter}. Supported filters are {self.supported_filters}.")
1643-
elif isinstance(filter, torch.Tensor) or isinstance(filter, np.ndarray):
1643+
elif isinstance(filter, (torch.Tensor, np.ndarray)):
16441644
if filter.ndim not in [1, 2, 3]:
16451645
raise ValueError("Only 1D, 2D, and 3D filters are supported.")
16461646
self._check_all_values_uneven(filter.shape)
1647-
elif isinstance(filter, (nn.Module, Transform)):
1648-
pass
1649-
else:
1647+
elif not isinstance(filter, (nn.Module, Transform)):
16501648
raise TypeError(
16511649
f"{type(filter)} is not supported."
16521650
"Supported types are `class 'str'`, `class 'torch.Tensor'`, `class 'np.ndarray'`, "

monai/utils/aliases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def resolve_name(name):
8181
if obj is None:
8282
# Get all modules having the declaration/import, need to check here that getattr returns something which doesn't
8383
# equate to False since in places __getattr__ returns 0 incorrectly:
84-
# https://github.com/tensorflow/tensorboard/blob/a22566561d2b4fea408755a951ac9eaf3a156f8e/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py#L35 # noqa: B950
84+
# https://github.com/tensorflow/tensorboard/blob/a22566561d2b4fea408755a951ac9eaf3a156f8e/
85+
# tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py#L35
8586
mods = [m for m in list(sys.modules.values()) if getattr(m, name, None)]
8687

8788
if len(mods) > 0: # found modules with this declaration or import

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ exclude = '''
3636
all = true
3737
exclude = "monai/bundle/__main__.py"
3838

39+
[tool.ruff]
40+
line-length = 133
41+
ignore-init-module-imports = true
42+
ignore = ["F401", "E741"]
43+
3944
[tool.pytype]
4045
# Space-separated list of files or directories to exclude.
4146
exclude = ["versioneer.py", "_version.py"]

requirements-dev.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ lmdb
1313
flake8>=3.8.1
1414
flake8-bugbear
1515
flake8-comprehensions
16-
flake8-executable
17-
pylint!=2.13 # https://github.com/PyCQA/pylint/issues/5969
1816
mccabe
1917
pep8-naming
2018
pycodestyle

runtests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ then
533533
# ensure that the necessary packages for code format testing are installed
534534
if ! is_pip_installed pylint
535535
then
536-
install_deps
536+
echo "Pip installing pylint ..."
537+
${cmdPrefix}${PY_EXE} -m pip install pylint>2.16
537538
fi
538539
${cmdPrefix}${PY_EXE} -m pylint --version
539540

0 commit comments

Comments
 (0)