Skip to content

Commit 5f99e8a

Browse files
committed
ci: Enable ruff N802, N803, N806, T20 naming rules.
1 parent b61e328 commit 5f99e8a

6 files changed

Lines changed: 31 additions & 26 deletions

File tree

lib/bq27441/bq27441/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class BQ27441(object):
7777
def __init__(
7878
self,
7979
i2c,
80-
capacity_mAh=LIPO_BATTERY_CAPACITY,
80+
capacity_mAh=LIPO_BATTERY_CAPACITY, # noqa: N803
8181
address=BQ27441_I2C_ADDRESS,
8282
gpout_pin=None,
8383
):

lib/hts221/hts221/device.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def _read_reg(self, reg):
5252
return self.readbuffer[0]
5353

5454
def _read_reg16(self, reg):
55-
lowerByte = self._read_reg(reg)
56-
higherByte = self._read_reg(reg + 1)
57-
return (higherByte << 8) + lowerByte
55+
lo = self._read_reg(reg)
56+
hi = self._read_reg(reg + 1)
57+
return (hi << 8) + lo
5858

5959
# Device identification
6060
def who_am_i(self):

lib/lis2mdl/lis2mdl/device.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def _read_reg(self, reg):
203203

204204
_MAG_LSB_TO_uT = 0.15 # 1.5 mG/LSB ≈ 0.15 µT/LSB
205205

