Skip to content

Commit 9967ff0

Browse files
authored
Replace distutils which is deprecated in 3.10 (#668)
* Replace distutils.version.Looseversion with pcg_resources.parse_version * Replace distutils.core.Command with setuptools.Command
1 parent e6674ec commit 9967ff0

File tree

8 files changed

+127
-127
lines changed

8 files changed

+127
-127
lines changed

examples/tools/test_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ elif [[ "`which easy_install`" != "" ]]; then
1616
INSTALL="easy_install -qU"
1717
else
1818
echo -e "\E[31m"
19-
echo "\E[31mPlease install distutils before continuing"
19+
echo "\E[31mPlease install setuptools before continuing"
2020
echo "wget http://peak.telecommunity.com/dist/ez_setup.py | sudo python"
2121
echo -e "\E[0m"
2222
exit -1

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
"""
3-
Installs pymodbus using distutils
3+
Installs pymodbus using setuptools
44
55
Run:
66
python setup.py install
@@ -123,4 +123,3 @@
123123
test_suite='nose.collector',
124124
cmdclass=command_classes,
125125
)
126-

setup_commands.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from distutils.core import Command
2-
import sys, os, shutil
3-
1+
import os
2+
import shutil
3+
import sys
4+
from setuptools import Command
45
# --------------------------------------------------------------------------- #
56
# Extra Commands
67
# --------------------------------------------------------------------------- #
@@ -12,7 +13,7 @@ class BuildApiDocsCommand(Command):
1213
build.py script underneath trying to build the api
1314
documentation for the given format.
1415
"""
15-
description = "build all the projects api documents"
16+
description = "build all the project's api documents"
1617
user_options = []
1718

1819
def initialize_options(self):
@@ -39,7 +40,7 @@ class DeepCleanCommand(Command):
3940
Helper command to return the directory to a completely
4041
clean state.
4142
"""
42-
description = "clean everything that we don't want"
43+
description = "clean everything that we don't want"
4344
user_options = []
4445
trash = ['build', 'dist', 'pymodbus.egg-info',
4546
os.path.join(os.path.join('doc', 'sphinx'), 'build'),
@@ -70,7 +71,7 @@ def _delete_pyc_files():
7071
for root, dirs, files in os.walk('.'):
7172
for file in files:
7273
if file.endswith('.pyc'):
73-
os.remove(os.path.join(root,file))
74+
os.remove(os.path.join(root, file))
7475

7576

7677
class LintCommand(Command):
@@ -111,15 +112,17 @@ def _try_pychecker(self):
111112
sys.argv = """pychecker pymodbus/*.py""".split()
112113
main()
113114
return True
114-
except: return False
115+
except Exception:
116+
return False
115117

116118
def _try_pylint(self):
117119
try:
118120
import pylint
119121
sys.argv = """pylint pymodbus/*.py""".split()
120122
main()
121123
return True
122-
except: return False
124+
except Exception:
125+
return False
123126

124127

125128
class Python3Command(Command):
@@ -150,7 +153,8 @@ def _run_python3(self):
150153
sys.argv = ['2to3'] + self.directories
151154
main("lib2to3.fixes")
152155
return True
153-
except: return False
156+
except Exception:
157+
return False
154158

155159

156160
class Pep8Command(Command):

test/test_client_async.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import pytest
66
from pymodbus.compat import IS_PYTHON3, PYTHON_VERSION
77
if IS_PYTHON3 and PYTHON_VERSION >= (3, 4):
8-
from unittest.mock import patch, Mock, MagicMock
8+
from unittest.mock import patch
99
import asyncio
1010
from pymodbus.client.asynchronous.async_io import ReconnectingAsyncioModbusTlsClient
1111
from pymodbus.client.asynchronous.async_io import AsyncioModbusSerialClient
12-
from serial_asyncio import SerialTransport
1312
else:
14-
from mock import patch, Mock, MagicMock
13+
from mock import patch
1514
import platform
16-
from distutils.version import LooseVersion
15+
from pkg_resources import parse_version
1716

1817
from pymodbus.client.asynchronous.serial import AsyncModbusSerialClient
1918
from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient
@@ -26,16 +25,17 @@
2625
from pymodbus.client.asynchronous import schedulers
2726
from pymodbus.factory import ClientDecoder
2827
from pymodbus.exceptions import ConnectionException
29-
from pymodbus.transaction import ModbusSocketFramer, ModbusTlsFramer, ModbusRtuFramer, ModbusAsciiFramer, ModbusBinaryFramer
28+
from pymodbus.transaction import ModbusSocketFramer, ModbusTlsFramer, ModbusRtuFramer
29+
from pymodbus.transaction import ModbusAsciiFramer, ModbusBinaryFramer
3030
from pymodbus.client.asynchronous.twisted import ModbusSerClientProtocol
3131

3232
import ssl
3333

3434
IS_DARWIN = platform.system().lower() == "darwin"
3535
IS_WINDOWS = platform.system().lower() == "windows"
36-
OSX_SIERRA = LooseVersion("10.12")
36+
OSX_SIERRA = parse_version("10.12")
3737
if IS_DARWIN:
38-
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < LooseVersion(platform.mac_ver()[0])
38+
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < parse_version(platform.mac_ver()[0])
3939
SERIAL_PORT = '/dev/ptyp0' if not IS_HIGH_SIERRA_OR_ABOVE else '/dev/ttyp0'
4040
else:
4141
IS_HIGH_SIERRA_OR_ABOVE = False
@@ -231,9 +231,9 @@ def handle_failure(failure):
231231
assert (not client.protocol._connected)
232232

233233
@pytest.mark.parametrize("method, framer", [("rtu", ModbusRtuFramer),
234-
("socket", ModbusSocketFramer),
235-
("binary", ModbusBinaryFramer),
236-
("ascii", ModbusAsciiFramer)])
234+
("socket", ModbusSocketFramer),
235+
("binary", ModbusBinaryFramer),
236+
("ascii", ModbusAsciiFramer)])
237237
def testSerialTornadoClient(self, method, framer):
238238
""" Test the serial tornado client client initialize """
239239
from serial import Serial
@@ -257,7 +257,7 @@ def handle_failure(failure):
257257
protocol.stop()
258258
assert(not client._connected)
259259

260-
@pytest.mark.skipif(IS_PYTHON3 , reason="requires python2.7")
260+
@pytest.mark.skipif(IS_PYTHON3, reason="requires python2.7")
261261
def testSerialAsyncioClientPython2(self):
262262
"""
263263
Test Serial asynchronous asyncio client exits on python2
@@ -272,10 +272,10 @@ def testSerialAsyncioClientPython2(self):
272272
@patch("asyncio.get_event_loop")
273273
@patch("asyncio.gather", side_effect=mock_asyncio_gather)
274274
@pytest.mark.parametrize("method, framer", [("rtu", ModbusRtuFramer),
275-
("socket", ModbusSocketFramer),
276-
("binary", ModbusBinaryFramer),
277-
("ascii", ModbusAsciiFramer)])
278-
def testSerialAsyncioClient(self, mock_gather, mock_event_loop, method, framer):
275+
("socket", ModbusSocketFramer),
276+
("binary", ModbusBinaryFramer),
277+
("ascii", ModbusAsciiFramer)])
278+
def testSerialAsyncioClient(self, mock_gather, mock_event_loop, method, framer):
279279
"""
280280
Test that AsyncModbusSerialClient instantiates AsyncioModbusSerialClient for asyncio scheduler.
281281
:return:

test/test_client_async_tornado.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pymodbus.compat import IS_PYTHON3
44
if IS_PYTHON3:
55
from unittest.mock import patch, Mock
6-
else: # Python 2
6+
else: # Python 2
77
from mock import patch, Mock
88
from pymodbus.client.asynchronous.tornado import (BaseTornadoClient,
99
AsyncModbusSerialClient, AsyncModbusUDPClient, AsyncModbusTCPClient
@@ -19,12 +19,12 @@
1919
# Fixture
2020
# ---------------------------------------------------------------------------#
2121
import platform
22-
from distutils.version import LooseVersion
22+
from pkg_resources import parse_version
2323

2424
IS_DARWIN = platform.system().lower() == "darwin"
25-
OSX_SIERRA = LooseVersion("10.12")
25+
OSX_SIERRA = parse_version("10.12")
2626
if IS_DARWIN:
27-
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < LooseVersion(platform.mac_ver()[0])
27+
IS_HIGH_SIERRA_OR_ABOVE = OSX_SIERRA < parse_version(platform.mac_ver()[0])
2828
SERIAL_PORT = '/dev/ptyp0' if not IS_HIGH_SIERRA_OR_ABOVE else '/dev/ttyp0'
2929
else:
3030
IS_HIGH_SIERRA_OR_ABOVE = False
@@ -43,8 +43,8 @@ class AsynchronousClientTest(unittest.TestCase):
4343
def testBaseClientInit(self):
4444
""" Test the client client initialize """
4545
client = BaseTornadoClient()
46-
self.assertTrue(client.port ==502)
47-
self.assertTrue(client.host =="127.0.0.1")
46+
self.assertTrue(client.port == 502)
47+
self.assertTrue(client.host == "127.0.0.1")
4848
self.assertEqual(0, len(list(client.transaction)))
4949
self.assertFalse(client._connected)
5050
self.assertTrue(client.io_loop is None)
@@ -95,7 +95,7 @@ def testBaseClientExecute(self, mock_iostream, mock_ioloop):
9595

9696
@patch("pymodbus.client.asynchronous.tornado.IOLoop")
9797
@patch("pymodbus.client.asynchronous.tornado.IOStream")
98-
def testBaseClientHandleResponse(self, mock_iostream, mock_ioloop):
98+
def testBaseClientHandleResponse(self, mock_iostream, mock_ioloop):
9999
""" Test the BaseTornado client handles responses """
100100
client = AsyncModbusTCPClient(port=5020)
101101
client.connect()
@@ -171,13 +171,15 @@ def handle_failure(failure):
171171
client.close()
172172
self.assertFalse(client._connected)
173173

174-
175174
# -----------------------------------------------------------------------#
176175
# Test Serial Client client
177176
# -----------------------------------------------------------------------#
178177
def testSerialClientInit(self):
179178
""" Test the tornado serial client client initialize """
180-
client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP, framer=ModbusRtuFramer(ClientDecoder()), port=SERIAL_PORT)
179+
client = AsyncModbusSerialClient(ioloop=schedulers.IO_LOOP,
180+
framer=ModbusRtuFramer(
181+
ClientDecoder()),
182+
port=SERIAL_PORT)
181183
self.assertEqual(0, len(list(client.transaction)))
182184
self.assertTrue(isinstance(client.framer, ModbusRtuFramer))
183185

@@ -309,6 +311,7 @@ def testModbusClientFactory(self):
309311
factory = ModbusClientFactory()
310312
self.assertTrue(factory is not None)
311313

314+
312315
# ---------------------------------------------------------------------------#
313316
# Main
314317
# ---------------------------------------------------------------------------#

0 commit comments

Comments
 (0)