-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADD import sanity checks * FIX linter * Fix linting * FIX json
- Loading branch information
Showing
7 changed files
with
156 additions
and
4 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from typing import Optional | ||
|
||
from ..components import BaseComponent, monitor_exec | ||
|
||
|
||
|
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,5 @@ | ||
"""Custom exceptions raised during sanity checks for itwinai.""" | ||
|
||
|
||
class SanityCheckError(Exception): | ||
"""Base exception for all sanity check errors.""" |
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,104 @@ | ||
|
||
import importlib | ||
from typing import List | ||
|
||
from .exceptions import SanityCheckError | ||
|
||
core_modules = [ | ||
'itwinai', | ||
'itwinai.cli', | ||
'itwinai.components', | ||
'itwinai.distributed', | ||
'itwinai.loggers', | ||
'itwinai.parser', | ||
'itwinai.pipeline', | ||
'itwinai.serialization', | ||
'itwinai.type', | ||
'itwinai.utils', | ||
'itwinai.tests', | ||
'itwinai.tests.dummy_components', | ||
'itwinai.tests.exceptions', | ||
'itwinai.tests.sanity_check', | ||
'itwinai.plugins' | ||
] | ||
|
||
torch_modules = [ | ||
'itwinai.torch', | ||
'itwinai.torch.data', | ||
'itwinai.torch.models', | ||
'itwinai.torch.models.mnist', | ||
'itwinai.torch.config', | ||
'itwinai.torch.distributed', | ||
'itwinai.torch.inference', | ||
'itwinai.torch.mlflow', | ||
'itwinai.torch.reproducibility', | ||
'itwinai.torch.trainer', | ||
'itwinai.torch.type', | ||
] | ||
|
||
tensorflow_modules = [ | ||
'itwinai.tensorflow', | ||
'itwinai.tensorflow.data', | ||
'itwinai.tensorflow.models', | ||
'itwinai.tensorflow.models.mnist', | ||
'itwinai.tensorflow.distributed', | ||
'itwinai.tensorflow.trainer', | ||
'itwinai.tensorflow.utils', | ||
] | ||
|
||
|
||
def run_sanity_check(modules: List[str]): | ||
"""Run sanity checks by trying to import modules. | ||
Args: | ||
modules (List[str]): list of modules | ||
Raises: | ||
SanityCheckError: when some module cannot be imported. | ||
""" | ||
failed_imports = [] | ||
|
||
for module in modules: | ||
try: | ||
importlib.import_module(module) | ||
print(f"✅ Successfully imported: {module}") | ||
except ImportError as e: | ||
failed_imports.append((module, str(e))) | ||
print(f"❌ Failed to import: {module} - {e}") | ||
|
||
if failed_imports: | ||
err_msg = "\nSummary of failed imports:\n" | ||
for module, error in failed_imports: | ||
err_msg += f"Module: {module}, Error: {error}\n" | ||
|
||
raise SanityCheckError( | ||
"Not all itwinai modules could be successfully imported!\n" | ||
+ err_msg | ||
) | ||
else: | ||
print("\nAll modules imported successfully!") | ||
|
||
|
||
def sanity_check_slim(): | ||
"""Run sanity check on the installation | ||
of core modules of itwinai (neither itwinai.torch, | ||
nor itwinai.tensorflow).""" | ||
|
||
run_sanity_check(modules=core_modules) | ||
|
||
|
||
def sanity_check_torch(): | ||
"""Run sanity check on the installation of itwinai | ||
for a torch environment.""" | ||
run_sanity_check(modules=core_modules+torch_modules) | ||
|
||
|
||
def sanity_check_tensorflow(): | ||
"""Run sanity check on the installation of itwinai | ||
for a tensorflow environment.""" | ||
run_sanity_check(modules=core_modules+tensorflow_modules) | ||
|
||
|
||
def sanity_check_all(): | ||
"""Run all sanity checks.""" | ||
run_sanity_check(modules=core_modules+torch_modules+tensorflow_modules) |