Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from black to ruff-format #1838

Merged
merged 5 commits into from
Oct 18, 2023
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
14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# run ruff with --fix before black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.0'
hooks:
- id: ruff-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.287'
rev: 'v0.1.0'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe, --quiet]
files: (examples|pymodbus|test)/
48 changes: 15 additions & 33 deletions pymodbus/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,15 @@ def __str__(self):
# -------------------------------------------------------------------------#
# Properties
# -------------------------------------------------------------------------#
VendorName = dict_property(
lambda s: s.__data, 0 # pylint: disable=protected-access
)
ProductCode = dict_property(
lambda s: s.__data, 1 # pylint: disable=protected-access
)
MajorMinorRevision = dict_property(
lambda s: s.__data, 2 # pylint: disable=protected-access
)
# fmt: off
VendorName = dict_property(lambda s: s.__data, 0) # pylint: disable=protected-access
ProductCode = dict_property(lambda s: s.__data, 1) # pylint: disable=protected-access
MajorMinorRevision = dict_property(lambda s: s.__data, 2) # pylint: disable=protected-access
VendorUrl = dict_property(lambda s: s.__data, 3) # pylint: disable=protected-access
ProductName = dict_property(
lambda s: s.__data, 4 # pylint: disable=protected-access
)
ProductName = dict_property(lambda s: s.__data, 4) # pylint: disable=protected-access
ModelName = dict_property(lambda s: s.__data, 5) # pylint: disable=protected-access
UserApplicationName = dict_property(
lambda s: s.__data, 6 # pylint: disable=protected-access
)
UserApplicationName = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access
# fmt: on


class DeviceInformationFactory: # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -428,27 +420,17 @@ def summary(self):
# -------------------------------------------------------------------------#
# Properties
# -------------------------------------------------------------------------#
BusMessage = dict_property(
lambda s: s.__data, 0 # pylint: disable=protected-access
)
BusCommunicationError = dict_property(
lambda s: s.__data, 1 # pylint: disable=protected-access
)
BusExceptionError = dict_property(
lambda s: s.__data, 2 # pylint: disable=protected-access
)
SlaveMessage = dict_property(
lambda s: s.__data, 3 # pylint: disable=protected-access
)
SlaveNoResponse = dict_property(
lambda s: s.__data, 4 # pylint: disable=protected-access
)
# fmt: off
BusMessage = dict_property(lambda s: s.__data, 0) # pylint: disable=protected-access
BusCommunicationError = dict_property(lambda s: s.__data, 1) # pylint: disable=protected-access
BusExceptionError = dict_property(lambda s: s.__data, 2) # pylint: disable=protected-access
SlaveMessage = dict_property(lambda s: s.__data, 3) # pylint: disable=protected-access
SlaveNoResponse = dict_property(lambda s: s.__data, 4) # pylint: disable=protected-access
SlaveNAK = dict_property(lambda s: s.__data, 5) # pylint: disable=protected-access
SlaveBusy = dict_property(lambda s: s.__data, 6) # pylint: disable=protected-access
BusCharacterOverrun = dict_property(
lambda s: s.__data, 7 # pylint: disable=protected-access
)
BusCharacterOverrun = dict_property(lambda s: s.__data, 7) # pylint: disable=protected-access
Event = dict_property(lambda s: s.__data, 8) # pylint: disable=protected-access
# fmt: on


# ---------------------------------------------------------------------------#
Expand Down
22 changes: 8 additions & 14 deletions pymodbus/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,20 @@ def dict_property(store, index):
getter = lambda self: store( # pylint: disable=unnecessary-lambda-assignment
self
)[index]
setter = (
lambda self, value: store( # pylint: disable=unnecessary-lambda-assignment
self
).__setitem__(index, value)
)
setter = lambda self, value: store( # pylint: disable=unnecessary-lambda-assignment
self
).__setitem__(index, value)
elif isinstance(store, str):
getter = lambda self: self.__getattribute__( # pylint: disable=unnecessary-dunder-call,unnecessary-lambda-assignment
store
)[
index
]
)[index]
setter = lambda self, value: self.__getattribute__( # pylint: disable=unnecessary-dunder-call,unnecessary-lambda-assignment
store
).__setitem__(
index, value
)
).__setitem__(index, value)
else:
getter = lambda self: store[ # pylint: disable=unnecessary-lambda-assignment
index
]
getter = (
lambda self: store[index] # pylint: disable=unnecessary-lambda-assignment
)
setter = lambda self, value: store.__setitem__( # pylint: disable=unnecessary-lambda-assignment
index, value
)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ development = [
"pytest-cov>=4.1.0",
"pytest-timeout>=2.2.0",
"pytest-xdist>=3.3.1",
"ruff>=0.0.287",
"ruff>=0.1.0",
"twine>=4.0.2",
"types-Pygments",
"types-pyserial"
Expand Down Expand Up @@ -143,7 +143,7 @@ enable = "all"
disable = [
"duplicate-code", # TBD
"file-ignored", # ONLY to be used with extreme care.
"format", # NOT wanted, handled by black
"format", # NOT wanted, handled by ruff
"locally-disabled", # NOT wanted
"suppressed-message" # NOT wanted"""
]
Expand Down
4 changes: 2 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
target-version="py38"
exclude = [
"pymodbus/transport/serial_asyncio",
"venv",
".venv",
".git",
"build",
"doc"
]
ignore = [
"D202", # No blank lines allowed after function docstring (to work with black)
Expand All @@ -19,7 +19,7 @@ ignore = [
"RUF013", # implicit Optional
"RUF015" # next(iter(list)) instead of list[0]
]
line-length = 120
line-length = 88
select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
Expand Down
3 changes: 1 addition & 2 deletions test/sub_messages/test_register_read_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def setup_method(self):
ReadWriteMultipleRegistersRequest(
write_registers=0xAB,
**arguments,
): b"\x00\x01\x00\x05\x00\x01\x00"
b"\x01\x02\x00\xAB",
): b"\x00\x01\x00\x05\x00\x01\x00" b"\x01\x02\x00\xAB",
}
self.response_read = {
ReadRegistersResponseBase(self.values): TEST_MESSAGE,
Expand Down
8 changes: 4 additions & 4 deletions test/sub_server/test_server_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ async def test_async_udp_server_serve_forever_twice(self):

async def test_async_udp_server_roundtrip(self):
"""Test sending and receiving data on udp socket"""
expected_response = b"\x01\x00\x00\x00\x00\x05\x01\x03\x02\x00\x11" # value of 17 as per context
expected_response = (
b"\x01\x00\x00\x00\x00\x05\x01\x03\x02\x00\x11"
) # value of 17 as per context
BasicClient.dataTo = TEST_DATA # slave 1, read register
BasicClient.done = asyncio.Future()
await self.start_server(do_udp=True)
random_port = self.server.transport._sock.getsockname()[ # pylint: disable=protected-access
1
]
random_port = self.server.transport._sock.getsockname()[1] # pylint: disable=protected-access
transport, _ = await self.loop.create_datagram_endpoint(
BasicClient, remote_addr=("127.0.0.1", random_port)
)
Expand Down
6 changes: 2 additions & 4 deletions test/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ def test_calculate_expected_response_length(self):
self._tm.client = mock.MagicMock()
self._tm.client.framer = mock.MagicMock()
self._tm._set_adu_size() # pylint: disable=protected-access
assert (
not self._tm._calculate_response_length( # pylint: disable=protected-access
0
)
assert not self._tm._calculate_response_length( # pylint: disable=protected-access
0
)
self._tm.base_adu_size = 10
assert (
Expand Down