Add PyLint ruff checks

This commit is contained in:
Julian Stirling 2025-09-18 14:58:00 +01:00
parent 65f172d650
commit 528c6a2b63
4 changed files with 20 additions and 5 deletions

View file

@ -108,7 +108,7 @@ select = [
"E", # pycodestyle errors "E", # pycodestyle errors
"W", #pycodestyle warnings "W", #pycodestyle warnings
"F", # PyFlakes "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 "B", # Flake8 bugbear
"A", # Flake8 builtins checker "A", # Flake8 builtins checker
"C", # Flake8 comprehensions "C", # Flake8 comprehensions
@ -137,6 +137,9 @@ ignore = [
"D400", # A stricter version of #415 that doesn't allow ! "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 "ANN401", # Disalows Any, Any is needed at times, Once MyPy is running Any will be
# handled appropriately # 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] [tool.ruff.lint.per-file-ignores]
@ -147,6 +150,7 @@ ignore = [
"S101", # Allow asserts in tests "S101", # Allow asserts in tests
"T20", # Allow prints 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 # Developer CLI scripts
"{pull_webapp,picamera_tests,change_log_helper}.py" = [ "{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 # This lets the D401 checker understand that decorated thing properties and thing
# settings act like properties so should be documented as such. # settings act like properties so should be documented as such.
property-decorators = ["labthings_fastapi.thing_property", "labthings_fastapi.thing_setting"] property-decorators = ["labthings_fastapi.thing_property", "labthings_fastapi.thing_setting"]
[tool.ruff.lint.pylint]
max-args = 7
max-positional-args = 5

View file

@ -34,7 +34,7 @@ def configure_logging(log_folder: str) -> None:
root_logger = logging.getLogger() root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO) root_logger.setLevel(logging.INFO)
# Explicitly make OFM_LOG_FILE a global so it can be updated based on log settings # 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") OFM_LOG_FILE = os.path.join(log_folder, "openflexure_microscope.log")
# Add OFM_HANDLER first so it can capture the error log if the # Add OFM_HANDLER first so it can capture the error log if the

View file

@ -706,7 +706,10 @@ class AutofocusThing(lt.Thing):
sharpness=cam.grab_jpeg_size(stream_name="lores"), 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] self, captures: list[CaptureInfo]
) -> tuple[Literal["success", "continue", "restart"], int]: ) -> tuple[Literal["success", "continue", "restart"], int]:
"""Check if the sharpest image in a list of captures is central enough. """Check if the sharpest image in a list of captures is central enough.

View file

@ -201,9 +201,13 @@ def adjust_shutter_and_gain_from_raw(
return test.level 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, camera: Picamera2,
sensor_info: SensorInfo, sensor_info: SensorInfo,
*,
percentile: float = 99, percentile: float = 99,
luminance: Optional[np.ndarray] = None, luminance: Optional[np.ndarray] = None,
Cr: Optional[np.ndarray] = None, Cr: Optional[np.ndarray] = None,