Skip to content

Commit

Permalink
Fix Requirement.parse issue and address pre-commit issues. (#2172)
Browse files Browse the repository at this point in the history
Fix requirement parsing issue, and pre-commit
  • Loading branch information
samet-akcay authored Jul 5, 2024
1 parent 6d22921 commit 3ea4dad
Show file tree
Hide file tree
Showing 127 changed files with 67 additions and 178 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# list of supported hooks: https://pre-commit.com/hooks.html
- id: trailing-whitespace
Expand All @@ -15,7 +15,7 @@ repos:

# Ruff version.
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.5"
rev: "v0.5.0"
hooks:
# Run the linter.
- id: ruff
Expand All @@ -27,35 +27,35 @@ repos:

# python static type checking
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.0"
rev: "v1.10.1"
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-setuptools]
exclude: "tests"

# add bandit for security checks
- repo: https://github.com/PyCQA/bandit
rev: 1.7.7
rev: 1.7.9
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]

# notebooks.
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
rev: 1.8.5
hooks:
- id: nbqa-ruff
# Ignore unsorted imports. This is because jupyter notebooks can import
# packages in a different order than the rest of the codebase.
args: ["--ignore=D100,D407,I001"]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
rev: v0.41.0
hooks:
- id: markdownlint
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ We welcome contributions from everyone. If you're interested in helping out, ple
Here is a list of contributors of Anomalib:

<a href="https://github.com/openvinotoolkit/anomalib/graphs/contributors">
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" />
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" alt="Contributors to openvinotoolkit/anomalib" />
</a>

## 🙏 Acknowledgements
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

<img src="https://raw.githubusercontent.com/openvinotoolkit/anomalib/main/docs/source/_static/images/logos/anomalib-wide-blue.png" width="600px">
<img src="https://raw.githubusercontent.com/openvinotoolkit/anomalib/main/docs/source/_static/images/logos/anomalib-wide-blue.png" width="600px" alt="Anomalib Logo">

**A library for benchmarking, developing and deploying deep learning anomaly detection algorithms**

Expand Down Expand Up @@ -30,7 +30,7 @@
Anomalib is a deep learning library that aims to collect state-of-the-art anomaly detection algorithms for benchmarking on both public and private datasets. Anomalib provides several ready-to-use implementations of anomaly detection algorithms described in the recent literature, as well as a set of tools that facilitate the development and implementation of custom models. The library has a strong focus on visual anomaly detection, where the goal of the algorithm is to detect and/or localize anomalies within images or videos in a dataset. Anomalib is constantly updated with new algorithms and training/inference extensions, so keep checking!

<p align="center">
<img src="https://raw.githubusercontent.com/openvinotoolkit/anomalib/main/docs/source/_static/images/readme.png" width="1000">
<img src="https://raw.githubusercontent.com/openvinotoolkit/anomalib/main/docs/source/_static/images/readme.png" width="1000" alt="A prediction made by anomalib">
</p>

## Key features
Expand Down Expand Up @@ -304,5 +304,5 @@ For those who would like to contribute to the library, see [CONTRIBUTING.md](CON
Thank you to all of the people who have already made a contribution - we appreciate your support!

<a href="https://github.com/openvinotoolkit/anomalib/graphs/contributors">
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" />
<img src="https://contrib.rocks/image?repo=openvinotoolkit/anomalib" alt="Contributors to openvinotoolkit/anomalib" />
</a>
4 changes: 2 additions & 2 deletions notebooks/500_use_cases/501_dobot/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dobot Use Case Tutorial

| Notebook | | |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- |
| Notebook | Link |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Training a Model | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501a_training_a_model_with_cubes_from_a_robotic_arm.ipynb) |
| Inference with the Model | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openvinotoolkit/anomalib/blob/main/notebooks/500_use_cases/501_dobot/501b_inference_with_a_robotic_arm.ipynb) |

Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from importlib import import_module
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from enum import Enum
from typing import Any
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/nncf/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import subprocess # nosec B404
from pathlib import Path
from typing import TYPE_CHECKING, Any
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/nncf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from copy import copy
from typing import TYPE_CHECKING, Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from typing import Any

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from typing import Any

import torch
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/callbacks/tiler_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from collections.abc import Sequence

import lightning.pytorch as pl
Expand Down
10 changes: 3 additions & 7 deletions src/anomalib/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@

import logging

from packaging.requirements import Requirement
from packaging.version import parse
from rich.console import Console
from rich.logging import RichHandler

from anomalib.cli.utils.installation import (
get_requirements,
get_torch_install_args,
parse_requirements,
)
from anomalib.cli.utils.installation import get_requirements, get_torch_install_args, parse_requirements

