mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
implement ruff recommendations
This commit is contained in:
parent
4802f19720
commit
598449e893
@ -28,7 +28,7 @@ class Image(DataService):
|
|||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def format(self) -> str:
|
def format(self) -> str: # noqa: A003
|
||||||
return self._format
|
return self._format
|
||||||
|
|
||||||
def load_from_path(self, path: Path | str) -> None:
|
def load_from_path(self, path: Path | str) -> None:
|
||||||
|
@ -309,8 +309,8 @@ class CallbackManager:
|
|||||||
):
|
):
|
||||||
|
|
||||||
def list_or_data_service_callback(
|
def list_or_data_service_callback(
|
||||||
name: Any, # noqa: ARG001
|
name: Any,
|
||||||
value: Any, # noqa: ARG001
|
value: Any,
|
||||||
dependent_attr: str = attr_name,
|
dependent_attr: str = attr_name,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Emits a notification through the service's callback
|
"""Emits a notification through the service's callback
|
||||||
@ -331,7 +331,7 @@ class CallbackManager:
|
|||||||
|
|
||||||
def callback(
|
def callback(
|
||||||
name: str,
|
name: str,
|
||||||
value: Any, # noqa: ARG001
|
value: Any,
|
||||||
dependent_attr: str = attr_name,
|
dependent_attr: str = attr_name,
|
||||||
dep: str = dependency,
|
dep: str = dependency,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -23,7 +23,7 @@ from pydase.utils.serializer import (
|
|||||||
get_nested_dict_by_path,
|
get_nested_dict_by_path,
|
||||||
)
|
)
|
||||||
from pydase.utils.warnings import (
|
from pydase.utils.warnings import (
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService,
|
warn_if_instance_class_does_not_inherit_from_data_service,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -98,7 +98,7 @@ class DataService(rpyc.Service, AbstractDataService):
|
|||||||
# every class defined by the user should inherit from DataService if it is
|
# every class defined by the user should inherit from DataService if it is
|
||||||
# assigned to a public attribute
|
# assigned to a public attribute
|
||||||
if not attr_name.startswith("_"):
|
if not attr_name.startswith("_"):
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService(attr_value)
|
warn_if_instance_class_does_not_inherit_from_data_service(attr_value)
|
||||||
|
|
||||||
def __set_attribute_based_on_type( # noqa: PLR0913
|
def __set_attribute_based_on_type( # noqa: PLR0913
|
||||||
self,
|
self,
|
||||||
|
@ -3,7 +3,7 @@ from typing import Any
|
|||||||
|
|
||||||
import pydase.units as u
|
import pydase.units as u
|
||||||
from pydase.utils.warnings import (
|
from pydase.utils.warnings import (
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService,
|
warn_if_instance_class_does_not_inherit_from_data_service,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ class DataServiceList(list):
|
|||||||
self._callbacks = callback_list
|
self._callbacks = callback_list
|
||||||
|
|
||||||
for item in args[0]:
|
for item in args[0]:
|
||||||
warn_if_instance_class_does_not_inherit_from_DataService(item)
|
warn_if_instance_class_does_not_inherit_from_data_service(item)
|
||||||
|
|
||||||
# prevent gc to delete the passed list by keeping a reference
|
# prevent gc to delete the passed list by keeping a reference
|
||||||
self._original_list = args[0]
|
self._original_list = args[0]
|
||||||
|
@ -164,16 +164,18 @@ class Server:
|
|||||||
def __init__( # noqa: PLR0913
|
def __init__( # noqa: PLR0913
|
||||||
self,
|
self,
|
||||||
service: DataService,
|
service: DataService,
|
||||||
host: str = "0.0.0.0",
|
host: str = "127.0.0.1",
|
||||||
rpc_port: int = 18871,
|
rpc_port: int = 18871,
|
||||||
web_port: int = 8001,
|
web_port: int = 8001,
|
||||||
enable_rpc: bool = True,
|
enable_rpc: bool = True,
|
||||||
enable_web: bool = True,
|
enable_web: bool = True,
|
||||||
filename: Optional[str | Path] = None,
|
filename: Optional[str | Path] = None,
|
||||||
use_forking_server: bool = False,
|
use_forking_server: bool = False,
|
||||||
additional_servers: list[AdditionalServer] = [],
|
additional_servers: list[AdditionalServer] | None = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
if additional_servers is None:
|
||||||
|
additional_servers = []
|
||||||
self._service = service
|
self._service = service
|
||||||
self._host = host
|
self._host = host
|
||||||
self._rpc_port = rpc_port
|
self._rpc_port = rpc_port
|
||||||
@ -276,10 +278,6 @@ class Server:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def sio_callback(parent_path: str, name: str, value: Any) -> None:
|
def sio_callback(parent_path: str, name: str, value: Any) -> None:
|
||||||
# TODO: an error happens when an attribute is set to a list
|
|
||||||
# > File "/usr/lib64/python3.11/json/encoder.py", line 180, in default
|
|
||||||
# > raise TypeError(f'Object of type {o.__class__.__name__} '
|
|
||||||
# > TypeError: Object of type list is not JSON serializable
|
|
||||||
full_access_path = ".".join([*parent_path.split(".")[1:], name])
|
full_access_path = ".".join([*parent_path.split(".")[1:], name])
|
||||||
cached_value_dict = deepcopy(
|
cached_value_dict = deepcopy(
|
||||||
get_nested_dict_by_path(self._state_manager.cache, full_access_path)
|
get_nested_dict_by_path(self._state_manager.cache, full_access_path)
|
||||||
|
@ -70,13 +70,13 @@ class WebAPI:
|
|||||||
__sio_app: socketio.ASGIApp
|
__sio_app: socketio.ASGIApp
|
||||||
__fastapi_app: FastAPI
|
__fastapi_app: FastAPI
|
||||||
|
|
||||||
def __init__(
|
def __init__( # noqa: PLR0913
|
||||||
self,
|
self,
|
||||||
service: DataService,
|
service: DataService,
|
||||||
state_manager: StateManager,
|
state_manager: StateManager,
|
||||||
frontend: str | Path | None = None,
|
frontend: str | Path | None = None,
|
||||||
css: str | Path | None = None,
|
css: str | Path | None = None,
|
||||||
enable_CORS: bool = True,
|
enable_cors: bool = True,
|
||||||
*args: Any,
|
*args: Any,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -84,7 +84,7 @@ class WebAPI:
|
|||||||
self.state_manager = state_manager
|
self.state_manager = state_manager
|
||||||
self.frontend = frontend
|
self.frontend = frontend
|
||||||
self.css = css
|
self.css = css
|
||||||
self.enable_CORS = enable_CORS
|
self.enable_cors = enable_cors
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class WebAPI:
|
|||||||
|
|
||||||
def setup_socketio(self) -> None:
|
def setup_socketio(self) -> None:
|
||||||
# the socketio ASGI app, to notify clients when params update
|
# the socketio ASGI app, to notify clients when params update
|
||||||
if self.enable_CORS:
|
if self.enable_cors:
|
||||||
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
||||||
else:
|
else:
|
||||||
sio = socketio.AsyncServer(async_mode="asgi")
|
sio = socketio.AsyncServer(async_mode="asgi")
|
||||||
@ -127,7 +127,7 @@ class WebAPI:
|
|||||||
def setup_fastapi_app(self) -> None:
|
def setup_fastapi_app(self) -> None:
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
if self.enable_CORS:
|
if self.enable_cors:
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
|
@ -54,7 +54,7 @@ def get_object_attr_from_path_list(target_obj: Any, path: list[str]) -> Any:
|
|||||||
index_str = index_str.replace("]", "")
|
index_str = index_str.replace("]", "")
|
||||||
index = int(index_str)
|
index = int(index_str)
|
||||||
target_obj = getattr(target_obj, attr)[index]
|
target_obj = getattr(target_obj, attr)[index]
|
||||||
except ValueError:
|
except ValueError: # noqa: PERF203
|
||||||
# No index, so just get the attribute
|
# No index, so just get the attribute
|
||||||
target_obj = getattr(target_obj, part)
|
target_obj = getattr(target_obj, part)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -5,7 +5,7 @@ from pydase.utils.helpers import get_component_class_names
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def warn_if_instance_class_does_not_inherit_from_DataService(__value: object) -> None:
|
def warn_if_instance_class_does_not_inherit_from_data_service(__value: object) -> None:
|
||||||
base_class_name = __value.__class__.__base__.__name__
|
base_class_name = __value.__class__.__base__.__name__
|
||||||
module_name = __value.__class__.__module__
|
module_name = __value.__class__.__module__
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ def warn_if_instance_class_does_not_inherit_from_DataService(__value: object) ->
|
|||||||
"_abc",
|
"_abc",
|
||||||
]
|
]
|
||||||
and base_class_name
|
and base_class_name
|
||||||
not in ["DataService", "list", "Enum"] + get_component_class_names()
|
not in ["DataService", "list", "Enum", *get_component_class_names()]
|
||||||
and type(__value).__name__ not in ["CallbackManager", "TaskManager", "Quantity"]
|
and type(__value).__name__ not in ["CallbackManager", "TaskManager", "Quantity"]
|
||||||
):
|
):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user