Skip to content

Commit 93855d4

Browse files
committed
update to ruff
1 parent 962ef54 commit 93855d4

File tree

10 files changed

+74
-91
lines changed

10 files changed

+74
-91
lines changed

pyproject.toml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,19 @@ Forum = "https://forum.compas-framework.org/"
4949
# setuptools config
5050
# ============================================================================
5151

52-
[tool.black]
53-
line-length = 120
52+
[tool.ruff]
53+
line-length = 179
54+
indent-width = 4
55+
target-version = "py39"
56+
exclude = ["src/compas_eve/proto"]
57+
58+
[tool.ruff.lint]
59+
select = ["E", "F", "I"]
60+
61+
[tool.ruff.lint.per-file-ignores]
62+
"__init__.py" = ["I001"]
63+
"tests/*" = ["I001"]
64+
"tasks.py" = ["I001"]
5465

5566
[tool.pytest.ini_options]
5667
minversion = "6.0"
@@ -64,7 +75,7 @@ doctest_optionflags= "NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ALLOW_UNICODE
6475
filterwarnings = "ignore::DeprecationWarning"
6576

6677
[tool.isort]
67-
line_length = 120
78+
line_length = 179
6879
multi_line_output = 3
6980
include_trailing_comma = true
7081
force_grid_wrap = 0
@@ -76,3 +87,16 @@ default_section = "THIRDPARTY"
7687
forced_separate = "test_compas_eve"
7788
skip = ["__init__.py"]
7889

90+
[tool.ruff.lint.isort]
91+
force-single-line = true
92+
known-first-party = ["compas_eve"]
93+
94+
[tool.ruff.lint.pydocstyle]
95+
convention = "numpy"
96+
97+
[tool.ruff.lint.pycodestyle]
98+
max-doc-length = 179
99+
100+
[tool.ruff.format]
101+
docstring-code-format = true
102+
docstring-code-line-length = "dynamic"

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
universal = 1
33

