Skip to content

Commit

Permalink
Remove pkg_resources imports and use packaging instead (openvinotoolk…
Browse files Browse the repository at this point in the history
…it#2082)

remove pkg_resources imports and use packaging instead

Co-authored-by: Samet Akcay <samet.akcay@intel.com>
  • Loading branch information
davnn and samet-akcay committed Jul 5, 2024
1 parent c3e0b38 commit c9297a5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- Remove deprecated `pkg_resources` dependencies, install `packaging` instead by @davnn in (<https://github.com/openvinotoolkit/anomalib/pull/2082>)
- WinCLIP: set device in text embedding collection and apply forward pass with no grad, by @djdameln in https://github.com/openvinotoolkit/anomalib/pull/1984
- 🔨 Move all export functionalities to AnomalyModule as base methods by @thinhngo-x in (<https://github.com/openvinotoolkit/anomalib/pull/1803>)
- ⬆️ Update torch and lightning package versions by @samet-akcay in https://github.com/openvinotoolkit/anomalib/pull/1949
- 🔨 Use default model-specific eval transform when only train_transform specified by @djdameln(https://github.com/djdameln) in (<https://github.com/openvinotoolkit/anomalib/pull/1953>)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"jsonargparse[signatures]>=4.27.7",
"docstring_parser", # CLI help-formatter
"rich_argparse", # CLI help-formatter
"packaging"
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/anomalib/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging

from pkg_resources import Requirement
from packaging.requirements import Requirement
from rich.console import Console
from rich.logging import RichHandler

Expand Down
6 changes: 3 additions & 3 deletions src/anomalib/cli/utils/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pathlib import Path
from warnings import warn

from pkg_resources import Requirement
from packaging.requirements import Requirement

AVAILABLE_TORCH_VERSIONS = {
"2.0.0": {"torchvision": "0.15.1", "cuda": ("11.7", "11.8")},
Expand Down Expand Up @@ -293,7 +293,7 @@ def add_hardware_suffix_to_torch(
Defaults to False.
Examples:
>>> from pkg_resources import Requirement
>>> from packaging.requirements import Requirement
>>> req = "torch>=1.13.0, <=2.0.1"
>>> requirement = Requirement.parse(req)
>>> requirement.name, requirement.specs
Expand Down Expand Up @@ -364,7 +364,7 @@ def get_torch_install_args(requirement: str | Requirement) -> list[str]:
RuntimeError: If the OS is not supported.
Example:
>>> from pkg_resources import Requirement
>>> from packaging.requirements import Requirement
>>> requriment = "torch>=1.13.0"
>>> get_torch_install_args(requirement)
['--extra-index-url', 'https://download.pytorch.org/whl/cpu',
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/models/video/ai_vad/clip/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import requests
import torch
from PIL import Image
from pkg_resources import packaging
from packaging import version
from torchvision.transforms import CenterCrop, Compose, Normalize, Resize, ToTensor
from tqdm import tqdm

Expand All @@ -33,7 +33,7 @@
BICUBIC = Image.BICUBIC


if packaging.version.parse(torch.__version__) < packaging.version.parse("1.7.1"):
if version.parse(torch.__version__) < version.parse("1.7.1"):
msg = "PyTorch version 1.7.1 or higher is recommended"
logger.warn(msg)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cli/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path

import pytest
from pkg_resources import Requirement
from packaging.requirements import Requirement
from pytest_mock import MockerFixture

from anomalib.cli.utils.installation import (
Expand Down

0 comments on commit c9297a5

Please sign in to comment.