| Total Complexity | 5 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from importlib import import_module |
||
| 2 | from importlib.util import find_spec |
||
| 3 | from types import ModuleType |
||
| 4 | |||
| 5 | |||
| 6 | def _check_package(*, package: str, extra: str) -> None: |
||
| 7 | if find_spec(package) is None: |
||
| 8 | message = ( |
||
| 9 | f'The `{package}` package is required for this.' |
||
| 10 | f' Install TorchIO with the `{extra}` extra:' |
||
| 11 | f' `pip install torchio[{extra}]`.' |
||
| 12 | ) |
||
| 13 | raise ImportError(message) |
||
| 14 | |||
| 15 | |||
| 16 | def _check_and_import(package: str, extra: str) -> ModuleType: |
||
| 17 | _check_package(package=package, extra=extra) |
||
| 18 | return import_module(package) |
||
| 19 | |||
| 20 | |||
| 21 | def get_pandas() -> ModuleType: |
||
| 22 | return _check_and_import(package='pandas', extra='csv') |
||
| 23 | |||
| 24 | |||
| 25 | def get_distinctipy() -> ModuleType: |
||
| 26 | return _check_and_import(package='distinctipy', extra='plot') |
||
| 27 |