Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ondratu committed Jun 28, 2024
1 parent 3c7793e commit 9f227dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 31 deletions.
1 change: 1 addition & 0 deletions prusa/link/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
37 changes: 15 additions & 22 deletions prusa/link/cameras/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions prusa/link/multi_instance/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 1 addition & 3 deletions prusa/link/printer_adapter/special_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions prusa/link/printer_adapter/telemetry_passer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
4 changes: 1 addition & 3 deletions prusa/link/web/lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 9f227dc

Please sign in to comment.