gsitk_compat.py 947 Bytes
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
import logging

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
3
4
from pkg_resources import parse_version, get_distribution, DistributionNotFound

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
5
6
7
8
9
10
11
12
13
14
15
16
logger = logging.getLogger(__name__)

MSG = 'GSITK is not (properly) installed.'
IMPORTMSG = '{} Some functions will be unavailable.'.format(MSG)
RUNMSG = '{} Install it to use this function.'.format(MSG)


def raise_exception(*args, **kwargs):
    raise Exception(RUNMSG)


try:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
17
18
19
20
21
22
23
24
    gsitk_distro = get_distribution("gsitk")
    GSITK_VERSION = parse_version(gsitk_distro.version)
    GSITK_AVAILABLE = GSITK_VERSION > parse_version("0.1.9.1")  # Earlier versions have a bug
except DistributionNotFound:
    GSITK_AVAILABLE = False
    GSITK_VERSION = ()

if GSITK_AVAILABLE:
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
25
26
27
28
    from gsitk.datasets.datasets import DatasetManager
    from gsitk.evaluation.evaluation import Evaluation as Eval
    from sklearn.pipeline import Pipeline
    modules = locals()
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
29
else:
30
    logger.warning(IMPORTMSG)
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
31
    DatasetManager = Eval = Pipeline = raise_exception