Skip to content

Commit aa08fbe

Browse files
authored
tooling: Enable ruff preview rules E203, E302, and E303. (#401)
* tooling: Enable ruff preview rules E203, E302, and E303. Closes #400. These three pycodestyle rules are in preview in ruff 0.11.6 and were not active because of explicit-preview-rules = true. Add them to the explicit select list and auto-fix the 11 existing violations across the codebase: E203 — whitespace before ':' (catches `else :`, `if x :`, etc.) E302 — expected 2 blank lines before function/class definition E303 — too many blank lines inside a block E203 was spotted in PR #399 (Aline's tamagotchi example) and E302/E303 in PR #376 (Kaan's spirit level) — both were caught manually because ruff did not flag them. * tooling: Add steami_screen to Pylance extraPaths. * tooling: Remove deprecated and unknown settings from VSCode config. * tooling: Migrate Pylance settings from VSCode to pyproject.toml. Pylance ignores python.analysis.* in settings.json when a pyproject.toml exists and warns "cannot be set when a pyproject.toml is being used". Move typeCheckingMode, extraPaths, stubPath, and diagnosticSeverityOverrides into [tool.pyright] in pyproject.toml where Pylance reads them. This also makes the configuration IDE-agnostic (works for any pyright-based tool, not just VSCode).
1 parent e619b1e commit aa08fbe

10 files changed

Lines changed: 34 additions & 34 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
{
22
"python.languageServer": "Pylance",
3-
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
4-
"python.analysis.typeCheckingMode": "basic",
5-
"python.analysis.extraPaths": [
6-
"lib/apds9960",
7-
"lib/bme280",
8-
"lib/bq27441",
9-
"lib/daplink_bridge",
10-
"lib/daplink_flash",
11-
"lib/gc9a01",
12-
"lib/hts221",
13-
"lib/im34dt05",
14-
"lib/ism330dl",
15-
"lib/lis2mdl",
16-
"lib/mcp23009e",
17-
"lib/ssd1327",
18-
"lib/steami_config",
19-
"lib/vl53l1x",
20-
"lib/wsen-hids",
21-
"lib/wsen-pads"
22-
],
23-
"python.analysis.stubPath": "typings",
24-
"python.analysis.diagnosticSeverityOverrides": {
25-
"reportMissingModuleSource": "none",
26-
"reportWildcardImportFromLibrary": "none",
27-
"reportGeneralTypeIssues": "warning"
28-
},
29-
"pylint.enabled": false,
30-
"mypy-type-checker.enabled": false
3+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"
314
}

lib/apds9960/examples/light_theremin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
# Map the light range to an index in our note array (0 to 14)
6767
note_index = (clamped_light - MIN_LIGHT) * (TOTAL_NOTES - 1) // range_light
6868

69-
7069
# Fetch the perfect harmonic frequency
7170
freq = PENTATONIC_NOTES[note_index]
7271

@@ -77,7 +76,6 @@
7776
print("Light: {} | Note: {} | Freq: {} Hz".format(light_level, note_index, freq), end="\r")
7877
last_freq = freq
7978

80-
8179
sleep_ms(20)
8280

8381
except KeyboardInterrupt:

lib/mcp23009e/examples/i2c_scan.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
reset.value(1)
1414

1515

16-
1716
print("=" * 60)
1817
print("Scanner I2C - Recherche des périphériques")
1918
print("=" * 60)

lib/steami_config/steami_config/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Reverse map: short key -> sensor name.
1313
_KEY_SENSORS = {v: k for k, v in _SENSOR_KEYS.items()}
1414

15+
1516
class SteamiConfig(object):
1617
"""Persistent configuration stored in the DAPLink F103 config zone.
1718
@@ -239,7 +240,6 @@ def get_accelerometer_calibration(self):
239240
"oz": cal.get("oz", 0.0),
240241
}
241242

242-
243243
def apply_accelerometer_calibration(self, ism330dl_instance):
244244
"""Apply stored accelerometer calibration to an ISM330DL instance."""
245245
if type(ism330dl_instance).__name__.lower() != "ism330dl":

lib/steami_screen/steami_screen/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
# --- Cardinal position names ---
4242

43+
4344
class Screen:
4445
"""High-level wrapper around a raw display backend."""
4546

@@ -196,7 +197,6 @@ def bar(self, val, max_val=100, y_offset=0, color=LIGHT):
196197
if fill_w > 0:
197198
self._fill_rect(bx, by, fill_w, bar_h, color)
198199

199-
200200
def gauge(self, val, min_val=0, max_val=100, color=LIGHT):
201201
"""Draw a circular arc gauge (270 deg, gap at bottom).
202202

lib/wsen-pads/examples/altitude.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
sensor = WSEN_PADS(i2c)
1212

13+
1314
def pressure_to_altitude(p):
1415
return 44330 * (1 - (p / SEA_LEVEL_PRESSURE) ** EXPONENT)
1516

lib/wsen-pads/examples/pressure_trend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
MAX_VALUES = 10
1616
THRESHOLD = 0.5 # sensitivity (hPa)
1717

18+
1819
def get_trend(values):
1920
if len(values) < 2:
2021
return "N/A"

lib/wsen-pads/examples/temp_pressure_display.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
i2c = I2C(1)
1616
sensor = WSEN_PADS(i2c)
1717

18+
1819
def bar_graph(value, vmin, vmax, width=20):
1920
# Clamp value
2021
if value < vmin:

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ select = [
4848
"C90", # McCabe cyclomatic complexity
4949
"DTZ", # flake8-datetimez
5050
"E", # pycodestyle
51+
"E203", # (preview) whitespace before ':', ';', or ','
5152
"E225", # (preview) missing whitespace around operator
5253
"E261", # (preview) at least two spaces before inline comment
5354
"E262", # (preview) inline comment must start with '# '
5455
"E265", # (preview) block comment must start with '# '
56+
"E302", # (preview) expected 2 blank lines before function/class definition
57+
"E303", # (preview) too many blank lines
5558
"EXE", # flake8-executable
5659
"F", # Pyflakes
5760
"G", # flake8-logging-format
@@ -125,3 +128,28 @@ quote-style = "double"
125128
indent-style = "space"
126129
skip-magic-trailing-comma = false
127130
line-ending = "auto"
131+
132+
[tool.pyright]
133+
typeCheckingMode = "basic"
134+
stubPath = "typings"
135+
extraPaths = [
136+
"lib/apds9960",
137+
"lib/bme280",
138+
"lib/bq27441",
139+
"lib/daplink_bridge",
140+
"lib/daplink_flash",
141+
"lib/gc9a01",
142+
"lib/hts221",
143+
"lib/im34dt05",
144+
"lib/ism330dl",
145+
"lib/lis2mdl",
146+
"lib/mcp23009e",
147+
"lib/ssd1327",
148+
"lib/steami_config",
149+
"lib/steami_screen",
150+
"lib/vl53l1x",
151+
"lib/wsen-hids",
152+
"lib/wsen-pads",
153+
]
154+
reportMissingModuleSource = "none"
155+
reportWildcardImportFromLibrary = "none"

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def pytest_addoption(parser):
2323
)
2424

2525

26-
2726
def pytest_collection_modifyitems(config, items):
2827
port = config.getoption("--port")
2928
driver = config.getoption("--driver")

0 commit comments

Comments
 (0)