-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
428 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,14 @@ jobs: | |
actions-ref: main | ||
|
||
check-schema: | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].0 | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].2 | ||
with: | ||
azure-dir: "" | ||
|
||
check-package: | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].0 | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].2 | ||
with: | ||
actions-ref: v0.11.0 | ||
actions-ref: v0.11.2 | ||
import-name: "litdata" | ||
artifact-name: dist-packages-${{ github.sha }} | ||
testing-matrix: | | ||
|
@@ -35,6 +35,6 @@ jobs: | |
} | ||
check-docs: | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].0 | ||
uses: Lightning-AI/utilities/.github/workflows/[email protected].2 | ||
with: | ||
requirements-file: "requirements/docs.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
lightning-cloud == 0.5.64 # Must be pinned to ensure compatibility | ||
lightning-utilities >=0.8.0, <0.11.0 | ||
torch >=2.1.0 | ||
filelock | ||
tqdm | ||
numpy | ||
torchvision | ||
pillow | ||
viztracer | ||
pyarrow | ||
boto3[crt] | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
torchvision | ||
pillow | ||
viztracer | ||
pyarrow | ||
tqdm | ||
lightning-cloud == 0.5.65 # Must be pinned to ensure compatibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
coverage ==7.4.3 | ||
coverage ==7.4.4 | ||
pytest ==8.0.2 | ||
pytest-cov ==4.1.0 | ||
pytest-timeout ==2.2.0 | ||
pytest-rerunfailures ==12.0 | ||
pytest-timeout ==2.3.1 | ||
pytest-rerunfailures ==14.0 | ||
pytest-random-order ==1.1.1 | ||
pandas | ||
lightning | ||
lightning-cloud == 0.5.65 # Must be pinned to ensure compatibility |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Copyright The Lightning AI team. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import importlib | ||
from functools import lru_cache | ||
from importlib.util import find_spec | ||
from typing import Optional, TypeVar | ||
|
||
import pkg_resources | ||
from typing_extensions import ParamSpec | ||
|
||
T = TypeVar("T") | ||
P = ParamSpec("P") | ||
|
||
|
||
@lru_cache | ||
def package_available(package_name: str) -> bool: | ||
"""Check if a package is available in your environment. | ||
>>> package_available('os') | ||
True | ||
>>> package_available('bla') | ||
False | ||
""" | ||
try: | ||
return find_spec(package_name) is not None | ||
except ModuleNotFoundError: | ||
return False | ||
|
||
|
||
@lru_cache | ||
def module_available(module_path: str) -> bool: | ||
"""Check if a module path is available in your environment. | ||
>>> module_available('os') | ||
True | ||
>>> module_available('os.bla') | ||
False | ||
>>> module_available('bla.bla') | ||
False | ||
""" | ||
module_names = module_path.split(".") | ||
if not package_available(module_names[0]): | ||
return False | ||
try: | ||
importlib.import_module(module_path) | ||
except ImportError: | ||
return False | ||
return True | ||
|
||
|
||
class RequirementCache: | ||
"""Boolean-like class to check for requirement and module availability. | ||
Args: | ||
requirement: The requirement to check, version specifiers are allowed. | ||
module: The optional module to try to import if the requirement check fails. | ||
>>> RequirementCache("torch>=0.1") | ||
Requirement 'torch>=0.1' met | ||
>>> bool(RequirementCache("torch>=0.1")) | ||
True | ||
>>> bool(RequirementCache("torch>100.0")) | ||
False | ||
>>> RequirementCache("torch") | ||
Requirement 'torch' met | ||
>>> bool(RequirementCache("torch")) | ||
True | ||
>>> bool(RequirementCache("unknown_package")) | ||
False | ||
""" | ||
|
||
def __init__(self, requirement: str, module: Optional[str] = None) -> None: | ||
self.requirement = requirement | ||
self.module = module | ||
|
||
def _check_requirement(self) -> None: | ||
if hasattr(self, "available"): | ||
return | ||
try: | ||
# first try the pkg_resources requirement | ||
pkg_resources.require(self.requirement) | ||
self.available = True | ||
self.message = f"Requirement {self.requirement!r} met" | ||
except Exception as ex: | ||
self.available = False | ||
self.message = f"{ex.__class__.__name__}: {ex}. HINT: Try running `pip install -U {self.requirement!r}`" | ||
requirement_contains_version_specifier = any(c in self.requirement for c in "=<>") | ||
if not requirement_contains_version_specifier or self.module is not None: | ||
module = self.requirement if self.module is None else self.module | ||
# sometimes `pkg_resources.require()` fails but the module is importable | ||
self.available = module_available(module) | ||
if self.available: | ||
self.message = f"Module {module!r} available" | ||
|
||
def __bool__(self) -> bool: | ||
"""Format as bool.""" | ||
self._check_requirement() | ||
return self.available | ||
|
||
def __str__(self) -> str: | ||
"""Format as string.""" | ||
self._check_requirement() | ||
return self.message | ||
|
||
def __repr__(self) -> str: | ||
"""Format as string.""" | ||
return self.__str__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright The Lightning AI team. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.