206-
def read_magnet_uT(self):
206+
def read_magnet_uT(self): # noqa: N802
207207
"""Reads the magnetic field in µT, uncalibrated (simple conversion from LSB)."""
208208
x, y, z = self.read_magnet()
209209
return (
@@ -220,7 +220,7 @@ def read_magnet_calibrated_norm(self):
220220
z = (z - self.z_off) / self.z_scale
221221
return (x, y, z)
222222

223-
def magnitude_uT(self) -> float:
223+
def magnitude_uT(self) -> float: # noqa: N802
224224
"""Total magnetic field strength (µT)."""
225225
x, y, z = self.read_magnet_uT()
226226
return math.sqrt(x * x + y * y + z * z)
@@ -328,11 +328,11 @@ def read_registers(self, start_addr: int, length: int) -> bytes:
328328
def read_all(self) -> dict:
329329
"""Grouped reading useful for debug & logs."""
330330
raw = self.read_magnet_raw()
331-
uT = self.read_magnet_uT()
331+
mag_ut = self.read_magnet_uT()
332332
cal = self.read_magnet_calibrated_norm()
333-
T = self.read_temperature_c()
333+
temp = self.read_temperature_c()
334334
st = self.read_status()
335-
return {"raw": raw, "uT": uT, "cal_norm": cal, "tempC": T, "status": st}
335+
return {"raw": raw, "uT": mag_ut, "cal_norm": cal, "tempC": temp, "status": st}
336336

337337
##
338338
# --- CALIBRATIONS ---
@@ -508,9 +508,9 @@ def _filter_heading(self, angle_deg):
508508
self._hf_cos = (1.0 - a) * self._hf_cos + a * c
509509
self._hf_sin = (1.0 - a) * self._hf_sin + a * s
510510
# light normalization to avoid amplitude drift
511-
NORMALIZATION_THRESHOLD = 1e-6
511+
norm_threshold = 1e-6
512512
norm = math.sqrt(self._hf_cos * self._hf_cos + self._hf_sin * self._hf_sin)
513-
if norm > NORMALIZATION_THRESHOLD:
513+
if norm > norm_threshold:
514514
self._hf_cos /= norm
515515
self._hf_sin /= norm
516516
ang = math.degrees(math.atan2(self._hf_sin, self._hf_cos))
@@ -556,13 +556,13 @@ def heading_with_tilt_compensation(self, read_accel):
556556
roll = math.atan2(ay, az)
557557
pitch = math.atan2(-ax, math.sqrt(ay * ay + az * az))
558558
# straighten the magnetic vector
559-
Xh = x * math.cos(pitch) + z * math.sin(pitch)
560-
Yh = (
559+
xh = x * math.cos(pitch) + z * math.sin(pitch)
560+
yh = (
561561
x * math.sin(roll) * math.sin(pitch)
562562
+ y * math.cos(roll)
563563
- z * math.sin(roll) * math.cos(pitch)
564564
)
565-
ang = math.degrees(math.atan2(Yh, Xh)) # atan2(Yh, Xh)
565+
ang = math.degrees(math.atan2(yh, xh))
566566
ang = self._apply_heading_offsets(ang)
567567
return self._filter_heading(ang)
568568

lib/ssd1327/examples/rotating_3d_cube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
r = [0, 0, 0]
2828

2929

30-
def drawCube():
30+
def draw_cube():
3131
r[0] = r[0] + pi / 180.0
3232
r[1] = r[1] + pi / 180.0
3333
r[2] = r[2] + pi / 180.0
@@ -70,4 +70,4 @@ def drawCube():
7070

7171

7272
while True:
73-
drawCube()
73+
draw_cube()

lib/wsen-hids/wsen_hids/device.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,20 @@ def check_device(self):
144144
def _read_calibration(self):
145145
h0_rh_x2 = self._read_reg(REG_H0_RH_X2)
146146
h1_rh_x2 = self._read_reg(REG_H1_RH_X2)
147-
t0_degC_x8_lsb = self._read_reg(REG_T0_DEGC_X8)
148-
t1_degC_x8_lsb = self._read_reg(REG_T1_DEGC_X8)
147+
t0_degc_x8_lsb = self._read_reg(REG_T0_DEGC_X8)
148+
t1_degc_x8_lsb = self._read_reg(REG_T1_DEGC_X8)
149149
t1_t0_msb = self._read_reg(REG_T1_T0_MSB)
150150

151-
t0_degC_x8 = ((t1_t0_msb & 0x03) << 8) | t0_degC_x8_lsb
152-
t1_degC_x8 = ((t1_t0_msb & 0x0C) << 6) | t1_degC_x8_lsb
151+
t0_degc_x8 = ((t1_t0_msb & 0x03) << 8) | t0_degc_x8_lsb
152+
t1_degc_x8 = ((t1_t0_msb & 0x0C) << 6) | t1_degc_x8_lsb
153153

154154
self._calibration = {
155155
"H0_rH": h0_rh_x2 / 2.0,
156156
"H1_rH": h1_rh_x2 / 2.0,
157157
"H0_T0_OUT": self._read_s16_le(REG_H0_T0_OUT_L),
158158
"H1_T0_OUT": self._read_s16_le(REG_H1_T0_OUT_L),
159-
"T0_degC": t0_degC_x8 / 8.0,
160-
"T1_degC": t1_degC_x8 / 8.0,
159+
"T0_degC": t0_degc_x8 / 8.0,
160+
"T1_degC": t1_degc_x8 / 8.0,
161161
"T0_OUT": self._read_s16_le(REG_T0_OUT_L),
162162
"T1_OUT": self._read_s16_le(REG_T1_OUT_L),
163163
}
@@ -250,16 +250,16 @@ def _convert_humidity(self, h_raw):
250250
return self._clamp(humidity, 0.0, 100.0)
251251

252252
def _convert_temperature(self, t_raw):
253-
t0_degC = self._calibration["T0_degC"]
254-
t1_degC = self._calibration["T1_degC"]
253+
t0_degc = self._calibration["T0_degC"]
254+
t1_degc = self._calibration["T1_degC"]
255255
t0_out = self._calibration["T0_OUT"]
256256
t1_out = self._calibration["T1_OUT"]
257257

258258
delta_out = t1_out - t0_out
259259
if delta_out == 0:
260260
raise WSENHIDSError("Invalid temperature calibration data")
261261

262-
factory = ((t1_degC - t0_degC) * (t_raw - t0_out) / delta_out) + t0_degC
262+
factory = ((t1_degc - t0_degc) * (t_raw - t0_out) / delta_out) + t0_degc
263263
return self._temp_gain * factory + self._temp_offset
264264

265265
# -------------------------------------------------------------------------

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ select = [
4141
# "FBT", # flake8-boolean-trap
4242
# "I", # isort
4343
# "INP", # flake8-no-pep420
44-
# "N", # pep8-naming
44+
"N802", # pep8-naming: function name should be lowercase
45+
"N803", # pep8-naming: argument name should be lowercase
46+
"N806", # pep8-naming: variable in function should be lowercase
47+
"T20", # flake8-print: no print() in production code
4548
# "NPY", # NumPy-specific rules
4649
# "PD", # pandas-vet
4750
# "PT", # flake8-pytest-style
@@ -92,6 +95,8 @@ max-statements = 166
9295
[tool.ruff.lint.per-file-ignores]
9396
# manifest.py files are evaluated with some global names pre-defined
9497
"**/manifest.py" = ["F821"]
98+
"**/examples/*.py" = ["T20", "N806"]
99+
"tests/**/*.py" = ["T20"]
95100

96101
[tool.ruff.format]
97102
# Like Black, use double quotes for strings.

0 commit comments

Comments
 (0)