Skip to content

Commit

Permalink
Adds ruff precommit autofixes (#6402)
Browse files Browse the repository at this point in the history
### 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 <wenqil@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
wyli and pre-commit-ci[bot] authored Apr 20, 2023
1 parent 05dbc86 commit 79723ca
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 39 deletions.
35 changes: 6 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ repos:
args: ['--autofix', '--no-sort-keys', '--indent=4']
- id: end-of-file-fixer
- id: mixed-line-ending
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
hooks:
- id: ruff
args:
- --fix

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
Expand Down Expand Up @@ -53,8 +59,6 @@ repos:
- flake8>=3.8.1
- flake8-bugbear
- flake8-comprehensions
- flake8-executable
- flake8-pyi
- pep8-naming
exclude: |
(?x)^(
Expand All @@ -68,30 +72,3 @@ repos:
hooks:
- id: pycln
args: [--config=pyproject.toml]

#- 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
3 changes: 1 addition & 2 deletions monai/networks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

logger = get_logger(module_name=__name__)

global _has_nvfuser
_has_nvfuser = None


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

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

device = device if device else 0
Expand Down
6 changes: 2 additions & 4 deletions monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,13 +1640,11 @@ def _check_filter_format(self, filter: str | NdarrayOrTensor | nn.Module, filter
raise ValueError("`filter_size` should be a single uneven integer.")
if filter not in self.supported_filters:
raise NotImplementedError(f"{filter}. Supported filters are {self.supported_filters}.")
elif isinstance(filter, torch.Tensor) or isinstance(filter, np.ndarray):
elif isinstance(filter, (torch.Tensor, np.ndarray)):
if filter.ndim not in [1, 2, 3]:
raise ValueError("Only 1D, 2D, and 3D filters are supported.")
self._check_all_values_uneven(filter.shape)
elif isinstance(filter, (nn.Module, Transform)):
pass
else:
elif not isinstance(filter, (nn.Module, Transform)):
raise TypeError(
f"{type(filter)} is not supported."
"Supported types are `class 'str'`, `class 'torch.Tensor'`, `class 'np.ndarray'`, "
Expand Down
3 changes: 2 additions & 1 deletion monai/utils/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def resolve_name(name):
if obj is None:
# Get all modules having the declaration/import, need to check here that getattr returns something which doesn't
# equate to False since in places __getattr__ returns 0 incorrectly:
# https://github.com/tensorflow/tensorboard/blob/a22566561d2b4fea408755a951ac9eaf3a156f8e/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py#L35 # noqa: B950
# https://github.com/tensorflow/tensorboard/blob/a22566561d2b4fea408755a951ac9eaf3a156f8e/
# tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py#L35
mods = [m for m in list(sys.modules.values()) if getattr(m, name, None)]

if len(mods) > 0: # found modules with this declaration or import
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ exclude = '''
all = true
exclude = "monai/bundle/__main__.py"

[tool.ruff]
line-length = 133
ignore-init-module-imports = true
ignore = ["F401", "E741"]

[tool.pytype]
# Space-separated list of files or directories to exclude.
exclude = ["versioneer.py", "_version.py"]
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ lmdb
flake8>=3.8.1
flake8-bugbear
flake8-comprehensions
flake8-executable
pylint!=2.13 # https://github.com/PyCQA/pylint/issues/5969
mccabe
pep8-naming
pycodestyle
Expand Down
3 changes: 2 additions & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ then
# ensure that the necessary packages for code format testing are installed
if ! is_pip_installed pylint
then
install_deps
echo "Pip installing pylint ..."
${cmdPrefix}${PY_EXE} -m pip install pylint>2.16
fi
${cmdPrefix}${PY_EXE} -m pylint --version

Expand Down

0 comments on commit 79723ca

Please sign in to comment.