44
[flake8]
5-
max-line-length = 120
5+
max-line-length = 179
66
exclude = */migrations/*
77

88
[doc8]
9-
max-line-length = 120
9+
max-line-length = 179
1010
ignore = D001
1111

1212
[pydocstyle]

src/compas_eve/codecs/__init__.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ class ProtobufMessageCodec(MessageCodec):
141141
def __init__(self):
142142
super(ProtobufMessageCodec, self).__init__()
143143
if not COMPAS_PB_AVAILABLE:
144-
raise ImportError(
145-
"The ProtobufMessageCodec requires 'compas_pb' to be installed. "
146-
"Please install it with: pip install compas_pb"
147-
)
144+
raise ImportError("The ProtobufMessageCodec requires 'compas_pb' to be installed. Please install it with: pip install compas_pb")
148145

149146
def encode(self, message):
150147
"""Encode a message to Protocol Buffers binary format.
@@ -161,10 +158,7 @@ def encode(self, message):
161158
Protocol Buffers binary representation of the message.
162159
"""
163160
if not COMPAS_PB_AVAILABLE:
164-
raise ImportError(
165-
"The ProtobufMessageCodec requires 'compas_pb' to be installed. "
166-
"Please install it with: pip install compas_pb"
167-
)
161+
raise ImportError("The ProtobufMessageCodec requires 'compas_pb' to be installed. Please install it with: pip install compas_pb")
168162
return compas_pb.pb_dump_bts(message)
169163

170164
def decode(self, encoded_data, message_type=None):
@@ -183,8 +177,5 @@ def decode(self, encoded_data, message_type=None):
183177
Decoded message object.
184178
"""
185179
if not COMPAS_PB_AVAILABLE:
186-
raise ImportError(
187-
"The ProtobufMessageCodec requires 'compas_pb' to be installed. "
188-
"Please install it with: pip install compas_pb"
189-
)
180+
raise ImportError("The ProtobufMessageCodec requires 'compas_pb' to be installed. Please install it with: pip install compas_pb")
190181
return compas_pb.pb_load_bts(encoded_data)

src/compas_eve/codecs/conversions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def message_to_pb(message: Message) -> message_pb2.Message:
1414
pb.data[k].CopyFrom(_serializer_any(v))
1515
return pb
1616

17+
1718
@pb_deserializer(message_pb2.Message)
1819
def message_from_pb(pb: message_pb2.Message) -> Message:
1920
message = Message()

src/compas_eve/event_emitter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ class EventEmitterMixin(object):
7373
7474
For example::
7575
76-
@ee.on('error')
76+
@ee.on("error")
7777
def onError(message):
7878
logging.err(message)
7979
80-
ee.emit('error', Exception('something blew up'))
80+
81+
ee.emit("error", Exception("something blew up"))
8182
8283
For synchronous callbacks, exceptions are **not** handled for you---
8384
you must catch your own exceptions inside synchronous ``on`` handlers.
@@ -102,7 +103,7 @@ def on(self, event, f=None):
102103
takes ``f`` as a callback; in other words, you can use this method
103104
as a decorator, like so::
104105
105-
@ee.on('data')
106+
@ee.on("data")
106107
def data_handler(data):
107108
print(data)
108109
@@ -150,7 +151,7 @@ def emit(self, event, *args, **kwargs):
150151
151152
Example::
152153
153-
ee.emit('data', '00101001')
154+
ee.emit("data", "00101001")
154155
155156
Assuming ``data`` is an attached function, this will call
156157
``data('00101001')'``.

src/compas_eve/ghpython/background.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class BackgroundWorker(object):
3333
3434
import time
3535
36+
3637
def do_something_long_and_complicated(worker):
3738
# Result can be of any data type
3839
result = 0
3940
4041
for i in range(50):
4142
worker.current_value = i
4243
result += i
43-
worker.display_progress(i / (50-1))
44+
worker.display_progress(i / (50 - 1))
4445
time.sleep(0.01)
4546
4647
worker.display_message("Done!")
@@ -190,9 +191,7 @@ def ui_callback():
190191
Rhino.RhinoApp.InvokeOnUiThread(System.Action(ui_callback))
191192

192193
@classmethod
193-
def instance_by_component(
194-
cls, ghenv, long_running_function=None, dispose_function=None, auto_set_done=True, force_new=False, args=()
195-
):
194+
def instance_by_component(cls, ghenv, long_running_function=None, dispose_function=None, auto_set_done=True, force_new=False, args=()):
196195
"""Get the worker instance assigned to the component.
197196
198197
This will get a persistant instance of a background worker

src/compas_eve/memory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def publish(self, topic, message):
5757

5858
def _callback(**kwargs):
5959
encoded_message = self.codec.encode(message)
60-
encoded_message_bytes = encoded_message if isinstance(encoded_message, bytes) else encoded_message.encode('utf-8')
60+
encoded_message_bytes = encoded_message if isinstance(encoded_message, bytes) else encoded_message.encode("utf-8")
6161
self.emit(event_key, encoded_message_bytes)
6262

6363
self.on_ready(_callback)

tests/integration/test_mqtt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def callback(msg):
136136
assert isinstance(result["value"]["graph"], Graph)
137137

138138

139-
140139
def test_nested_message_types():
141-
142140
class Header(Message):
143141
def __init__(self, sequence_id=None):
144142
super(Header, self).__init__()

tests/unit/test_codecs.py

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
def test_json_codec_encode_decode():
88
codec = JsonMessageCodec()
9-
9+
1010
original_message = Message(name="test", value=42, active=True)
1111
encoded = codec.encode(original_message)
12-
wire_encoding = encoded.encode('utf-8') # simulate wire encoding
12+
wire_encoding = encoded.encode("utf-8") # simulate wire encoding
1313
decoded = codec.decode(wire_encoding, Message)
14-
14+
1515
assert isinstance(encoded, str)
1616
assert isinstance(decoded, Message)
1717
assert decoded.name == "test"
@@ -21,17 +21,13 @@ def test_json_codec_encode_decode():
2121

2222
def test_json_codec_nested_data():
2323
codec = JsonMessageCodec()
24-
25-
nested_data = {
26-
"coordinates": [1.0, 2.0, 3.0],
27-
"metadata": {"author": "test", "version": 1},
28-
"tags": ["geometry", "point"]
29-
}
30-
24+
25+
nested_data = {"coordinates": [1.0, 2.0, 3.0], "metadata": {"author": "test", "version": 1}, "tags": ["geometry", "point"]}
26+
3127
original_message = Message(**nested_data)
32-
encoded = codec.encode(original_message).encode('utf-8')
28+
encoded = codec.encode(original_message).encode("utf-8")
3329
decoded = codec.decode(encoded, Message)
34-
30+
3531
assert decoded.coordinates == [1.0, 2.0, 3.0]
3632
assert decoded.metadata["author"] == "test"
3733
assert decoded.metadata["version"] == 1
@@ -40,9 +36,9 @@ def test_json_codec_nested_data():
4036

4137
def test_json_codec_empty_message():
4238
codec = JsonMessageCodec()
43-
39+
4440
original_message = Message()
45-
encoded = codec.encode(original_message).encode('utf-8')
41+
encoded = codec.encode(original_message).encode("utf-8")
4642
decoded = codec.decode(encoded, Message)
4743

4844
assert isinstance(decoded, Message)
@@ -52,23 +48,15 @@ def test_json_codec_empty_message():
5248
def test_json_codec_roundtrip():
5349
"""Test JSON codec maintains data integrity through multiple encode/decode cycles."""
5450
codec = JsonMessageCodec()
55-
56-
original_message = Message(
57-
string_val="hello world",
58-
int_val=123,
59-
float_val=3.14159,
60-
bool_val=True,
61-
null_val=None,
62-
list_val=[1, 2, 3],
63-
dict_val={"key": "value"}
64-
)
65-
51+
52+
original_message = Message(string_val="hello world", int_val=123, float_val=3.14159, bool_val=True, null_val=None, list_val=[1, 2, 3], dict_val={"key": "value"})
53+
6654
# Multiple roundtrips
6755
current = original_message
6856
for _ in range(3):
69-
encoded = codec.encode(current).encode('utf-8')
57+
encoded = codec.encode(current).encode("utf-8")
7058
current = codec.decode(encoded, Message)
71-
59+
7260
assert current.string_val == "hello world"
7361
assert current.int_val == 123
7462
assert current.float_val == 3.14159
@@ -80,12 +68,12 @@ def test_json_codec_roundtrip():
8068

8169
def test_protobuf_codec_encode_decode():
8270
codec = ProtobufMessageCodec()
83-
71+
8472
# Test with simple message
8573
original_message = Message(name="test", value=42, active=True, frame=Frame.worldXY())
8674
encoded = codec.encode(original_message.data)
8775
decoded = codec.decode(encoded, dict)
88-
76+
8977
assert isinstance(encoded, bytes)
9078
assert isinstance(decoded, dict)
9179
assert decoded["name"] == "test"
@@ -99,17 +87,13 @@ def test_protobuf_codec_encode_decode():
9987
def test_protobuf_codec_nested_data():
10088
"""Test Protobuf codec handles nested data structures."""
10189
codec = ProtobufMessageCodec()
102-
103-
nested_data = {
104-
"coordinates": [1.0, 2.0, 3.0],
105-
"metadata": {"author": "test", "version": 1},
106-
"tags": ["geometry", "point"]
107-
}
108-
90+
91+
nested_data = {"coordinates": [1.0, 2.0, 3.0], "metadata": {"author": "test", "version": 1}, "tags": ["geometry", "point"]}
92+
10993
original_message = Message(**nested_data)
11094
encoded = codec.encode(original_message.data)
11195
decoded = codec.decode(encoded)
112-
96+
11397
assert decoded["coordinates"] == [1.0, 2.0, 3.0]
11498
assert decoded["metadata"]["author"] == "test"
11599
assert decoded["metadata"]["version"] == 1
@@ -119,23 +103,16 @@ def test_protobuf_codec_nested_data():
119103
def test_protobuf_codec_roundtrip():
120104
"""Test Protobuf codec maintains data integrity through multiple encode/decode cycles."""
121105
codec = ProtobufMessageCodec()
122-
123-
original_message = Message(
124-
string_val="hello world",
125-
int_val=123,
126-
float_val=3.14159,
127-
bool_val=True,
128-
list_val=[1, 2, 3],
129-
dict_val={"key": "value"}
130-
)
106+
107+
original_message = Message(string_val="hello world", int_val=123, float_val=3.14159, bool_val=True, list_val=[1, 2, 3], dict_val={"key": "value"})
131108
original_message = original_message.data
132-
109+
133110
# Multiple roundtrips
134111
current = original_message
135112
for _ in range(3):
136113
encoded = codec.encode(current)
137114
current = codec.decode(encoded)
138-
115+
139116
assert current["string_val"] == "hello world"
140117
assert current["int_val"] == 123
141118
assert current["float_val"] == 3.14159
@@ -148,22 +125,17 @@ def test_codec_compatibility():
148125
"""Test that both codecs produce equivalent results for the same message."""
149126
json_codec = JsonMessageCodec()
150127
protobuf_codec = ProtobufMessageCodec()
151-
152-
original_message = Message(
153-
name="compatibility_test",
154-
count=100,
155-
enabled=False,
156-
data=[1, 2, 3, 4, 5]
157-
)
158-
128+
129+
original_message = Message(name="compatibility_test", count=100, enabled=False, data=[1, 2, 3, 4, 5])
130+
159131
# Encode with both codecs
160-
json_encoded = json_codec.encode(original_message).encode('utf-8')
132+
json_encoded = json_codec.encode(original_message).encode("utf-8")
161133
protobuf_encoded = protobuf_codec.encode(original_message.data)
162-
134+
163135
# Decode with respective codecs
164136
json_decoded = json_codec.decode(json_encoded, Message)
165137
protobuf_decoded = protobuf_codec.decode(protobuf_encoded, Message)
166-
138+
167139
# Both should produce equivalent messages
168140
assert json_decoded["name"] == protobuf_decoded["name"] == "compatibility_test"
169141
assert json_decoded["count"] == protobuf_decoded["count"] == 100

tests/unit/test_mqtt_paho_compatibility.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55

66
def test_paho_mqtt_v1_compatibility():
7-
with patch("compas_eve.mqtt.mqtt_paho.PAHO_MQTT_V2_AVAILABLE", False), patch(
8-
"paho.mqtt.client.Client"
9-
) as mock_client_class:
10-
7+
with patch("compas_eve.mqtt.mqtt_paho.PAHO_MQTT_V2_AVAILABLE", False), patch("paho.mqtt.client.Client") as mock_client_class:
118
mock_client = Mock()
129
mock_client_class.return_value = mock_client
1310

0 commit comments

Comments
 (0)