From 528c6a2b63de15c97507fd0bf46e2538f7e91a8e Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Thu, 18 Sep 2025 14:58:00 +0100 Subject: [PATCH] Add PyLint ruff checks --- pyproject.toml | 12 ++++++++++-- src/openflexure_microscope_server/logging.py | 2 +- .../things/autofocus.py | 5 ++++- .../things/camera/picamera_recalibrate_utils.py | 6 +++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ef0c8af2..02e5e93e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ select = [ "E", # pycodestyle errors "W", #pycodestyle warnings "F", # PyFlakes -# "PL", # Pylint (a subset of, catches far less than pylint does) + "PL", # Pylint (a subset of, catches far less than pylint does) "B", # Flake8 bugbear "A", # Flake8 builtins checker "C", # Flake8 comprehensions @@ -137,6 +137,9 @@ ignore = [ "D400", # A stricter version of #415 that doesn't allow ! "ANN401", # Disalows Any, Any is needed at times, Once MyPy is running Any will be # handled appropriately + "PLR2004", # Ignore magic values in comparison for now. It doesn't seem we can set + # allowed magic values and a number of our magic values are not really + # magic (such as 255 when doing uint8 maths) ] [tool.ruff.lint.per-file-ignores] @@ -146,7 +149,8 @@ ignore = [ "ANN", # Tests are not typehinted for fixtures etc "S101", # Allow asserts in tests "T20", # Allow prints in tests - "LOG015",# Allow tests to use the root logger. + "LOG015", # Allow tests to use the root logger. + "PLC0415", # Allow tests to import later as this is needed for mocking ] # Developer CLI scripts "{pull_webapp,picamera_tests,change_log_helper}.py" = [ @@ -157,3 +161,7 @@ ignore = [ # This lets the D401 checker understand that decorated thing properties and thing # settings act like properties so should be documented as such. property-decorators = ["labthings_fastapi.thing_property", "labthings_fastapi.thing_setting"] + +[tool.ruff.lint.pylint] +max-args = 7 +max-positional-args = 5 \ No newline at end of file diff --git a/src/openflexure_microscope_server/logging.py b/src/openflexure_microscope_server/logging.py index 5e09b054..d50fb72f 100644 --- a/src/openflexure_microscope_server/logging.py +++ b/src/openflexure_microscope_server/logging.py @@ -34,7 +34,7 @@ def configure_logging(log_folder: str) -> None: root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) # Explicitly make OFM_LOG_FILE a global so it can be updated based on log settings - global OFM_LOG_FILE + global OFM_LOG_FILE # noqa: PLW0603 OFM_LOG_FILE = os.path.join(log_folder, "openflexure_microscope.log") # Add OFM_HANDLER first so it can capture the error log if the diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 5c5e01dc..88ad91eb 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -706,7 +706,10 @@ class AutofocusThing(lt.Thing): sharpness=cam.grab_jpeg_size(stream_name="lores"), ) - def check_stack_result( + # Silence too many returns in this situation as refactoring to reduce returns is + # unlikely to improve readability. This function is basically a complex switch + # statement, having an explicit return after each option is clear. + def check_stack_result( # noqa: PLR0911 self, captures: list[CaptureInfo] ) -> tuple[Literal["success", "continue", "restart"], int]: """Check if the sharpest image in a list of captures is central enough. diff --git a/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py b/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py index b88976b6..ff15e02d 100644 --- a/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py +++ b/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py @@ -201,9 +201,13 @@ def adjust_shutter_and_gain_from_raw( return test.level -def adjust_white_balance_from_raw( +# Explicitly allow this to have 8 arguments as the later arguments are keyword only +# We should be able to enforce this without noqa once PyLint moves PLR0917 out of +# preview +def adjust_white_balance_from_raw( # noqa: PLR0913 camera: Picamera2, sensor_info: SensorInfo, + *, percentile: float = 99, luminance: Optional[np.ndarray] = None, Cr: Optional[np.ndarray] = None,