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 3131 # For asyncio the actual client is returned and event loop is asyncio loop
3232
3333"""
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 4343"""
4444
4545
46- def deprecated (name ): # pragma: no cover
46+ def deprecated (name ): # pragma: no cover
4747 warnings .warn (WARNING .format (name ), DeprecationWarning )
Original file line number Diff line number Diff line change 5858 implements_to_string = lambda x : x
5959
6060 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
6171# --------------------------------------------------------------------------- #
6272# python > 2.5 compatability layer
6373# --------------------------------------------------------------------------- #
@@ -76,3 +86,11 @@ def implements_to_string(klass):
7686 klass .__unicode__ = klass .__str__
7787 klass .__str__ = lambda x : x .__unicode__ ().encode ('utf-8' )
7888 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