Passed
Push — main ( 9f3cbe...a1ce2e )
by Fernando
01:38
created

torchio.external.imports.get_distinctipy()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 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