def try_import(import_path: str) -> bool:
    """Try to import a module and return whether the import succeeded.

    This function attempts to dynamically import a Python module and handles any
    import errors gracefully. It is deprecated and will be removed in v2.0.0.
    Users should migrate to ``module_available`` from lightning-utilities instead.

    Args:
        import_path (str): The import path of the module to try importing. This can
            be a top-level package name (e.g. ``"torch"``) or a submodule path
            (e.g. ``"torch.nn"``).

    Returns:
        bool: ``True`` if the import succeeds, ``False`` if an ``ImportError``
            occurs.

    Warns:
        DeprecationWarning: This function is deprecated and will be removed in
            v2.0.0. Use ``module_available`` from lightning-utilities instead.

    Example:
        >>> from anomalib.utils.exceptions import try_import
        >>> # Try importing an optional dependency
        >>> has_torch = try_import("torch")
        >>> if not has_torch:
        ...     print("PyTorch is not installed")
        >>> # Try importing a submodule
        >>> has_torchvision = try_import("torchvision.transforms")
    """
    import warnings

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

    try:
        import_module(import_path)
    except ImportError:
        import_package = import_path.split(".")[0]
        logger.warning(
            f"Could not find {import_package}. To use this feature, ensure that you have {import_package} installed.",
        )
    else:
        return True
    return False
Try to import a module and return whether the import succeeded.

    This function attempts to dynamically import a Python module and handles any
    import errors gracefully. It is deprecated and will be removed in v2.0.0.
    Users should migrate to ``module_available`` from lightning-utilities instead.

    Args:
        import_path (str): The import path of the module to try importing. This can
            be a top-level package name (e.g. ``"torch"``) or a submodule path
            (e.g. ``"torch.nn"``).

    Returns:
        bool: ``True`` if the import succeeds, ``False`` if an ``ImportError``
            occurs.

    Warns:
        DeprecationWarning: This function is deprecated and will be removed in
            v2.0.0. Use ``module_available`` from lightning-utilities instead.

    Example:
        >>> from anomalib.utils.exceptions import try_import
        >>> # Try importing an optional dependency
        >>> has_torch = try_import("torch")
        >>> if not has_torch:
        ...     print("PyTorch is not installed")
        >>> # Try importing a submodule
        >>> has_torchvision = try_import("torchvision.transforms")
    
src/anomalib/utils/exceptions/imports.py