Skip to content

Commit ce81765

Browse files
Feature/add ruff workflow (#26)
Co-authored-by: kroskinskiis <ivo.kroskinski@tno.nl>
1 parent a40df5f commit ce81765

32 files changed

Lines changed: 461 additions & 306 deletions

.github/workflows/format.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Pyformat
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.10", "3.11"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install ruff
21+
pip install poetry
22+
poetry install
23+
- name: Analysing the code with Ruff
24+
run: |
25+
ruff format --check

examples/pong_example.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ def capability_pong_callback(command: Command) -> ResultStructure:
2323
description="If ping, return pong",
2424
value="pong",
2525
constant=True,
26-
external=False)
26+
external=False,
27+
)
2728

2829
context = command.command.context
2930

3031
return ResultStructure(
31-
state="success", context=context, variables={"result": result})
32+
state="success", context=context, variables={"result": result}
33+
)
3234

3335

3436
def main(mqtt_broker: str, mqtt_port: int, username: str, password: str) -> None:
35-
3637
finId = "soarca-fin--pingpong-f877bb3a-bb37-429e-8ece-2d4286cf326d"
3738
agentName = "soarca-fin-pong-f896bb3b-bb37-429e-8ece-2d4286cf326d"
3839
externalReferenceName = "external-reference-example-name"
3940
capabilityId = "mod-pong--e896aa3b-bb37-429e-8ece-2d4286cf326d"
4041

4142
# Create AgentStructure
42-
agent = AgentStructure(
43-
name=agentName)
43+
agent = AgentStructure(name=agentName)
4444

4545
# Create ExternalReference
4646
external_reference = ExternalReference(name=externalReferenceName)
@@ -51,18 +51,18 @@ def main(mqtt_broker: str, mqtt_port: int, username: str, password: str) -> None
5151
description="step description",
5252
external_references=[external_reference],
5353
command="pong",
54-
target=agentName)
54+
target=agentName,
55+
)
5556

5657
# Create CapabilityStructure
5758
capability_structure = CapabilityStructure(
5859
capability_id=capabilityId,
5960
type=WorkFlowStepEnum.action,
6061
name="Ping Pong capability",
6162
version="0.0.1",
62-
step={
63-
"test": step_structure},
64-
agent={
65-
"testagent": agent})
63+
step={"test": step_structure},
64+
agent={"testagent": agent},
65+
)
6666

6767
# Create Soarca fin
6868
fin = SoarcaFin(finId)

soarca_fin_python_library/abstract_classes/i_executor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class IExecutor(ABC):
7-
87
@abstractmethod
98
def queue_message(self, message: Message) -> None:
109
pass

soarca_fin_python_library/abstract_classes/i_mqtt_client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66

77
class IMQTTClient(ABC):
8-
98
@abstractmethod
10-
def on_connect(self, client: Client,
11-
userdata,
12-
connect_flags: ConnectFlags,
13-
reason_code: ReasonCode,
14-
properties: Properties):
9+
def on_connect(
10+
self,
11+
client: Client,
12+
userdata,
13+
connect_flags: ConnectFlags,
14+
reason_code: ReasonCode,
15+
properties: Properties,
16+
):
1517
pass
1618

1719
@abstractmethod

soarca_fin_python_library/abstract_classes/i_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class IParser(ABC):
7-
87
@abstractmethod
98
def parse_on_message(self, message: mqtt.MQTTMessage) -> Message:
109
pass

soarca_fin_python_library/abstract_classes/i_soarca_fin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55

66
class ISoarcaFin(ABC):
7-
87
@abstractmethod
9-
def set_config_MQTT_server(self, host: str, port: str, username: str, password: str) -> None:
8+
def set_config_MQTT_server(
9+
self, host: str, port: str, username: str, password: str
10+
) -> None:
1011
pass
1112

1213
@abstractmethod

soarca_fin_python_library/executor.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222

2323
class Executor(IExecutor):
24-
2524
def __init__(self, executor_id: str, callback, queue: Queue, mqttc: Client):
2625
self.queue: Queue[Message] = queue
2726
self.mqttc: Client = mqttc
@@ -41,7 +40,6 @@ def stop_executor(self):
4140

