From 58563c0af7045fa0393dccab90854825aea42255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Mon, 30 Mar 2026 17:20:51 +0200 Subject: [PATCH 1/2] tooling: Enable ruff preview rules for comment and operator spacing. --- lib/lis2mdl/lis2mdl/device.py | 2 +- lib/wsen-pads/examples/altitude.py | 4 ++-- lib/wsen-pads/examples/pressure_trend.py | 2 +- lib/wsen-pads/examples/threshold_alert.py | 4 ++-- pyproject.toml | 9 +++++++++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/lis2mdl/lis2mdl/device.py b/lib/lis2mdl/lis2mdl/device.py index 335ca51a..e90ea880 100644 --- a/lib/lis2mdl/lis2mdl/device.py +++ b/lib/lis2mdl/lis2mdl/device.py @@ -558,7 +558,7 @@ def heading_from_vectors(self, x, y, z, calibrated=True): x = (x - self.x_off) / (self.x_scale or 1.0) y = (y - self.y_off) / (self.y_scale or 1.0) # IMPORTANT: atan2(Y, X) - ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right) + ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right) ang = self._apply_heading_offsets(ang) return self._filter_heading(ang) diff --git a/lib/wsen-pads/examples/altitude.py b/lib/wsen-pads/examples/altitude.py index 23d428ed..84f0d589 100644 --- a/lib/wsen-pads/examples/altitude.py +++ b/lib/wsen-pads/examples/altitude.py @@ -3,8 +3,8 @@ from machine import I2C from wsen_pads import WSEN_PADS -SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation -EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation +SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation +EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation i2c = I2C(1) diff --git a/lib/wsen-pads/examples/pressure_trend.py b/lib/wsen-pads/examples/pressure_trend.py index 01e06695..6424306c 100644 --- a/lib/wsen-pads/examples/pressure_trend.py +++ b/lib/wsen-pads/examples/pressure_trend.py @@ -13,7 +13,7 @@ pressure_history = [] MAX_VALUES = 10 -THRESHOLD = 0.5 # sensitivity (hPa) +THRESHOLD = 0.5 # sensitivity (hPa) def get_trend(values): if len(values) < 2: diff --git a/lib/wsen-pads/examples/threshold_alert.py b/lib/wsen-pads/examples/threshold_alert.py index 1aac09d3..7610faab 100644 --- a/lib/wsen-pads/examples/threshold_alert.py +++ b/lib/wsen-pads/examples/threshold_alert.py @@ -6,8 +6,8 @@ from wsen_pads import WSEN_PADS from wsen_pads.const import ODR_10_HZ -PRESSURE_ALERT_HPA = 1000 # Alert threshold -READ_INTERVAL_S = 1 # Time between printed readings +PRESSURE_ALERT_HPA = 1000 # Alert threshold +READ_INTERVAL_S = 1 # Time between printed readings i2c = I2C(1) sensor = WSEN_PADS(i2c) diff --git a/pyproject.toml b/pyproject.toml index efb4e301..c747d23f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,8 @@ line-length = 99 target-version = "py37" [tool.ruff.lint] +preview = true +explicit-preview-rules = true select = [ "A", # flake8-builtins: prevent shadowing builtins "ASYNC", # flake8-async @@ -45,6 +47,10 @@ select = [ "C90", # McCabe cyclomatic complexity "DTZ", # flake8-datetimez "E", # pycodestyle + "E225", # (preview) missing whitespace around operator + "E261", # (preview) at least two spaces before inline comment + "E262", # (preview) inline comment must start with '# ' + "E265", # (preview) block comment must start with '# ' "EXE", # flake8-executable "F", # Pyflakes "G", # flake8-logging-format @@ -83,6 +89,9 @@ ignore = [ "PLW0603", # global statement "PLW2901", # overwriting loop variable "RUF012", # mutable class variable + "RUF001", # ambiguous unicode in string (µ for microtesla is intentional) + "RUF002", # ambiguous unicode in docstring + "RUF003", # ambiguous unicode in comment "RUF100", # unused noqa "SIM101", # merge isinstance calls (micropython compat) "SIM105", # contextlib.suppress not available in micropython From 46459d3011bd68f4f38bc070e602762bdaaef573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Mon, 30 Mar 2026 17:31:13 +0200 Subject: [PATCH 2/2] tooling: Bump ruff target to py310 and scope RUF unicode ignores to lis2mdl. --- pyproject.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c747d23f..bf8a5a64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ markers = [ [tool.ruff] line-length = 99 -target-version = "py37" +target-version = "py310" [tool.ruff.lint] preview = true @@ -76,6 +76,7 @@ select = [ "YTT", # flake8-2020 ] ignore = [ + "B905", # zip() strict= not available in micropython "E501", # line length, recommended to disable "E741", # 'l' is currently widely used "ISC001", # conflicts with formatter @@ -89,9 +90,6 @@ ignore = [ "PLW0603", # global statement "PLW2901", # overwriting loop variable "RUF012", # mutable class variable - "RUF001", # ambiguous unicode in string (µ for microtesla is intentional) - "RUF002", # ambiguous unicode in docstring - "RUF003", # ambiguous unicode in comment "RUF100", # unused noqa "SIM101", # merge isinstance calls (micropython compat) "SIM105", # contextlib.suppress not available in micropython @@ -117,6 +115,7 @@ max-statements = 65 "**/examples/*.py" = ["T20", "N806"] "lib/mcp23009e/examples/i2c_scan.py" = ["PERF203"] "tests/**/*.py" = ["T20", "PLR0911", "PLR0912", "PLR0915"] +"lib/lis2mdl/**/*.py" = ["RUF001", "RUF002", "RUF003"] # µ (microtesla) is intentional [tool.ruff.format] quote-style = "double"