From 9f227dc3ade2f46bcd1bd6e9b7d478dccd974233 Mon Sep 17 00:00:00 2001 From: Ondrej Tuma Date: Fri, 28 Jun 2024 11:43:48 +0200 Subject: [PATCH] Fix linter issues --- prusa/link/__main__.py | 1 + prusa/link/cameras/encoders.py | 37 ++++++++----------- prusa/link/multi_instance/__main__.py | 1 + .../link/printer_adapter/special_commands.py | 4 +- .../link/printer_adapter/telemetry_passer.py | 4 +- prusa/link/web/lib/files.py | 4 +- 6 files changed, 20 insertions(+), 31 deletions(-) diff --git a/prusa/link/__main__.py b/prusa/link/__main__.py index 33a2dc0b..63e07464 100644 --- a/prusa/link/__main__.py +++ b/prusa/link/__main__.py @@ -51,6 +51,7 @@ def excepthook(exception_arguments, args, argv): # excepthook has the global exception set, besides even if we failed # here, it will literally affect nothing # pylint: disable=misplaced-bare-raise + # ruff: noqa: PLE0704 raise diff --git a/prusa/link/cameras/encoders.py b/prusa/link/cameras/encoders.py index f23785d1..c6bbe639 100644 --- a/prusa/link/cameras/encoders.py +++ b/prusa/link/cameras/encoders.py @@ -149,10 +149,8 @@ def is_available(cls): ingest_format = v4l2.v4l2_format() ingest_format.type = v4l2.V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE ingest_format.fmt.pix_mp.pixelformat = v4l2.V4L2_PIX_FMT_YUYV - if fcntl.ioctl(file_descriptor, v4l2.VIDIOC_S_FMT, ingest_format): - return False - - return True + return not fcntl.ioctl(file_descriptor, v4l2.VIDIOC_S_FMT, + ingest_format) def __init__(self): """Initialise V4L2 encoder""" @@ -194,8 +192,7 @@ def _get_buffer(self, buffer_type, memory): # This is a definition of a ctype array plane_proto = v4l2.v4l2_plane * 1 buffer = v4l2.v4l2_buffer() - ctypes.memset( - ctypes.byref(buffer), 0, ctypes.sizeof(buffer)) + ctypes.memset(ctypes.byref(buffer), 0, ctypes.sizeof(buffer)) buffer.type = buffer_type buffer.memory = memory buffer.index = 0 @@ -216,8 +213,8 @@ def start(self): reference_complexity = 1920 * 1080 actual_complexity = self.width * self.height reference_bitrate = self.BITRATE_TABLE[self.quality] * 1000000 - self._bitrate = int(reference_bitrate * sqrt( - actual_complexity / reference_complexity)) + self._bitrate = int(reference_bitrate * + sqrt(actual_complexity / reference_complexity)) # pylint: disable=consider-using-with self.file_object = open(self.DEVICE_PATH, 'rb+', buffering=0) @@ -333,27 +330,21 @@ def encode(self, bytes_used): fcntl.ioctl(self.file_object, v4l2.VIDIOC_QBUF, self.ingest_buffer) - select.select((self.file_object,), (), ()) + select.select((self.file_object, ), (), ()) - if fcntl.ioctl(self.file_object, - v4l2.VIDIOC_DQBUF, + if fcntl.ioctl(self.file_object, v4l2.VIDIOC_DQBUF, self.ingest_buffer): raise RuntimeError( "Encoding failed - dequeueing the ingest buffer") - if fcntl.ioctl(self.file_object, - v4l2.VIDIOC_DQBUF, - self.coded_buffer): + if fcntl.ioctl(self.file_object, v4l2.VIDIOC_DQBUF, self.coded_buffer): raise RuntimeError( "Encoding failed - de-queueing the coded buffer") - output = self.coded_mmap.read( - self.coded_buffer.m.planes[0].bytesused) + output = self.coded_mmap.read(self.coded_buffer.m.planes[0].bytesused) self.coded_mmap.seek(0) - if fcntl.ioctl(self.file_object, - v4l2.VIDIOC_QBUF, - self.coded_buffer): + if fcntl.ioctl(self.file_object, v4l2.VIDIOC_QBUF, self.coded_buffer): raise RuntimeError( "Encoding failed - re-queueing the coded buffer") @@ -384,11 +375,13 @@ def encode(self, bytes_used): array_data = np.array(self.source_details.mmap, dtype=np.uint8) size = bytes_used - yuv_array = np.empty((size,), dtype=np.uint8) + yuv_array = np.empty((size, ), dtype=np.uint8) yuv_array[:size // 2] = array_data[0::2] - yuv_array[size // 2: size // 4 * 3] = array_data[1::4] + yuv_array[size // 2:size // 4 * 3] = array_data[1::4] yuv_array[size // 4 * 3:] = array_data[3::4] - return jpeg.encode_from_yuv(yuv_array, self.height, self.width, + return jpeg.encode_from_yuv(yuv_array, + self.height, + self.width, quality=self.quality_percent, jpeg_subsample=TJSAMP_422) diff --git a/prusa/link/multi_instance/__main__.py b/prusa/link/multi_instance/__main__.py index 16b1daef..0854d813 100644 --- a/prusa/link/multi_instance/__main__.py +++ b/prusa/link/multi_instance/__main__.py @@ -45,6 +45,7 @@ def main_thread_exception(exc_type, exc_value, exc_traceback): def thread_exception(_): """Re-raise unhandled exceptions in threads to call sys.excepthook""" + # ruff: noqa: PLE0704 raise # pylint: disable=misplaced-bare-raise diff --git a/prusa/link/printer_adapter/special_commands.py b/prusa/link/printer_adapter/special_commands.py index eec8b7ed..f92f3537 100644 --- a/prusa/link/printer_adapter/special_commands.py +++ b/prusa/link/printer_adapter/special_commands.py @@ -68,9 +68,7 @@ def _open_is_special(self, match): return False if parts[-2] != self.menu_folder_sfn: return False - if parts[-1] not in self.commands: - return False - return True + return parts[-1] in self.commands def handle_file(self, _, match): """A file has been opened, should we pass along that info, diff --git a/prusa/link/printer_adapter/telemetry_passer.py b/prusa/link/printer_adapter/telemetry_passer.py index 903d927a..c6c74774 100644 --- a/prusa/link/printer_adapter/telemetry_passer.py +++ b/prusa/link/printer_adapter/telemetry_passer.py @@ -256,9 +256,7 @@ def _should_wake_up(self, modifiers): return False if Modifier.FILTER_PRINTING in modifiers: return True - if Modifier.ACTIVATE_IDLE in modifiers: - return True - return False + return Modifier.ACTIVATE_IDLE in modifiers def reset_value(self, key_path): """Resets the value for filament_change_in and nothing else""" diff --git a/prusa/link/web/lib/files.py b/prusa/link/web/lib/files.py index 99f218bb..84418b0f 100644 --- a/prusa/link/web/lib/files.py +++ b/prusa/link/web/lib/files.py @@ -543,6 +543,4 @@ def check_cache_headers(req_headers: Headers, headers: dict, def get_boolean_header(headers, variable): """Return boolean value based on header variable""" header_boolean = headers.get(variable, "?0") - if header_boolean == "?1": - return True - return False + return header_boolean == "?1"