Skip to content

Commit

Permalink
🐞Replace package_available with module_available (#2407)
Browse files Browse the repository at this point in the history
  • Loading branch information
harimkang authored Nov 5, 2024
1 parent 6ed0067 commit bcc0b43
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/anomalib/cli/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import logging

from jsonargparse import Namespace
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available

from anomalib.cli.utils.help_formatter import get_short_docstring

logger = logging.getLogger(__name__)

if package_available("anomalib.pipelines"):
if module_available("anomalib.pipelines"):
from anomalib.pipelines import Benchmark
from anomalib.pipelines.components.base import Pipeline

Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/cli/utils/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import logging

from jsonargparse import ArgumentParser
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available

logger = logging.getLogger(__name__)


if package_available("openvino"):
if module_available("openvino"):
from openvino.tools.ovc.cli_parser import get_common_cli_parser
else:
get_common_cli_parser = None
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/deploy/inferencers/openvino_inferencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import cv2
import numpy as np
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available
from omegaconf import DictConfig
from PIL import Image

Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(
task: str | None = None,
config: dict | None = None,
) -> None:
if not package_available("openvino"):
if not module_available("openvino"):
msg = "OpenVINO is not installed. Please install OpenVINO to use OpenVINOInferencer."
raise ImportError(msg)

Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/loggers/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from lightning.fabric.utilities.types import _PATH
from lightning.pytorch.loggers.wandb import WandbLogger
from lightning.pytorch.utilities import rank_zero_only
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available
from matplotlib.figure import Figure

from .base import ImageLoggerBase

if package_available("wandb"):
if module_available("wandb"):
import wandb

if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions src/anomalib/models/components/base/export_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np
import torch
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available
from torch import nn
from torchmetrics import Metric
from torchvision.transforms.v2 import Transform
Expand Down Expand Up @@ -245,7 +245,7 @@ def to_openvino(
... task="segmentation",
... )
"""
if not package_available("openvino"):
if not module_available("openvino"):
logger.exception("Could not find OpenVINO. Please check OpenVINO installation.")
raise ModuleNotFoundError

Expand Down Expand Up @@ -294,7 +294,7 @@ def _compress_ov_model(
Returns:
model (CompiledModel): Model in the OpenVINO format compressed with NNCF quantization.
"""
if not package_available("nncf"):
if not module_available("nncf"):
logger.exception("Could not find NCCF. Please check NNCF installation.")
raise ModuleNotFoundError

Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/models/image/vlm_ad/backends/chat_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from typing import TYPE_CHECKING

from dotenv import load_dotenv
from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available

from anomalib.models.image.vlm_ad.utils import Prompt

from .base import Backend

if package_available("openai"):
if module_available("openai"):
from openai import OpenAI
else:
OpenAI = None
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/models/image/vlm_ad/backends/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
from typing import TYPE_CHECKING

from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available
from PIL import Image

from anomalib.models.image.vlm_ad.utils import Prompt
Expand All @@ -18,7 +18,7 @@
from transformers.modeling_utils import PreTrainedModel
from transformers.processing_utils import ProcessorMixin

if package_available("transformers"):
if module_available("transformers"):
import transformers
else:
transformers = None
Expand Down
4 changes: 2 additions & 2 deletions src/anomalib/models/image/vlm_ad/backends/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import logging
from pathlib import Path

from lightning_utilities.core.imports import package_available
from lightning_utilities.core.imports import module_available

from anomalib.models.image.vlm_ad.utils import Prompt

from .base import Backend

if package_available("ollama"):
if module_available("ollama"):
from ollama import chat
from ollama._client import _encode_image
else:
Expand Down
2 changes: 1 addition & 1 deletion src/anomalib/utils/exceptions/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def try_import(import_path: str) -> bool:

warnings.warn(
"The 'try_import' function is deprecated and will be removed in v2.0.0. "
"Use 'package_available' from lightning-utilities instead.",
"Use 'module_available' from lightning-utilities instead.",
DeprecationWarning,
stacklevel=2,
)
Expand Down

0 comments on commit bcc0b43

Please sign in to comment.