diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aacdd3ab9b..a23023bf83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: # list of supported hooks: https://pre-commit.com/hooks.html - id: trailing-whitespace @@ -15,80 +15,44 @@ repos: # python code formatting - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 23.1.0 hooks: - id: black - # python import sorting - - repo: https://github.com/PyCQA/isort - rev: 5.11.5 + # Ruff version. + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: "v0.0.253" hooks: - - id: isort - - # python code analysis - - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 - hooks: - - id: flake8 - args: ["--max-line-length=120", "--ignore=E203,W503"] + - id: ruff exclude: "tests" - # python linting - - repo: https://github.com/PyCQA/pylint - rev: v2.14.5 - hooks: - - id: pylint - name: pylint - entry: pylint --score=no - language: system - types: [python] - exclude: "tests|docs" - # python static type checking - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v0.971" + rev: "v1.0.1" hooks: - id: mypy additional_dependencies: [types-PyYAML] exclude: "tests" - - repo: https://github.com/PyCQA/pydocstyle - rev: 6.1.1 - hooks: - - id: pydocstyle - additional_dependencies: [toml] - name: pydocstyle - entry: pydocstyle - language: python - types: [python] - exclude: "tests|docs" - - - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 - hooks: - - id: pyupgrade - # notebooks. - repo: https://github.com/nbQA-dev/nbQA - rev: 1.4.0 + rev: 1.6.3 hooks: - id: nbqa-black - - id: nbqa-isort - - id: nbqa-flake8 - - id: nbqa-pylint + - id: nbqa-ruff - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.7.1 + rev: v3.0.0-alpha.4 hooks: - id: prettier - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.32.2 + rev: v0.33.0 hooks: - id: markdownlint - repo: https://github.com/AleksaC/hadolint-py - rev: v2.10.0 + rev: v2.12.0.2 hooks: - id: hadolint name: Lint Dockerfiles diff --git a/anomalib/data/utils/augmenter.py b/anomalib/data/utils/augmenter.py index 6d41acb98e..611bde8374 100644 --- a/anomalib/data/utils/augmenter.py +++ b/anomalib/data/utils/augmenter.py @@ -47,7 +47,6 @@ def __init__( p_anomalous: float = 0.5, beta: float | tuple[float, float] = (0.2, 1.0), ): - self.p_anomalous = p_anomalous self.beta = beta diff --git a/anomalib/deploy/inferencers/torch_inferencer.py b/anomalib/deploy/inferencers/torch_inferencer.py index 924e9d1713..e0d9284c54 100644 --- a/anomalib/deploy/inferencers/torch_inferencer.py +++ b/anomalib/deploy/inferencers/torch_inferencer.py @@ -44,7 +44,6 @@ def __init__( meta_data_path: str | Path | None = None, device: str = "auto", ) -> None: - self.device = self._get_device(device) # Check and load the configuration diff --git a/anomalib/models/csflow/torch_model.py b/anomalib/models/csflow/torch_model.py index 153672f73e..05129c076d 100644 --- a/anomalib/models/csflow/torch_model.py +++ b/anomalib/models/csflow/torch_model.py @@ -519,7 +519,6 @@ def __init__( clamp: int = 3, num_channels: int = 3, ) -> None: - super().__init__() self.input_dims = (num_channels, *input_size) self.clamp = clamp diff --git a/anomalib/models/fastflow/loss.py b/anomalib/models/fastflow/loss.py index 848f86980f..f7c7f00210 100644 --- a/anomalib/models/fastflow/loss.py +++ b/anomalib/models/fastflow/loss.py @@ -23,6 +23,6 @@ def forward(self, hidden_variables: list[Tensor], jacobians: list[Tensor]) -> Te Tensor: Fastflow loss computed based on the hidden variables and the log of the Jacobians. """ loss = torch.tensor(0.0, device=hidden_variables[0].device) # pylint: disable=not-callable - for (hidden_variable, jacobian) in zip(hidden_variables, jacobians): + for hidden_variable, jacobian in zip(hidden_variables, jacobians): loss += torch.mean(0.5 * torch.sum(hidden_variable**2, dim=(1, 2, 3)) - jacobian) return loss diff --git a/anomalib/models/ganomaly/lightning_model.py b/anomalib/models/ganomaly/lightning_model.py index 9018a56764..d8153fd6a5 100644 --- a/anomalib/models/ganomaly/lightning_model.py +++ b/anomalib/models/ganomaly/lightning_model.py @@ -208,7 +208,6 @@ class GanomalyLightning(Ganomaly): """ def __init__(self, hparams: DictConfig | ListConfig) -> None: - super().__init__( batch_size=hparams.dataset.train_batch_size, input_size=hparams.model.input_size, diff --git a/anomalib/models/rkde/region_extractor.py b/anomalib/models/rkde/region_extractor.py index 2a61695678..ab807337a2 100644 --- a/anomalib/models/rkde/region_extractor.py +++ b/anomalib/models/rkde/region_extractor.py @@ -123,7 +123,6 @@ def post_process_box_predictions(self, pred_boxes: Tensor, pred_scores: Tensor) processed_boxes: list[Tensor] = [] for boxes, scores in zip(pred_boxes, pred_scores): - # remove small boxes keep = box_ops.remove_small_boxes(boxes, min_size=self.min_size) boxes, scores = boxes[keep], scores[keep] diff --git a/anomalib/pre_processing/tiler.py b/anomalib/pre_processing/tiler.py index 43b148d048..120392765a 100644 --- a/anomalib/pre_processing/tiler.py +++ b/anomalib/pre_processing/tiler.py @@ -154,7 +154,6 @@ def __init__( mode: str = "padding", tile_count: int = 4, ) -> None: - self.tile_size_h, self.tile_size_w = self.__validate_size_type(tile_size) self.tile_count = tile_count diff --git a/anomalib/utils/callbacks/nncf/utils.py b/anomalib/utils/callbacks/nncf/utils.py index a1aafd759f..f2fcfb36e3 100644 --- a/anomalib/utils/callbacks/nncf/utils.py +++ b/anomalib/utils/callbacks/nncf/utils.py @@ -58,7 +58,7 @@ def get_target(self, _): def wrap_nncf_model( - model: nn.Module, config: dict, dataloader: DataLoader = None, init_state_dict: dict = None + model: nn.Module, config: dict, dataloader: DataLoader, init_state_dict: dict ) -> tuple[CompressionAlgorithmController, NNCFNetwork]: """Wrap model by NNCF. diff --git a/anomalib/utils/metrics/aupro.py b/anomalib/utils/metrics/aupro.py index 7b7fa17d04..3f3a0b9b18 100644 --- a/anomalib/utils/metrics/aupro.py +++ b/anomalib/utils/metrics/aupro.py @@ -36,7 +36,7 @@ def __init__( compute_on_step: bool = True, dist_sync_on_step: bool = False, process_group: Any | None = None, - dist_sync_fn: Callable = None, + dist_sync_fn: Callable | None = None, fpr_limit: float = 0.3, ) -> None: super().__init__( diff --git a/pyproject.toml b/pyproject.toml index 1413ff931b..576ed03ce7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,58 +5,59 @@ requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# ISORT CONFIGURATION. # -[tool.isort] -profile = "black" -known_first_party = "wandb" -sections = ['FUTURE', 'STDLIB', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER'] - - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # BLACK CONFIGURATION # [tool.black] line-length = 120 -[tool.flake8] -ignore = ["E203", "W503"] -max-line-length = 120 - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# PYLINT CONFIGURATION # -[tool.pylint.main] -extension-pkg-whitelist = "cv2" -ignore = ["tests", "docs"] -ignored-modules = "cv2" - -[tool.pylint.messages_control] -disable = [ - "duplicate-code", - "arguments-differ", - "fixme", - "import-error", - "too-many-arguments", - "too-many-branches", - "too-many-instance-attributes", - "too-many-locals", - "too-few-public-methods", +# RUFF CONFIGURATION # +[tool.ruff] +# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. +select = ["E", "F"] +ignore = [] + +# Allow autofix for all enabled rules (when `--fix`) is provided. +fixable = ["A", "B", "C", "D", "E", "F"] +unfixable = [] + +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", ] -[tool.pylint.typecheck] -generated-members = ["numpy.*", "torch.*"] - -[tool.pylint.basic] -good-names = ["e", "i", "id"] +# Same as Black. +line-length = 120 -[tool.pylint.format] -max-line-length = 120 +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -[tool.pylint.design] -max-parents = 15 +# Assume Python 3.8. +target-version = "py38" -[tool.pylint.similarities] -min-similarity-lines = 5 +[tool.ruff.mccabe] +# Unlike Flake8, default to a complexity level of 10. +max-complexity = 10 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @@ -83,23 +84,8 @@ exclude_lines = [ "raise ValueError", ] -[tool.pydocstyle] -inherit = false -ignore = [ - "D107", # Missing docstring in __init__ - "D202", # No blank lines allowed after function docstring - "D203", # 1 blank line required before class docstring - "D213", # Multi-line docstring summary should start at the second line - "D401", # First line should be in imperative mood; try rephrasing - "D404", # First word of the docstring should not be This - "D406", # Section name should end with a newline - "D407", # Missing dashed underline after section - "D413", # Missing blank line after last section -] - # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # NBQA CONFIGURATION # [tool.nbqa.addopts] -pylint = ["--disable=C0103,C0114,C0116,C0413,E0401,R0801,W0106"] -flake8 = ["--ignore=E203,W503,E402", "--max-line-length=120"] +ruff = ["--ignore=E402"] diff --git a/requirements/dev.txt b/requirements/dev.txt index 7d3e8098e3..fd9c88faef 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,8 +1,3 @@ -black==22.6.0 -isort==5.11.5 -pylint>=2.14.5 -flake8>=4.0.1 +pre-commit pytest -pre-commit>=2.15.0 -tox>=3.24.3 -nbmake>=1.3.5 +tox diff --git a/tests/helpers/aupro_reference.py b/tests/helpers/aupro_reference.py index 79b1a59131..23c71931bd 100644 --- a/tests/helpers/aupro_reference.py +++ b/tests/helpers/aupro_reference.py @@ -134,7 +134,6 @@ def collect_anomaly_scores(anomaly_maps, ground_truth_maps): # Collect anomaly scores within each ground truth region and for all potential fp pixels. ok_index = 0 for gt_map, prediction in zip(ground_truth_maps, anomaly_maps): - # Compute the connected components in the ground truth map. labeled, n_components = label(gt_map, structure) diff --git a/tools/inference/gradio_inference.py b/tools/inference/gradio_inference.py index deb0d7f494..bfd4f55e73 100644 --- a/tools/inference/gradio_inference.py +++ b/tools/inference/gradio_inference.py @@ -26,9 +26,9 @@ def get_args() -> Namespace: Example: Example for Torch Inference. - >>> python tools/inference/gradio_inference.py \ ─╯ + >>> python tools/inference/gradio_inference.py \ ... --config ./anomalib/models/padim/config.yaml \ - ... --weights ./results/padim/mvtec/bottle/weights/model.ckpt # noqa: E501 #pylint: disable=line-too-long + ... --weights ./results/padim/mvtec/bottle/weights/model.ckpt Returns: Namespace: List of arguments.