From 793bbe3503f0ad7d19a9cb3fe3db6403ff596e50 Mon Sep 17 00:00:00 2001 From: Eddasol Date: Mon, 16 Dec 2024 08:58:12 +0100 Subject: [PATCH] Implement ruff recommendations Remove unused imports and improve readability --- src/isar/apis/models/__init__.py | 1 - .../apis/schedule/scheduling_controller.py | 8 ++++++-- .../models/communication/queues/__init__.py | 4 ---- .../communication/queues/status_queue.py | 4 ++-- .../services/utilities/scheduling_utilities.py | 8 ++++++-- src/isar/state_machine/state_machine.py | 18 ++++++++---------- src/isar/state_machine/states/__init__.py | 8 -------- src/isar/storage/blob_storage.py | 2 +- src/isar/storage/uploader.py | 2 +- .../models/initialize/__init__.py | 1 - src/robot_interface/robot_interface.py | 2 +- tests/conftest.py | 4 +++- tests/isar/models/communication/test_queues.py | 2 +- .../utilities/test_scheduling_utilities.py | 3 ++- tests/mocks/robot_interface.py | 2 +- 15 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/isar/apis/models/__init__.py b/src/isar/apis/models/__init__.py index f4309818..e69de29b 100644 --- a/src/isar/apis/models/__init__.py +++ b/src/isar/apis/models/__init__.py @@ -1 +0,0 @@ -from .models import InputPose, StartMissionResponse diff --git a/src/isar/apis/schedule/scheduling_controller.py b/src/isar/apis/schedule/scheduling_controller.py index 33228f2e..bcc4d61a 100644 --- a/src/isar/apis/schedule/scheduling_controller.py +++ b/src/isar/apis/schedule/scheduling_controller.py @@ -6,8 +6,12 @@ from fastapi import Body, HTTPException, Path from injector import inject -from isar.apis.models import InputPose, StartMissionResponse -from isar.apis.models.models import ControlMissionResponse, TaskResponse +from isar.apis.models.models import ( + ControlMissionResponse, + TaskResponse, + InputPose, + StartMissionResponse, +) from isar.apis.models.start_mission_definition import ( StartMissionDefinition, to_isar_mission, diff --git a/src/isar/models/communication/queues/__init__.py b/src/isar/models/communication/queues/__init__.py index 40f8c9f4..e69de29b 100644 --- a/src/isar/models/communication/queues/__init__.py +++ b/src/isar/models/communication/queues/__init__.py @@ -1,4 +0,0 @@ -from .queue_io import QueueIO -from .queue_timeout_error import QueueTimeoutError -from .queues import Queues -from .status_queue import StatusQueue diff --git a/src/isar/models/communication/queues/status_queue.py b/src/isar/models/communication/queues/status_queue.py index e7e93bd1..7589ff29 100644 --- a/src/isar/models/communication/queues/status_queue.py +++ b/src/isar/models/communication/queues/status_queue.py @@ -11,8 +11,8 @@ def check(self) -> Any: if not self._qsize(): raise Empty with self.mutex: - l = list(self.queue) - return l.pop() + queueList = list(self.queue) + return queueList.pop() def update(self, item: Any): with self.mutex: diff --git a/src/isar/services/utilities/scheduling_utilities.py b/src/isar/services/utilities/scheduling_utilities.py index 9041c924..ede9692c 100644 --- a/src/isar/services/utilities/scheduling_utilities.py +++ b/src/isar/services/utilities/scheduling_utilities.py @@ -17,7 +17,11 @@ MissionPlannerInterface, ) from isar.models.communication.message import StartMissionMessage -from isar.models.communication.queues import QueueIO, Queues, QueueTimeoutError +from isar.models.communication.queues.queue_io import QueueIO +from isar.models.communication.queues.queues import Queues +from isar.models.communication.queues.queue_timeout_error import ( + QueueTimeoutError, +) from isar.services.utilities.queue_utilities import QueueUtilities from isar.state_machine.states_enum import States from robot_interface.models.mission.mission import Mission @@ -101,7 +105,7 @@ def verify_robot_capable_of_mission( is_capable: bool = True missing_capabilities: Set[str] = set() for task in mission.tasks: - if not task.type in robot_capabilities: + if task.type not in robot_capabilities: is_capable = False missing_capabilities.add(task.type) diff --git a/src/isar/state_machine/state_machine.py b/src/isar/state_machine/state_machine.py index 50106d32..9a4093bd 100644 --- a/src/isar/state_machine/state_machine.py +++ b/src/isar/state_machine/state_machine.py @@ -18,16 +18,14 @@ ) from isar.models.communication.message import StartMissionMessage from isar.models.communication.queues.queues import Queues -from isar.state_machine.states import ( - Idle, - Initialize, - Initiate, - Monitor, - Off, - Offline, - Paused, - Stop, -) +from isar.state_machine.states.idle import Idle +from isar.state_machine.states.initialize import Initialize +from isar.state_machine.states.initiate import Initiate +from isar.state_machine.states.monitor import Monitor +from isar.state_machine.states.off import Off +from isar.state_machine.states.offline import Offline +from isar.state_machine.states.paused import Paused +from isar.state_machine.states.stop import Stop from isar.state_machine.states_enum import States from robot_interface.models.exceptions.robot_exceptions import ErrorMessage from robot_interface.models.initialize.initialize_params import InitializeParams diff --git a/src/isar/state_machine/states/__init__.py b/src/isar/state_machine/states/__init__.py index 034c06fe..e69de29b 100644 --- a/src/isar/state_machine/states/__init__.py +++ b/src/isar/state_machine/states/__init__.py @@ -1,8 +0,0 @@ -from .idle import Idle -from .initialize import Initialize -from .initiate import Initiate -from .monitor import Monitor -from .off import Off -from .offline import Offline -from .paused import Paused -from .stop import Stop diff --git a/src/isar/storage/blob_storage.py b/src/isar/storage/blob_storage.py index 2eee30dc..254ffd62 100644 --- a/src/isar/storage/blob_storage.py +++ b/src/isar/storage/blob_storage.py @@ -47,7 +47,7 @@ def store(self, inspection: Inspection, mission: Mission) -> Union[str, dict]: def _upload_file(self, path: Path, data: bytes) -> Union[str, dict]: blob_client = self._get_blob_client(path) try: - blob_properties = blob_client.upload_blob(data=data) + blob_client.upload_blob(data=data) except ResourceExistsError as e: self.logger.error( f"Blob {path.as_posix()} already exists in container. Error: {e}" diff --git a/src/isar/storage/uploader.py b/src/isar/storage/uploader.py index d270f2a1..b50c2cd4 100644 --- a/src/isar/storage/uploader.py +++ b/src/isar/storage/uploader.py @@ -8,7 +8,7 @@ from injector import inject from isar.config.settings import settings -from isar.models.communication.queues import Queues +from isar.models.communication.queues.queues import Queues from isar.storage.storage_interface import StorageException, StorageInterface from robot_interface.models.inspection.inspection import Inspection from robot_interface.models.mission.mission import Mission diff --git a/src/robot_interface/models/initialize/__init__.py b/src/robot_interface/models/initialize/__init__.py index d1f58fbb..e69de29b 100644 --- a/src/robot_interface/models/initialize/__init__.py +++ b/src/robot_interface/models/initialize/__init__.py @@ -1 +0,0 @@ -from .initialize_params import InitializeParams diff --git a/src/robot_interface/robot_interface.py b/src/robot_interface/robot_interface.py index 5a2c3fa2..109c284e 100644 --- a/src/robot_interface/robot_interface.py +++ b/src/robot_interface/robot_interface.py @@ -3,7 +3,7 @@ from threading import Thread from typing import Callable, List, Optional -from robot_interface.models.initialize import InitializeParams +from robot_interface.models.initialize.initialize_params import InitializeParams from robot_interface.models.inspection.inspection import Inspection from robot_interface.models.mission.mission import Mission from robot_interface.models.mission.status import RobotStatus, TaskStatus diff --git a/tests/conftest.py b/tests/conftest.py index 9eb04e8a..c6c9eb3b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,9 @@ from isar.services.service_connections.request_handler import RequestHandler from isar.services.utilities.scheduling_utilities import SchedulingUtilities from isar.state_machine.state_machine import StateMachine -from isar.state_machine.states import Idle, Initiate, Monitor +from isar.state_machine.states.idle import Idle +from isar.state_machine.states.initiate import Initiate +from isar.state_machine.states.monitor import Monitor from robot_interface.telemetry.mqtt_client import MqttClientInterface from tests.mocks.robot_interface import MockRobot from tests.test_modules import ( diff --git a/tests/isar/models/communication/test_queues.py b/tests/isar/models/communication/test_queues.py index 54a13588..02edcafa 100644 --- a/tests/isar/models/communication/test_queues.py +++ b/tests/isar/models/communication/test_queues.py @@ -2,7 +2,7 @@ import pytest -from isar.models.communication.queues import Queues, StatusQueue +from isar.models.communication.queues.queues import Queues, StatusQueue class TestQueues: diff --git a/tests/isar/services/utilities/test_scheduling_utilities.py b/tests/isar/services/utilities/test_scheduling_utilities.py index f60a67c7..bbec2ed8 100644 --- a/tests/isar/services/utilities/test_scheduling_utilities.py +++ b/tests/isar/services/utilities/test_scheduling_utilities.py @@ -4,7 +4,8 @@ from fastapi import HTTPException from pytest_mock import MockerFixture -from isar.models.communication.queues import QueueIO, QueueTimeoutError +from isar.models.communication.queues.queues import QueueIO +from isar.models.communication.queues.queue_timeout_error import QueueTimeoutError from isar.services.utilities.queue_utilities import QueueUtilities from isar.services.utilities.scheduling_utilities import SchedulingUtilities from isar.state_machine.states_enum import States diff --git a/tests/mocks/robot_interface.py b/tests/mocks/robot_interface.py index f5442f7b..b3ba284f 100644 --- a/tests/mocks/robot_interface.py +++ b/tests/mocks/robot_interface.py @@ -5,7 +5,7 @@ from alitra import Frame, Orientation, Pose, Position -from robot_interface.models.initialize import InitializeParams +from robot_interface.models.initialize.initialize_params import InitializeParams from robot_interface.models.inspection.inspection import ( Image, ImageMetadata,