Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace package_available with module_available #16607

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lightning/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os

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

_root_logger = logging.getLogger()
_logger = logging.getLogger(__name__)
Expand All @@ -28,7 +28,7 @@
if "__version__" not in locals():
if os.path.isfile(os.path.join(os.path.dirname(__file__), "__version__.py")):
from lightning.app.__version__ import version as __version__
elif package_available("lightning"):
elif module_available("lightning"):
from lightning import __version__ # noqa: F401

from lightning.app.core.app import LightningApp # noqa: E402
Expand Down
4 changes: 2 additions & 2 deletions src/lightning/app/cli/commands/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import click
import psutil
from lightning_utilities.core.imports import package_available
from lightning_utilities import module_available
from rich.progress import Progress

from lightning.app.utilities.cli_helpers import _LightningAppOpenAPIRetriever
Expand Down Expand Up @@ -316,7 +316,7 @@ def _install_missing_requirements(
if requirements:
missing_requirements = []
for req in requirements:
if not (package_available(req) or package_available(req.replace("-", "_"))):
if not (module_available(req) or module_available(req.replace("-", "_"))):
missing_requirements.append(req)

if missing_requirements:
Expand Down
4 changes: 2 additions & 2 deletions src/lightning/app/testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import requests
from lightning_cloud.openapi import V1LightningappInstanceState
from lightning_cloud.openapi.rest import ApiException
from lightning_utilities.core.imports import package_available
from lightning_utilities import module_available
from requests import Session
from rich import print
from rich.color import ANSI_COLOR_NAMES
Expand Down Expand Up @@ -153,7 +153,7 @@ def application_testing(lit_app_cls: Type[LightningTestApp] = LightningTestApp,

patch1 = mock.patch("lightning.app.LightningApp", lit_app_cls)
# we need to patch both only with the mirror package
patch2 = mock.patch("lightning.LightningApp", lit_app_cls) if package_available("lightning") else nullcontext()
patch2 = mock.patch("lightning.LightningApp", lit_app_cls) if module_available("lightning") else nullcontext()
with patch1, patch2:
original = sys.argv
sys.argv = command_line
Expand Down
4 changes: 2 additions & 2 deletions src/lightning/fabric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import logging
import os

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

if os.path.isfile(os.path.join(os.path.dirname(__file__), "__about__.py")):
from lightning.fabric.__about__ import * # noqa: F401, F403
if os.path.isfile(os.path.join(os.path.dirname(__file__), "__version__.py")):
from lightning.fabric.__version__ import version as __version__
elif package_available("lightning"):
elif module_available("lightning"):
from lightning import __version__ # type: ignore[misc] # noqa: F401

_root_logger = logging.getLogger()
Expand Down
12 changes: 6 additions & 6 deletions src/lightning/pytorch/utilities/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import sys

import torch
from lightning_utilities.core.imports import compare_version, package_available, RequirementCache
from lightning_utilities.core.imports import compare_version, module_available, RequirementCache

_PYTHON_GREATER_EQUAL_3_8_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 8)
_PYTHON_GREATER_EQUAL_3_10_0 = (sys.version_info.major, sys.version_info.minor) >= (3, 10)
# duplicated from fabric because HPU is patching it below
_TORCH_GREATER_EQUAL_1_13 = compare_version("torch", operator.ge, "1.13.0")
_TORCHMETRICS_GREATER_EQUAL_0_9_1 = RequirementCache("torchmetrics>=0.9.1")

_HABANA_FRAMEWORK_AVAILABLE = package_available("habana_frameworks")
_HABANA_FRAMEWORK_AVAILABLE = module_available("habana_frameworks")
_KINETO_AVAILABLE = torch.profiler.kineto_available()
_OMEGACONF_AVAILABLE = package_available("omegaconf")
_POPTORCH_AVAILABLE = package_available("poptorch")
_PSUTIL_AVAILABLE = package_available("psutil")
_RICH_AVAILABLE = package_available("rich") and compare_version("rich", operator.ge, "10.2.2")
_OMEGACONF_AVAILABLE = module_available("omegaconf")
_POPTORCH_AVAILABLE = module_available("poptorch")
carmocca marked this conversation as resolved.
Show resolved Hide resolved
_PSUTIL_AVAILABLE = module_available("psutil")
_RICH_AVAILABLE = module_available("rich") and compare_version("rich", operator.ge, "10.2.2")
_TORCH_QUANTIZE_AVAILABLE = bool([eg for eg in torch.backends.quantized.supported_engines if eg != "none"])
_TORCHVISION_AVAILABLE = RequirementCache("torchvision")

Expand Down
4 changes: 2 additions & 2 deletions tests/integrations_app/public/test_multi_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from integrations_app.public import _PATH_EXAMPLES
from lightning_utilities.core.imports import package_available
from lightning_utilities import module_available

from lightning.app.testing.helpers import _RunIf
from lightning.app.testing.testing import application_testing, LightningTestApp
Expand All @@ -19,7 +19,7 @@ def on_before_run_once(self):


# for the skip to work, the package needs to be installed without editable mode
_SKIP_LIGHTNING_UNAVAILABLE = pytest.mark.skipif(not package_available("lightning"), reason="script requires lightning")
_SKIP_LIGHTNING_UNAVAILABLE = pytest.mark.skipif(not module_available("lightning"), reason="script requires lightning")


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
import torch
from lightning_utilities.core.imports import module_available
from lightning_utilities import module_available
from lightning_utilities.test.warning import no_warning_call
from packaging.version import Version

Expand Down