diff --git a/examples/client_async.py b/examples/client_async.py index bb0d3164b2..c9c368fb7d 100755 --- a/examples/client_async.py +++ b/examples/client_async.py @@ -20,9 +20,9 @@ The corresponding server must be started before e.g. as: python3 server_sync.py """ -import os import asyncio import logging +import os # --------------------------------------------------------------------------- # # import the various client implementations diff --git a/examples/client_async_basic_calls.py b/examples/client_async_basic_calls.py index 6aa9d2fc67..846ecd404f 100755 --- a/examples/client_async_basic_calls.py +++ b/examples/client_async_basic_calls.py @@ -9,8 +9,8 @@ import asyncio import logging -from examples.helper import get_commandline from examples.client_async import run_async_client, setup_async_client +from examples.helper import get_commandline _logger = logging.getLogger() diff --git a/examples/client_async_extended_calls.py b/examples/client_async_extended_calls.py index cd263c06d9..ad7b873502 100755 --- a/examples/client_async_extended_calls.py +++ b/examples/client_async_extended_calls.py @@ -25,9 +25,8 @@ import asyncio import logging -from examples.helper import get_commandline from examples.client_async import run_async_client, setup_async_client - +from examples.helper import get_commandline from pymodbus.diag_message import ( ChangeAsciiInputDelimiterRequest, ClearCountersRequest, @@ -54,6 +53,7 @@ ReportSlaveIdRequest, ) + _logger = logging.getLogger() UNIT = 0x01 diff --git a/examples/client_payload.py b/examples/client_payload.py index 473efd4226..c790ee7702 100755 --- a/examples/client_payload.py +++ b/examples/client_payload.py @@ -7,8 +7,8 @@ Works out of the box together with payload_server.py """ -from collections import OrderedDict import logging +from collections import OrderedDict from pymodbus.client import ModbusTcpClient as ModbusClient from pymodbus.constants import Endian diff --git a/examples/client_sync.py b/examples/client_sync.py index 321c7e9b85..cd9f8999fd 100755 --- a/examples/client_sync.py +++ b/examples/client_sync.py @@ -20,8 +20,8 @@ The corresponding server must be started before e.g. as: python3 server_sync.py """ -import os import logging +import os # --------------------------------------------------------------------------- # # import the various client implementations diff --git a/examples/client_sync_basic_calls.py b/examples/client_sync_basic_calls.py index 509aedc66d..d5ae1bef00 100755 --- a/examples/client_sync_basic_calls.py +++ b/examples/client_sync_basic_calls.py @@ -8,8 +8,8 @@ """ import logging -from examples.helper import get_commandline from examples.client_sync import run_sync_client, setup_sync_client +from examples.helper import get_commandline _logger = logging.getLogger() diff --git a/examples/client_sync_extended_calls.py b/examples/client_sync_extended_calls.py index 7a6d92d844..fb80a19052 100755 --- a/examples/client_sync_extended_calls.py +++ b/examples/client_sync_extended_calls.py @@ -24,9 +24,8 @@ """ import logging -from examples.helper import get_commandline from examples.client_sync import run_sync_client, setup_sync_client - +from examples.helper import get_commandline from pymodbus.diag_message import ( ChangeAsciiInputDelimiterRequest, ClearCountersRequest, diff --git a/examples/common/custom_synchronous_server.py b/examples/common/custom_synchronous_server.py index 8e72e63ed7..b2d1366de6 100755 --- a/examples/common/custom_synchronous_server.py +++ b/examples/common/custom_synchronous_server.py @@ -57,10 +57,6 @@ def decode(self, data): """ import logging -from .custom_message import ( # pylint: disable=relative-beyond-top-level - CustomModbusRequest, -) - from pymodbus.datastore import ( ModbusSequentialDataBlock, ModbusServerContext, @@ -70,6 +66,10 @@ def decode(self, data): from pymodbus.server import StartTcpServer from pymodbus.version import version +from .custom_message import ( # pylint: disable=relative-beyond-top-level + CustomModbusRequest, +) + # --------------------------------------------------------------------------- # # configure the service logging diff --git a/examples/common/performance.py b/examples/common/performance.py index 3349aaab2c..d4a36e2a2f 100755 --- a/examples/common/performance.py +++ b/examples/common/performance.py @@ -5,21 +5,23 @@ The following is an quick performance check of the synchronous modbus client. """ -from concurrent.futures import ThreadPoolExecutor as eWorker, as_completed - # --------------------------------------------------------------------------- # # import the necessary modules # --------------------------------------------------------------------------- # import logging import os -from threading import Lock, Thread as tWorker +from concurrent.futures import ThreadPoolExecutor as eWorker +from concurrent.futures import as_completed +from threading import Lock +from threading import Thread as tWorker from time import time from pymodbus.client import ModbusTcpClient try: - from multiprocessing import Process as mWorker, log_to_stderr + from multiprocessing import Process as mWorker + from multiprocessing import log_to_stderr except ImportError: log_to_stderr = logging.getLogger diff --git a/examples/contrib/concurrent_client.py b/examples/contrib/concurrent_client.py index 26bbb197cb..3cacf3c36f 100755 --- a/examples/contrib/concurrent_client.py +++ b/examples/contrib/concurrent_client.py @@ -6,8 +6,6 @@ a high level of concurrency by using worker threads/processes to handle writing/reading from one or more client handles at once. """ -from collections import namedtuple -from concurrent.futures import Future import itertools # -------------------------------------------------------------------------- # @@ -15,13 +13,13 @@ # -------------------------------------------------------------------------- # import logging import multiprocessing -from multiprocessing import ( - Event as mEvent, - Process as mProcess, - Queue as mQueue, -) -from queue import Queue as qQueue import threading +from collections import namedtuple +from concurrent.futures import Future +from multiprocessing import Event as mEvent +from multiprocessing import Process as mProcess +from multiprocessing import Queue as mQueue +from queue import Queue as qQueue from threading import Event, Thread # -------------------------------------------------------------------------- # diff --git a/examples/contrib/message_generator.py b/examples/contrib/message_generator.py index eea3d8a221..c27c425a0d 100755 --- a/examples/contrib/message_generator.py +++ b/examples/contrib/message_generator.py @@ -14,6 +14,7 @@ import logging from optparse import OptionParser # pylint: disable=deprecated-module +import pymodbus.diag_message as modbus_diag from pymodbus.bit_read_message import ( ReadCoilsRequest, ReadCoilsResponse, @@ -26,7 +27,6 @@ WriteSingleCoilRequest, WriteSingleCoilResponse, ) -import pymodbus.diag_message as modbus_diag from pymodbus.file_message import ( ReadFifoQueueRequest, ReadFifoQueueResponse, diff --git a/examples/contrib/message_parser.py b/examples/contrib/message_parser.py index 761bf71dfe..a076ec3d5c 100755 --- a/examples/contrib/message_parser.py +++ b/examples/contrib/message_parser.py @@ -17,8 +17,8 @@ import codecs as c import collections import logging -from optparse import OptionParser # pylint: disable=deprecated-module import textwrap +from optparse import OptionParser # pylint: disable=deprecated-module from pymodbus.factory import ClientDecoder, ServerDecoder from pymodbus.transaction import ( diff --git a/examples/contrib/modbus_mapper.py b/examples/contrib/modbus_mapper.py index c69da8d9fa..30aa60f92a 100644 --- a/examples/contrib/modbus_mapper.py +++ b/examples/contrib/modbus_mapper.py @@ -124,16 +124,14 @@ StartTcpServer(context=context, identity=identity, address=("localhost", 5020)) """ -from collections import defaultdict import csv -from io import StringIO import json +from collections import defaultdict +from io import StringIO from tokenize import generate_tokens -from pymodbus.datastore import ( - ModbusSlaveContext, - ModbusSparseDataBlock, -) +from pymodbus.datastore import ModbusSlaveContext, ModbusSparseDataBlock + # --------------------------------------------------------------------------- # # raw mapping input parsers diff --git a/examples/contrib/modbus_simulator.py b/examples/contrib/modbus_simulator.py index 96a3b6efa0..f7310badb2 100644 --- a/examples/contrib/modbus_simulator.py +++ b/examples/contrib/modbus_simulator.py @@ -5,8 +5,8 @@ with read/write data as well as user configurable base data """ import logging -from optparse import OptionParser # pylint: disable=deprecated-module import pickle # nosec +from optparse import OptionParser # pylint: disable=deprecated-module from pymodbus.datastore import ModbusServerContext, ModbusSlaveContext from pymodbus.server import StartTcpServer diff --git a/examples/contrib/thread_safe_datastore.py b/examples/contrib/thread_safe_datastore.py index 8d9d4c8dce..cb085fb7e3 100644 --- a/examples/contrib/thread_safe_datastore.py +++ b/examples/contrib/thread_safe_datastore.py @@ -1,7 +1,7 @@ # pylint: disable=missing-type-doc """Thread safe datastore.""" -from contextlib import contextmanager import threading +from contextlib import contextmanager from pymodbus.datastore.store import BaseModbusDataBlock diff --git a/examples/contrib/tornado_twisted/modbus_scraper.py b/examples/contrib/tornado_twisted/modbus_scraper.py index 0ddbe6a781..a226a4dc1d 100755 --- a/examples/contrib/tornado_twisted/modbus_scraper.py +++ b/examples/contrib/tornado_twisted/modbus_scraper.py @@ -5,10 +5,13 @@ them as a collection of sequential data blocks. """ import logging -from optparse import OptionParser import pickle # nosec +from optparse import OptionParser -from twisted.internet import reactor, serialport # pylint: disable=import-error +from twisted.internet import ( # pylint: disable=import-error + reactor, + serialport, +) from twisted.internet.protocol import ( ClientFactory, # pylint: disable=import-error ) diff --git a/examples/serial_forwarder.py b/examples/serial_forwarder.py index 99782b3ab7..86d1c234e8 100644 --- a/examples/serial_forwarder.py +++ b/examples/serial_forwarder.py @@ -4,14 +4,15 @@ python3 serial_forwarder.py --log DEBUG --port "/dev/ttyUSB0" --baudrate 9600 --server_ip "192.168.1.27" --server_port 5020 --slaves 1 2 3 """ import argparse +import asyncio import logging import signal -import asyncio -from pymodbus.server.async_io import ModbusTcpServer from pymodbus.client import ModbusSerialClient from pymodbus.datastore import ModbusServerContext from pymodbus.datastore.remote import RemoteSlaveContext +from pymodbus.server.async_io import ModbusTcpServer + FORMAT = "%(asctime)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s" logging.basicConfig(format=FORMAT) diff --git a/examples/server_async.py b/examples/server_async.py index cd7d975113..59e2f86577 100755 --- a/examples/server_async.py +++ b/examples/server_async.py @@ -27,9 +27,9 @@ The corresponding client can be started as: python3 client_sync.py """ -import os import asyncio import logging +import os from examples.helper import get_commandline from pymodbus.datastore import ( diff --git a/examples/server_sync.py b/examples/server_sync.py index ec7fc1b98b..560cfab330 100755 --- a/examples/server_sync.py +++ b/examples/server_sync.py @@ -31,8 +31,8 @@ is just a thin cover on top of the async server and is in some aspects a lot slower. """ -import os import logging +import os from examples.helper import get_commandline from examples.server_async import setup_server diff --git a/pymodbus/bit_read_message.py b/pymodbus/bit_read_message.py index be9d89e9ba..6fcdb436ea 100644 --- a/pymodbus/bit_read_message.py +++ b/pymodbus/bit_read_message.py @@ -3,11 +3,8 @@ import struct from pymodbus.constants import Defaults -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse from pymodbus.utilities import pack_bitstring, unpack_bitstring diff --git a/pymodbus/bit_write_message.py b/pymodbus/bit_write_message.py index 3d6cb10c7d..2292a34fad 100644 --- a/pymodbus/bit_write_message.py +++ b/pymodbus/bit_write_message.py @@ -6,11 +6,8 @@ import struct from pymodbus.constants import ModbusStatus -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse from pymodbus.utilities import pack_bitstring, unpack_bitstring diff --git a/pymodbus/client/__init__.py b/pymodbus/client/__init__.py index 904de56d7c..236dcd43b2 100644 --- a/pymodbus/client/__init__.py +++ b/pymodbus/client/__init__.py @@ -2,11 +2,11 @@ import external classes, to make them easier to use: """ +from pymodbus.client.base import ModbusBaseClient from pymodbus.client.serial import AsyncModbusSerialClient, ModbusSerialClient from pymodbus.client.tcp import AsyncModbusTcpClient, ModbusTcpClient from pymodbus.client.tls import AsyncModbusTlsClient, ModbusTlsClient from pymodbus.client.udp import AsyncModbusUdpClient, ModbusUdpClient -from pymodbus.client.base import ModbusBaseClient # ---------------------------------------------------------------------------# diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 500e6ad286..e7fff3e70a 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -2,9 +2,9 @@ from __future__ import annotations import asyncio -from dataclasses import dataclass import logging import socket +from dataclasses import dataclass from pymodbus.client.mixin import ModbusClientMixin from pymodbus.constants import Defaults diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index b50a619d8f..72a89456b4 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -4,12 +4,12 @@ import pymodbus.bit_read_message as pdu_bit_read import pymodbus.bit_write_message as pdu_bit_write -from pymodbus.constants import Defaults import pymodbus.diag_message as pdu_diag import pymodbus.other_message as pdu_other_msg -from pymodbus.pdu import ModbusRequest, ModbusResponse import pymodbus.register_read_message as pdu_reg_read import pymodbus.register_write_message as pdu_req_write +from pymodbus.constants import Defaults +from pymodbus.pdu import ModbusRequest, ModbusResponse from pymodbus.utilities import ModbusTransactionState diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index 4b64483b3c..5dc68224fe 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -1,16 +1,17 @@ """Modbus client async serial communication.""" -from functools import partial import asyncio -import time import logging +import time +from functools import partial from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol from pymodbus.constants import Defaults +from pymodbus.exceptions import ConnectionException from pymodbus.framer import ModbusFramer from pymodbus.framer.rtu_framer import ModbusRtuFramer -from pymodbus.exceptions import ConnectionException from pymodbus.utilities import ModbusTransactionState, hexlify_packets + try: import serial from serial_asyncio import create_serial_connection diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 1c5517a5f4..aaf08fb6b9 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -8,11 +8,12 @@ from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol from pymodbus.constants import Defaults +from pymodbus.exceptions import ConnectionException from pymodbus.framer import ModbusFramer from pymodbus.framer.socket_framer import ModbusSocketFramer -from pymodbus.exceptions import ConnectionException from pymodbus.utilities import ModbusTransactionState + _logger = logging.getLogger(__name__) diff --git a/pymodbus/client/tls.py b/pymodbus/client/tls.py index 637f050159..42bd59bee6 100644 --- a/pymodbus/client/tls.py +++ b/pymodbus/client/tls.py @@ -9,6 +9,7 @@ from pymodbus.framer import ModbusFramer from pymodbus.framer.tls_framer import ModbusTlsFramer + _logger = logging.getLogger(__name__) diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index dd4efe272f..8ac6526221 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -7,9 +7,10 @@ from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol from pymodbus.constants import Defaults +from pymodbus.exceptions import ConnectionException from pymodbus.framer import ModbusFramer from pymodbus.framer.socket_framer import ModbusSocketFramer -from pymodbus.exceptions import ConnectionException + _logger = logging.getLogger(__name__) diff --git a/pymodbus/datastore/database/sql_datastore.py b/pymodbus/datastore/database/sql_datastore.py index 6227e999fa..a9bef7de02 100644 --- a/pymodbus/datastore/database/sql_datastore.py +++ b/pymodbus/datastore/database/sql_datastore.py @@ -3,10 +3,10 @@ import logging import sqlalchemy +import sqlalchemy.types as sqltypes from sqlalchemy.schema import UniqueConstraint from sqlalchemy.sql import and_ from sqlalchemy.sql.expression import bindparam -import sqlalchemy.types as sqltypes from pymodbus.interfaces import IModbusSlaveContext diff --git a/pymodbus/device.py b/pymodbus/device.py index f299066969..6ccd5ce1aa 100644 --- a/pymodbus/device.py +++ b/pymodbus/device.py @@ -4,9 +4,10 @@ maintained in the server context and the various methods should be inserted in the correct locations. """ +import struct + # pylint: disable=missing-type-doc from collections import OrderedDict -import struct from pymodbus.constants import DeviceInformation from pymodbus.interfaces import Singleton diff --git a/pymodbus/factory.py b/pymodbus/factory.py index ae2ecbb07b..9ea58c24b0 100644 --- a/pymodbus/factory.py +++ b/pymodbus/factory.py @@ -85,13 +85,9 @@ ReportSlaveIdRequest, ReportSlaveIdResponse, ) -from pymodbus.pdu import ( - ExceptionResponse, - IllegalFunctionRequest, - ModbusExceptions as ecode, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ExceptionResponse, IllegalFunctionRequest +from pymodbus.pdu import ModbusExceptions as ecode +from pymodbus.pdu import ModbusRequest, ModbusResponse from pymodbus.register_read_message import ( ReadHoldingRegistersRequest, ReadHoldingRegistersResponse, diff --git a/pymodbus/file_message.py b/pymodbus/file_message.py index 6dcdf7a780..20c765917e 100644 --- a/pymodbus/file_message.py +++ b/pymodbus/file_message.py @@ -5,11 +5,8 @@ # pylint: disable=missing-type-doc import struct -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse # ---------------------------------------------------------------------------# diff --git a/pymodbus/framer/ascii_framer.py b/pymodbus/framer/ascii_framer.py index 62816638db..c015761953 100644 --- a/pymodbus/framer/ascii_framer.py +++ b/pymodbus/framer/ascii_framer.py @@ -1,8 +1,8 @@ """Ascii_framer.""" # pylint: disable=missing-type-doc -from binascii import a2b_hex, b2a_hex import logging import struct +from binascii import a2b_hex, b2a_hex from pymodbus.exceptions import ModbusIOException from pymodbus.framer import BYTE_ORDER, FRAME_HEADER, ModbusFramer diff --git a/pymodbus/mei_message.py b/pymodbus/mei_message.py index 686abb4d19..0fc386b279 100644 --- a/pymodbus/mei_message.py +++ b/pymodbus/mei_message.py @@ -4,11 +4,8 @@ from pymodbus.constants import DeviceInformation, MoreData from pymodbus.device import DeviceInformationFactory, ModbusControlBlock -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse _MCB = ModbusControlBlock() diff --git a/pymodbus/register_read_message.py b/pymodbus/register_read_message.py index b4a249374b..cafcd439dd 100644 --- a/pymodbus/register_read_message.py +++ b/pymodbus/register_read_message.py @@ -3,11 +3,8 @@ import struct from pymodbus.constants import Defaults -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse class ReadRegistersRequestBase(ModbusRequest): diff --git a/pymodbus/register_write_message.py b/pymodbus/register_write_message.py index c1b4fda78c..1b64f3f2ce 100644 --- a/pymodbus/register_write_message.py +++ b/pymodbus/register_write_message.py @@ -2,11 +2,8 @@ # pylint: disable=missing-type-doc import struct -from pymodbus.pdu import ( - ModbusExceptions as merror, - ModbusRequest, - ModbusResponse, -) +from pymodbus.pdu import ModbusExceptions as merror +from pymodbus.pdu import ModbusRequest, ModbusResponse class WriteSingleRegisterRequest(ModbusRequest): diff --git a/pymodbus/repl/client/helper.py b/pymodbus/repl/client/helper.py index cc73547855..ec13d83850 100644 --- a/pymodbus/repl/client/helper.py +++ b/pymodbus/repl/client/helper.py @@ -1,13 +1,13 @@ """Helper Module for REPL actions.""" -from collections import OrderedDict import inspect # pylint: disable=missing-type-doc import json +from collections import OrderedDict +import pygments from prompt_toolkit import print_formatted_text from prompt_toolkit.formatted_text import HTML, PygmentsTokens -import pygments from pygments.lexers.data import JsonLexer from pymodbus.payload import BinaryPayloadDecoder, Endian diff --git a/pymodbus/repl/client/main.py b/pymodbus/repl/client/main.py index a22afb2204..51bb647bb1 100644 --- a/pymodbus/repl/client/main.py +++ b/pymodbus/repl/client/main.py @@ -29,7 +29,10 @@ from pygments.lexers.python import PythonLexer from pymodbus.exceptions import ParameterException -from pymodbus.repl.client.completer import CmdCompleter, has_selected_completion +from pymodbus.repl.client.completer import ( + CmdCompleter, + has_selected_completion, +) from pymodbus.repl.client.helper import CLIENT_ATTRIBUTES, Result from pymodbus.repl.client.mclient import ModbusSerialClient, ModbusTcpClient from pymodbus.transaction import ( diff --git a/pymodbus/repl/client/mclient.py b/pymodbus/repl/client/mclient.py index 53e31b1452..9fa0747c08 100644 --- a/pymodbus/repl/client/mclient.py +++ b/pymodbus/repl/client/mclient.py @@ -2,10 +2,8 @@ # pylint: disable=missing-type-doc import functools -from pymodbus.client import ( - ModbusSerialClient as _ModbusSerialClient, - ModbusTcpClient as _ModbusTcpClient, -) +from pymodbus.client import ModbusSerialClient as _ModbusSerialClient +from pymodbus.client import ModbusTcpClient as _ModbusTcpClient from pymodbus.constants import Defaults from pymodbus.diag_message import ( ChangeAsciiInputDelimiterRequest, diff --git a/pymodbus/repl/server/main.py b/pymodbus/repl/server/main.py index ae90790587..d438334bef 100644 --- a/pymodbus/repl/server/main.py +++ b/pymodbus/repl/server/main.py @@ -2,9 +2,9 @@ from __future__ import annotations import asyncio -from enum import Enum import json import logging +from enum import Enum from pathlib import Path from typing import List diff --git a/pymodbus/server/__init__.py b/pymodbus/server/__init__.py index cee5fbdcb8..1a6150af77 100644 --- a/pymodbus/server/__init__.py +++ b/pymodbus/server/__init__.py @@ -5,10 +5,10 @@ from pymodbus.server.async_io import ( ServerAsyncStop, ServerStop, + StartAsyncSerialServer, StartAsyncTcpServer, StartAsyncTlsServer, StartAsyncUdpServer, - StartAsyncSerialServer, StartSerialServer, StartTcpServer, StartTlsServer, diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index b7cd095893..d8b2f28793 100755 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -1,10 +1,10 @@ """Implementation of a Threaded Modbus Server.""" # pylint: disable=missing-type-doc import asyncio -from binascii import b2a_hex import logging -import traceback import ssl +import traceback +from binascii import b2a_hex from time import sleep from pymodbus.constants import Defaults @@ -21,6 +21,7 @@ ) from pymodbus.utilities import hexlify_packets + try: import serial from serial_asyncio import create_serial_connection diff --git a/pymodbus/transaction.py b/pymodbus/transaction.py index d173d36e58..fc3b652a78 100644 --- a/pymodbus/transaction.py +++ b/pymodbus/transaction.py @@ -1,11 +1,11 @@ """Collection of transaction based abstractions.""" # pylint: disable=missing-type-doc -from functools import partial import logging import socket import struct -from threading import RLock import time +from functools import partial +from threading import RLock from pymodbus.constants import Defaults from pymodbus.exceptions import ( diff --git a/setup.cfg b/setup.cfg index 4dff916ac3..fd5b12569d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -548,15 +548,3 @@ lines_after_imports = 2 known_local_folder = common contrib -sections = - FUTURE - STDLIB - THIRDPARTY - FIRSTPARTY - LOCALFOLDER -include_trailing_comma = true -use_parentheses = true -combine_as_imports = true -force_sort_within_sections = true -forced_separate = doc,examples,pymodbus,test -known_first_party = doc,examples,pymodbus,test diff --git a/test/test_bit_read_messages.py b/test/test_bit_read_messages.py index 6b9beea3d1..5af92a65c5 100644 --- a/test/test_bit_read_messages.py +++ b/test/test_bit_read_messages.py @@ -7,9 +7,8 @@ * Read Coils """ import struct - -from test.conftest import MockContext import unittest +from test.conftest import MockContext from pymodbus.bit_read_message import ( ReadBitsRequestBase, diff --git a/test/test_bit_write_messages.py b/test/test_bit_write_messages.py index f4e40259c0..fd40a53c1d 100644 --- a/test/test_bit_write_messages.py +++ b/test/test_bit_write_messages.py @@ -6,8 +6,8 @@ * Read/Write Discretes * Read Coils """ -from test.conftest import FakeList, MockContext import unittest +from test.conftest import FakeList, MockContext from pymodbus.bit_write_message import ( WriteMultipleCoilsRequest, diff --git a/test/test_client.py b/test/test_client.py index 46cc537f59..49d4141e40 100755 --- a/test/test_client.py +++ b/test/test_client.py @@ -2,26 +2,26 @@ import asyncio import socket import ssl - from test.conftest import return_as_coroutine, run_coroutine from unittest import mock + import pytest import pymodbus.bit_read_message as pdu_bit_read import pymodbus.bit_write_message as pdu_bit_write import pymodbus.client as lib_client +import pymodbus.diag_message as pdu_diag +import pymodbus.other_message as pdu_other_msg +import pymodbus.register_read_message as pdu_reg_read +import pymodbus.register_write_message as pdu_req_write from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol from pymodbus.client.mixin import ModbusClientMixin from pymodbus.constants import Defaults -import pymodbus.diag_message as pdu_diag from pymodbus.exceptions import ConnectionException, NotImplementedException from pymodbus.framer.ascii_framer import ModbusAsciiFramer from pymodbus.framer.rtu_framer import ModbusRtuFramer from pymodbus.framer.socket_framer import ModbusSocketFramer from pymodbus.framer.tls_framer import ModbusTlsFramer -import pymodbus.other_message as pdu_other_msg -import pymodbus.register_read_message as pdu_reg_read -import pymodbus.register_write_message as pdu_req_write @pytest.mark.parametrize( diff --git a/test/test_client_sync.py b/test/test_client_sync.py index 37adc5ba3e..e53ff1d657 100755 --- a/test/test_client_sync.py +++ b/test/test_client_sync.py @@ -1,9 +1,8 @@ """Test client sync.""" -from itertools import count import ssl - -from test.conftest import mockSocket import unittest +from itertools import count +from test.conftest import mockSocket from unittest.mock import MagicMock, Mock, patch import serial diff --git a/test/test_client_sync_diag.py b/test/test_client_sync_diag.py index 220a1486d4..69d8508f32 100755 --- a/test/test_client_sync_diag.py +++ b/test/test_client_sync_diag.py @@ -1,10 +1,9 @@ """Test client sync diag.""" -from itertools import count import socket - import unittest -from unittest.mock import MagicMock, patch +from itertools import count from test.test_client_sync import mockSocket +from unittest.mock import MagicMock, patch from pymodbus.client.sync_diag import ModbusTcpDiagClient, get_client from pymodbus.exceptions import ConnectionException diff --git a/test/test_examples.py b/test/test_examples.py index af2bbe6458..0e1062e342 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -1,9 +1,9 @@ """Test client async.""" import asyncio +import logging from dataclasses import dataclass from threading import Thread from time import sleep -import logging import pytest import pytest_asyncio @@ -11,10 +11,9 @@ from examples.client_async import run_async_client, setup_async_client from examples.client_async_basic_calls import run_async_basic_calls from examples.client_async_extended_calls import run_async_ext_calls -from examples.server_async import setup_server, run_async_server +from examples.server_async import run_async_server, setup_server from examples.server_sync import run_sync_server - -from pymodbus.server import ServerStop, ServerAsyncStop +from pymodbus.server import ServerAsyncStop, ServerStop from pymodbus.transaction import ( ModbusAsciiFramer, ModbusBinaryFramer, diff --git a/test/test_factory.py b/test/test_factory.py index 30ba35d81f..7839257fcb 100644 --- a/test/test_factory.py +++ b/test/test_factory.py @@ -1,7 +1,7 @@ """Test factory.""" import unittest -from pymodbus.exceptions import ModbusException, MessageRegisterException +from pymodbus.exceptions import MessageRegisterException, ModbusException from pymodbus.factory import ClientDecoder, ServerDecoder from pymodbus.pdu import ModbusRequest, ModbusResponse diff --git a/test/test_file_message.py b/test/test_file_message.py index e649f08c43..49558bacfe 100644 --- a/test/test_file_message.py +++ b/test/test_file_message.py @@ -6,8 +6,8 @@ * Read/Write Discretes * Read Coils """ -from test.conftest import MockContext import unittest +from test.conftest import MockContext from pymodbus.file_message import ( FileRecord, diff --git a/test/test_register_read_messages.py b/test/test_register_read_messages.py index 100f622363..a873378fbb 100644 --- a/test/test_register_read_messages.py +++ b/test/test_register_read_messages.py @@ -1,6 +1,6 @@ """Test register read messages.""" -from test.conftest import FakeList, MockContext import unittest +from test.conftest import FakeList, MockContext from pymodbus.pdu import ModbusExceptions from pymodbus.register_read_message import ( diff --git a/test/test_register_write_messages.py b/test/test_register_write_messages.py index b0a54e6dd1..a733988636 100644 --- a/test/test_register_write_messages.py +++ b/test/test_register_write_messages.py @@ -1,6 +1,6 @@ """Test register write messages.""" -from test.conftest import MockContext, MockLastValuesContext import unittest +from test.conftest import MockContext, MockLastValuesContext from pymodbus.payload import BinaryPayloadBuilder, Endian from pymodbus.pdu import ModbusExceptions diff --git a/test/test_server_asyncio.py b/test/test_server_asyncio.py index bf8f0e33c6..2584b20a17 100755 --- a/test/test_server_asyncio.py +++ b/test/test_server_asyncio.py @@ -1,9 +1,9 @@ """Test server asyncio.""" import asyncio -from asyncio import CancelledError import logging import ssl import unittest +from asyncio import CancelledError from unittest.mock import AsyncMock, Mock, patch import pytest diff --git a/test/test_transaction.py b/test/test_transaction.py index 04f87cc36f..4ac0aa34ef 100755 --- a/test/test_transaction.py +++ b/test/test_transaction.py @@ -1,7 +1,7 @@ """Test transaction.""" +import unittest from binascii import a2b_hex from itertools import count -import unittest from unittest.mock import MagicMock, patch from pymodbus.exceptions import (