Skip to content

Commit

Permalink
add ruff linting to github action
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Sep 9, 2024
1 parent eacf68f commit d02981b
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test-mango.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ jobs:
sudo apt update
sudo apt install --assume-yes mosquitto
sudo service mosquitto start
pip3 install pytest
pip3 install coverage
pip3 install pytest coverage ruff
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff check .
ruff format --check .
- name: Test+Coverage
run: |
source venv/bin/activate
Expand Down
1 change: 1 addition & 0 deletions examples/distributed_clock/clock_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import TypedDict

import numpy as np

from mango import Role, RoleAgent, create_container
from mango.messages.message import Performatives
from mango.util.clock import ExternalClock
Expand Down
3 changes: 1 addition & 2 deletions examples/distributed_clock/clock_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import TypedDict

import pandas as pd
from serializer import mango_codec_factory
from tqdm import tqdm

from mango import Role, RoleAgent, create_container
Expand Down Expand Up @@ -65,7 +64,7 @@ async def clear_market(self):
self.demands.append(self.demand)
else:
logger.info("First opening does not have anything to clear")
price=0
price = 0
acl_metadata = {
"performative": Performatives.inform,
"sender_id": self.context.aid,
Expand Down
1 change: 1 addition & 0 deletions examples/rrule_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime

from dateutil import rrule

from mango import Agent, create_container
from mango.util.clock import ExternalClock

Expand Down
4 changes: 3 additions & 1 deletion mango/modules/mqtt_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def conn(self, client, userdata, flags, reason_code, properties):
:return: None
"""

def on_disconnect(self, client, userdata, disconnect_flags, reason_code, properties):
def on_disconnect(
self, client, userdata, disconnect_flags, reason_code, properties
):
# pylint: disable=unused-argument
"""
Callback method on broker disconnect on paho mqtt framework
Expand Down
6 changes: 3 additions & 3 deletions mango/util/distributed_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ async def shutdown(self):
await super().shutdown()

async def send_current_time(self, time=None):
time = time or self._scheduler.clock.time
time = time or self._scheduler.clock.time
await self.broadcast(time, add_futures=False)

async def get_next_event(self):
'''Get the next event from the scheduler by requesting all known clock agents'''
"""Get the next event from the scheduler by requesting all known clock agents"""
self.schedules = []
await self.broadcast("next_event")
await asyncio.sleep(0)
Expand Down Expand Up @@ -89,7 +89,6 @@ async def get_next_event(self):
logger.debug("next event at %s", next_event)
return next_event


async def distribute_time(self, time=None):
await self.send_current_time(time)
if not time:
Expand All @@ -110,6 +109,7 @@ def handle_message(self, content: float, meta):
if not self.stopped.done():
self.stopped.set_result(True)
elif content == "next_event":

async def wait_done():
await self.wait_all_done()

Expand Down
2 changes: 0 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
target-version = "py38"

src = ["crawler"]

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool:pytest]

markers =
markers =
mqtt

asyncio_default_fixture_loop_scope = function
asyncio_default_fixture_loop_scope = function
2 changes: 1 addition & 1 deletion tests/integration_tests/test_distributed_clock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio

import pytest

from mango import create_container
from mango.messages.codecs import JSON
from mango.util.clock import ExternalClock
from mango.util.distributed_clock import DistributedClockAgent, DistributedClockManager
from mango.util.termination_detection import tasks_complete_or_sleeping

JSON_CODEC = JSON()

Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/test_message_roundtrip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.core import Agent
from mango.messages.codecs import JSON, PROTOBUF, FastJSON

Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests/test_message_roundtrip_mp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio

import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.core import Agent


Expand Down
13 changes: 8 additions & 5 deletions tests/integration_tests/test_single_container_termination.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio

import pytest

from mango import Agent, create_container
from mango.util.clock import ExternalClock
from mango.util.termination_detection import tasks_complete_or_sleeping
from mango.util.distributed_clock import DistributedClockAgent, DistributedClockManager
from multiprocessing import Process
from mango.util.termination_detection import tasks_complete_or_sleeping


class Caller(Agent):
Expand Down Expand Up @@ -41,7 +41,9 @@ def __init__(self, container, receiver_addr=None, receiver_id=None):
def handle_message(self, content, meta):
print(f"{self.aid} Received a message with the following content {content}.")
self.schedule_instant_acl_message(
receiver_addr=self.receiver_addr or self.addr, receiver_id=self.receiver_id or "agent1", content=content
receiver_addr=self.receiver_addr or self.addr,
receiver_id=self.receiver_id or "agent1",
content=content,
)


Expand Down Expand Up @@ -112,7 +114,6 @@ async def distribute_time_test_case(connection_type, codec=None):
)
receiver = Receiver(container_ag, init_addr, "agent0")
caller = Caller(container_man, repl_addr, receiver.aid)


assert receiver._scheduler.clock.time == 0
# first synchronize the clock to the receiver
Expand Down Expand Up @@ -150,6 +151,7 @@ async def distribute_time_test_case(connection_type, codec=None):
container_ag.shutdown(),
)


async def send_current_time_test_case(connection_type, codec=None):
init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1"
repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2"
Expand Down Expand Up @@ -241,6 +243,7 @@ async def test_distribute_time_mqtt():
async def test_send_current_time_tcp():
await send_current_time_test_case("tcp")


@pytest.mark.asyncio
async def test_send_current_time_mqtt():
await send_current_time_test_case("mqtt")
await send_current_time_test_case("mqtt")
1 change: 1 addition & 0 deletions tests/unit_tests/clock/test_external_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time

import pytest

from mango.util.clock import AsyncioClock, ExternalClock
from mango.util.scheduling import Scheduler

Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/container/test_mp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

import pytest

from mango import Agent, create_container


Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/container/test_tcp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio

import pytest

from mango import create_container
from mango.container.protocol import ContainerProtocol
from mango.container.tcp import TCPConnectionPool
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/core/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict

import pytest

from mango import create_container
from mango.agent.core import Agent

Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/core/test_container.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.core import Agent


Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/core/test_external_scheduling_container.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
from typing import Any, Dict

import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.core import Agent
from mango.container.external_coupling import ExternalAgentMessage
from mango.container.factory import EXTERNAL_CONNECTION
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/messages/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass

import pytest

from mango.messages.codecs import (
JSON,
PROTOBUF,
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/role_agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from abc import abstractmethod
from typing import Any, Dict

import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.role import Role, RoleAgent, RoleContext
from mango.util.scheduling import TimestampScheduledTask

Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/test_agents.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
from typing import Any, Dict

import mango.container.factory as container_factory
import pytest

import mango.container.factory as container_factory
from mango.agent.core import Agent


Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/util/scheduling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from dateutil import rrule

from mango.util.clock import ExternalClock
from mango.util.scheduling import (
ConditionalProcessTask,
Expand Down

0 comments on commit d02981b

Please sign in to comment.