Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pymodbus/client/async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@
# For asyncio the actual client is returned and event loop is asyncio loop

"""
from pymodbus.client.async.deprecated.async import *
from pymodbus.compat import is_installed

installed = is_installed('twisted')
if installed:
# Import deprecated async client only if twisted is installed #338
from pymodbus.client.async.deprecated.async import *
else:
import logging
logger = logging.getLogger(__name__)
logger.warning("Not Importing deprecated clients. "
"Dependency Twisted is not Installed")
2 changes: 1 addition & 1 deletion pymodbus/client/async/deprecated/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"""


def deprecated(name): # pragma: no cover
def deprecated(name): # pragma: no cover
warnings.warn(WARNING.format(name), DeprecationWarning)
18 changes: 18 additions & 0 deletions pymodbus/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
implements_to_string = lambda x: x

byte2int = lambda b: b
if PYTHON_VERSION >= (3, 4):
def is_installed(module):
import importlib.util
found = importlib.util.find_spec(module)
return found
else:
def is_installed(module):
import importlib
found = importlib.find_loader(module)
return found
# --------------------------------------------------------------------------- #
# python > 2.5 compatability layer
# --------------------------------------------------------------------------- #
Expand All @@ -76,3 +86,11 @@ def implements_to_string(klass):
klass.__unicode__ = klass.__str__
klass.__str__ = lambda x: x.__unicode__().encode('utf-8')
return klass

def is_installed(module):
import imp
try:
imp.find_module(module)
return True
except ImportError:
return False