-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathimport_helper.py
More file actions
executable file
·107 lines (88 loc) · 2.83 KB
/
Copy pathimport_helper.py
File metadata and controls
executable file
·107 lines (88 loc) · 2.83 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import importlib
from typing import List
import ding
from .default_helper import one_time_warning
def try_import_ceph():
"""
Overview:
Try import ceph module, if failed, return ``None``
Returns:
- (:obj:`Module`): Imported module, or ``None`` when ceph not found
"""
try:
import ceph
client = ceph.S3Client()
return client
except ModuleNotFoundError as e:
try:
from petrel_client.client import Client
client = Client(conf_path='~/petreloss.conf')
return client
except ModuleNotFoundError as e:
one_time_warning("You have not installed ceph package! DI-engine has changed to some alternatives.")
ceph = None
return ceph
def try_import_mc():
"""
Overview:
Try import mc module, if failed, return ``None``
Returns:
- (:obj:`Module`): Imported module, or ``None`` when mc not found
"""
try:
import mc
except ModuleNotFoundError as e:
one_time_warning("You have not installed memcache package! DI-engine has changed to some alternatives.")
mc = None
return mc
def try_import_redis():
"""
Overview:
Try import redis module, if failed, return ``None``
Returns:
- (:obj:`Module`): Imported module, or ``None`` when redis not found
"""
try:
import redis
except ModuleNotFoundError as e:
one_time_warning("You have not installed redis package! DI-engine has changed to some alternatives.")
redis = None
return redis
def try_import_rediscluster():
"""
Overview:
Try import rediscluster module, if failed, return ``None``
Returns:
- (:obj:`Module`): Imported module, or ``None`` when rediscluster not found
"""
try:
import rediscluster
except ModuleNotFoundError as e:
one_time_warning("You have not installed rediscluster package! DI-engine has changed to some alternatives.")
rediscluster = None
return rediscluster
def try_import_link():
"""
Overview:
Try import linklink module, if failed, import ding.tests.fake_linklink instead
Returns:
- (:obj:`Module`): Imported module (may be ``fake_linklink``)
"""
if ding.enable_linklink:
try:
import linklink as link
except ModuleNotFoundError as e:
one_time_warning("You have not installed linklink package! DI-engine has changed to some alternatives.")
from .fake_linklink import link
else:
from .fake_linklink import link
return link
def import_module(modules: List[str]) -> None:
"""
Overview:
Import several module as a list
Arguments:
- (:obj:`str list`): List of module names
"""
for name in modules:
importlib.import_module(name)