4241
# Main executor loop. Polls for messages in the queue and parsers them.
4342
def start_executor(self):
44-
4543
log.info("Thread started for %s", self.id)
4644
self.running = True
4745

@@ -56,7 +54,9 @@ def start_executor(self):
5654
self._put_message_in_queue(message)
5755
else:
5856
log.debug(
59-
"Received unknown (n)ack with message_id: %s", message.message_id)
57+
"Received unknown (n)ack with message_id: %s",
58+
message.message_id,
59+
)
6060
case Register():
6161
self._handle_register_message(message)
6262
case Unregister():
@@ -68,7 +68,8 @@ def start_executor(self):
6868
case _:
6969
# Send Nack?
7070
log.warning(
71-
"Unimplemented command: %s", message.model_dump_json())
71+
"Unimplemented command: %s", message.model_dump_json()
72+
)
7273
except Empty:
7374
pass
7475

@@ -115,7 +116,9 @@ def _handle_unregister_self_message(self, message: UnregisterSelf):
115116
retries -= 1
116117
if retries == 0:
117118
log.fatal(
118-
"Did not receive an ack for message %s. Aborting...", message.message_id)
119+
"Did not receive an ack for message %s. Aborting...",
120+
message.message_id,
121+
)
119122
exit(-1)
120123

121124
# Handles self generated register message.
@@ -147,7 +150,9 @@ def _handle_register_message(self, message: Register):
147150
retries -= 1
148151
if retries == 0:
149152
log.fatal(
150-
"Did not receive an ack for message %s. Aborting...", message.message_id)
153+
"Did not receive an ack for message %s. Aborting...",
154+
message.message_id,
155+
)
151156
exit(-1)
152157

153158
# Handles a command message from SOARCA.
@@ -164,8 +169,7 @@ def _handle_command_message(self, message: Command):
164169
message_id = str(uuid1())
165170
timestamp = datetime.now(timezone.utc).isoformat()
166171
meta = Meta(timestamp=timestamp, sender_id=self.id)
167-
result = Result(message_id=message_id, meta=meta,
168-
result=resultStruct)
172+
result = Result(message_id=message_id, meta=meta, result=resultStruct)
169173

170174
# Send result back
171175
self._send_message_as_json(result)
@@ -187,7 +191,9 @@ def _handle_command_message(self, message: Command):
187191
if retries == 0:
188192
self.acks.remove(message_id)
189193
log.error(
190-
"Did not receive an acknowledgement for message %s. Skipping message...", result.message_id)
194+
"Did not receive an acknowledgement for message %s. Skipping message...",
195+
result.message_id,
196+
)
191197
break
192198

193199
# Publishes a message as JSON on a topic. Default topic is self.id.
@@ -221,12 +227,12 @@ def _wait_for_ack(self, message_id: str):
221227
log.info("Received ack for message: %s", message_id)
222228
return
223229
case Nack():
224-
log.warning(
225-
"Received nack for message: %s", message_id)
230+
log.warning("Received nack for message: %s", message_id)
226231
raise RuntimeError("Received a nack")
227232
case _:
228233
raise TypeError(
229-
f"Unexpected message type {message.model_dump_json()}")
234+
f"Unexpected message type {message.model_dump_json()}"
235+
)
230236

231237
except Empty as e:
232238
log.warning("Did not receive an ack")

soarca_fin_python_library/models/ack.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from soarca_fin_python_library.models.message import Message
32

43

soarca_fin_python_library/models/command_sub_structure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from typing import Optional
22
from pydantic import BaseModel
33

4-
from soarca_fin_python_library.models.authentication_information import AuthenticationInformation
4+
from soarca_fin_python_library.models.authentication_information import (
5+
AuthenticationInformation,
6+
)
57
from soarca_fin_python_library.models.context import Context
68
from soarca_fin_python_library.models.variable import Variable
79

soarca_fin_python_library/models/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
class Meta(BaseModel):
55
timestamp: str
6-
sender_id: str
6+
sender_id: str

0 commit comments

Comments
 (0)