From 029a99aaba4eae131dd58a2ce438f797e565aafa Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 6 Feb 2026 21:25:57 +0100 Subject: [PATCH] feat: added flake8 --- pyproject.toml | 44 +++++++++++++++++++ .../brother_printer/check_brother_printer.py | 9 ++-- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d8f12bb..3bc9e35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -281,6 +281,50 @@ partial_branches = [ # Note: Vulture uses command-line args, but we can document settings here # vulture --min-confidence 80 --exclude ".venv,Bash" . +# ============================================================================ +# FLAKE8 - Python linter (via Flake8-pyproject for pyproject.toml support) +# ============================================================================ +[tool.flake8] +# Maximum line length (matches ruff/black) +max-line-length = 88 +# Maximum McCabe complexity (matches ruff C901 threshold) +max-complexity = 10 +# Maximum cognitive complexity (flake8-cognitive-complexity) +max-cognitive-complexity = 12 +# Maximum function length (flake8-functions) +max-function-length = 50 +# Maximum returns/arguments per function +max-returns = 6 +max-arguments = 5 +# Docstring convention (matches ruff) +docstring-convention = "google" +# Select all error codes +select = ["E", "F", "W", "C", "B", "B950"] +# Extend with plugin codes +extend-select = ["B", "B9", "C4", "SIM", "PT", "TC", "ANN"] +# Ignore rules that conflict with ruff-format or are duplicated +extend-ignore = [ + "E501", # Line too long - B950 from bugbear is smarter (allows 10% overflow) + "W503", # Line break before binary operator - contradicts PEP 8 update + "ANN101", # Missing type annotation for self + "ANN102", # Missing type annotation for cls +] +# Exclude directories +exclude = [ + ".git", + ".venv", + "__pycache__", + "build", + "dist", + ".eggs", + "Bash/ffmpeg-build", +] +# Per-file ignores +per-file-ignores = [ + "**/tests/**/*.py:S101,ANN", + "**/test_*.py:S101,ANN", +] + # ============================================================================ # PYDOCSTYLE - Docstring style checker (ruff handles this, but for standalone) # ============================================================================ diff --git a/python_pkg/brother_printer/check_brother_printer.py b/python_pkg/brother_printer/check_brother_printer.py index 0bdf175..5ffb10f 100644 --- a/python_pkg/brother_printer/check_brother_printer.py +++ b/python_pkg/brother_printer/check_brother_printer.py @@ -13,6 +13,7 @@ Usage: from __future__ import annotations +import contextlib from dataclasses import dataclass, field import fcntl import logging @@ -243,11 +244,9 @@ def _drain_buffer(fd: int) -> None: """Read and discard any stale data from the USB buffer.""" flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) - try: + with contextlib.suppress(OSError): while os.read(fd, 4096): pass - except (BlockingIOError, OSError): - pass fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK) @@ -274,15 +273,13 @@ def pjl_query(fd: int, cmd: str, timeout_sec: float = 5.0) -> str: if readable: # Switch to non-blocking to read all available data fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) - try: + with contextlib.suppress(OSError): while True: chunk = os.read(fd, 4096) if chunk: response += chunk else: break - except (BlockingIOError, OSError): - pass fcntl.fcntl(fd, fcntl.F_SETFL, flags & ~os.O_NONBLOCK) # If we got meaningful PJL data, stop waiting if response and (b"=" in response or b"@PJL" in response):