forked from SeldonIO/seldon-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imports_helper.py
84 lines (66 loc) · 2.22 KB
/
imports_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import logging
import textwrap
logger = logging.getLogger(__name__)
# Variables to check if certain extra dependencies are included or
# not
_TF_PRESENT = False
_GCS_PRESENT = False
_AZURE_PRESENT = False
try:
# Fix for https://github.com/SeldonIO/seldon-core/issues/1076
#
# If we do `import tensorflow` and there is a folder on the current path
# also named `tensorflow`, it may give a false positive even if the folder
# is not a Python package. This happens because, since PEP 420 got
# introduced in Python 3.3, folders without `__init__.py` can still get
# imported as namespaces.
#
# To avoid this and make the check more robust, we test the presence of
# the `make_ndarray` method inside the `tensorflow` import.
from tensorflow import make_ndarray # noqa: F401
_TF_PRESENT = True
except ImportError:
_TF_PRESENT = False
notice = textwrap.dedent(
"""
Tensorflow is not installed.
If you want to use `tftensor` and Tensorflow's data types
install `tensorflow` or install `seldon_core` as
$ pip install seldon_core[tensorflow]
or
$ pip install seldon_core[all]
"""
)
logger.info(notice)
try:
from google.cloud import storage # noqa: F401
_GCS_PRESENT = True
except ImportError:
_GCS_PRESENT = False
notice = textwrap.dedent(
"""
Support for Google Cloud Storage is not installed.
If you want to download resources from Google Cloud Storage
install `google-cloud-storage` or install `seldon_core` as
$ pip install seldon_core[gcs]
or
$ pip install seldon_core[all]
"""
)
logger.info(notice)
try:
from azure.storage.blob import BlockBlobService # noqa: F401
_AZURE_PRESENT = True
except ImportError:
_AZURE_PRESENT = False
notice = textwrap.dedent(
"""
Support for Azure Blob Storage is not installed.
If you want to download resources from Azure Blob Storage
install `azure-storage-blob` or install `seldon_core` as
$ pip install seldon_core[azure]
or
$ pip install seldon_core[all]
"""
)
logger.info(notice)