logger = logging.getLogger("pip")
logger.setLevel(logging.WARNING) # setLevel: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET
Expand Down Expand Up @@ -50,7 +46,7 @@ def anomalib_install(option: str = "full", verbose: bool = False) -> int:
elif option in requirements_dict:
requirements.extend(requirements_dict[option])
elif option is not None:
requirements.append(Requirement.parse(option))
requirements.append(parse(option))

# Parse requirements into torch and other requirements.
# This is done to parse the correct version of torch (cpu/cuda).
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/cli/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging

from jsonargparse import Namespace
Expand Down
24 changes: 14 additions & 10 deletions src/anomalib/cli/utils/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import re
from importlib.metadata import requires
from pathlib import Path
from typing import TYPE_CHECKING
from warnings import warn

from packaging.requirements import Requirement
from packaging.version import parse

if TYPE_CHECKING:
from packaging.requirements import Requirement

AVAILABLE_TORCH_VERSIONS = {
"2.0.0": {"torchvision": "0.15.1", "cuda": ("11.7", "11.8")},
Expand Down Expand Up @@ -50,7 +54,7 @@ def get_requirements(module: str = "anomalib") -> dict[str, list[Requirement]]:
if isinstance(requirement_extra, list) and len(requirement_extra) > 1:
extra = requirement_extra[-1].split("==")[-1].strip("'\"")
_requirement_name = requirement_extra[0]
_requirement = Requirement.parse(_requirement_name)
_requirement = parse(_requirement_name)
if extra in extra_requirement:
extra_requirement[extra].append(_requirement)
else:
Expand All @@ -73,12 +77,12 @@ def parse_requirements(
Examples:
>>> requirements = [
... Requirement.parse("torch==1.13.0"),
... Requirement.parse("onnx>=1.8.1"),
... parse("torch==1.13.0"),
... parse("onnx>=1.8.1"),
... ]
>>> parse_requirements(requirements=requirements)
(Requirement.parse("torch==1.13.0"),
Requirement.parse("onnx>=1.8.1"))
(parse("torch==1.13.0"),
parse("onnx>=1.8.1"))
Returns:
tuple[str, list[str], list[str]]: Tuple of torch and other requirements.
Expand Down Expand Up @@ -295,7 +299,7 @@ def add_hardware_suffix_to_torch(
Examples:
>>> from packaging.requirements import Requirement
>>> req = "torch>=1.13.0, <=2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> requirement.name, requirement.specs
('torch', [('>=', '1.13.0'), ('<=', '2.0.1')])
Expand All @@ -304,13 +308,13 @@ def add_hardware_suffix_to_torch(
``with_available_torch_build=True`` will use the latest available PyTorch build.
>>> req = "torch==2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> add_hardware_suffix_to_torch(requirement, with_available_torch_build=True)
'torch==2.0.1+cu118'
It is possible to pass the ``hardware_suffix`` manually.
>>> req = "torch==2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement = parse(req)
>>> add_hardware_suffix_to_torch(requirement, hardware_suffix="cu121")
'torch==2.0.1+cu111'
Expand Down Expand Up @@ -374,7 +378,7 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]:
list[str]: The install arguments.
"""
if isinstance(requirement, str):
requirement = Requirement.parse(requirement)
requirement = parse(requirement)

# NOTE: This does not take into account if the requirement has multiple versions
# such as torch<2.0.1,>=1.13.0
Expand Down
3 changes: 1 addition & 2 deletions src/anomalib/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
)


class UnknownDatamoduleError(ModuleNotFoundError):
...
class UnknownDatamoduleError(ModuleNotFoundError): ...


def get_datamodule(config: DictConfig | ListConfig | dict) -> AnomalibDataModule:
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from .datamodule import AnomalibDataModule
from .dataset import AnomalibDataset
from .depth import AnomalibDepthDataset
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/base/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from abc import ABC, abstractmethod
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from enum import Enum

from .folder_3d import Folder3D
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/folder_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from pathlib import Path

from pandas import DataFrame, isna
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/depth/mvtec_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
from collections.abc import Sequence
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from enum import Enum

from .btech import BTech
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/image/visa.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# Subset splitting code adapted from https://github.com/amazon-science/spot-diff
# Original licence: Apache-2.0


import csv
import logging
import shutil
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


from pathlib import Path
from typing import Any

Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/augmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import math
import random
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import torch

from anomalib.utils.cv import connected_components_cpu, connected_components_gpu
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import hashlib
import io
import logging
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import logging
import math
from collections.abc import Sequence
Expand Down
1 change: 0 additions & 1 deletion src/anomalib/data/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0


import os
import re
from enum import Enum
Expand Down
Loading

0 comments on commit 3ea4dad

Please sign in to comment.