File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 31
31
# For asyncio the actual client is returned and event loop is asyncio loop
32
32
33
33
"""
34
- from pymodbus .client .async .deprecated .async import *
34
+ from pymodbus .compat import is_installed
35
+
36
+ installed = is_installed ('twisted' )
37
+ if installed :
38
+ # Import deprecated async client only if twisted is installed #338
39
+ from pymodbus .client .async .deprecated .async import *
40
+ else :
41
+ import logging
42
+ logger = logging .getLogger (__name__ )
43
+ logger .warning ("Not Importing deprecated clients. "
44
+ "Dependency Twisted is not Installed" )
Original file line number Diff line number Diff line change 43
43
"""
44
44
45
45
46
- def deprecated (name ): # pragma: no cover
46
+ def deprecated (name ): # pragma: no cover
47
47
warnings .warn (WARNING .format (name ), DeprecationWarning )
Original file line number Diff line number Diff line change 58
58
implements_to_string = lambda x : x
59
59
60
60
byte2int = lambda b : b
61
+ if PYTHON_VERSION >= (3 , 4 ):
62
+ def is_installed (module ):
63
+ import importlib .util
64
+ found = importlib .util .find_spec (module )
65
+ return found
66
+ else :
67
+ def is_installed (module ):
68
+ import importlib
69
+ found = importlib .find_loader (module )
70
+ return found
61
71
# --------------------------------------------------------------------------- #
62
72
# python > 2.5 compatability layer
63
73
# --------------------------------------------------------------------------- #
@@ -76,3 +86,11 @@ def implements_to_string(klass):
76
86
klass .__unicode__ = klass .__str__
77
87
klass .__str__ = lambda x : x .__unicode__ ().encode ('utf-8' )
78
88
return klass
89
+
90
+ def is_installed (module ):
91
+ import imp
92
+ try :
93
+ imp .find_module (module )
94
+ return True
95
+ except ImportError :
96
+ return False
You can’t perform that action at this time.
0 commit comments