Skip to content

Commit 99806b5

Browse files
committed
all: Lint Python code with ruff.
Signed-off-by: Christian Clauss <cclauss@me.com>
1 parent c113611 commit 99806b5

File tree

18 files changed

+128
-44
lines changed

18 files changed

+128
-44
lines changed

.github/workflows/build_packages.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v1
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with: {python-version: 3.x}
1415
- name: Setup environment
1516
run: source tools/ci.sh && ci_build_packages_setup
1617
- name: Check manifest files

.github/workflows/cleanup_published_packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ jobs:
77
runs-on: ubuntu-latest
88
if: vars.MICROPY_PUBLISH_MIP_INDEX
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v3
1111
- name: Clean up published files
1212
run: source tools/ci.sh && ci_cleanup_package_index ${{ github.event.ref }}

.github/workflows/code_formatting.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- uses: actions/setup-python@v1
9+
- uses: actions/checkout@v3
10+
- run: pip install --user ruff
11+
- run: ruff .
12+
- uses: actions/setup-python@v4
13+
with: {python-version: 3.x}
1114
- name: Install packages
1215
run: source tools/ci.sh && ci_code_formatting_setup
1316
- name: Run code formatting

micropython/drivers/codec/wm8960/wm8960.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def set_data_route(self, route):
578578
raise ValueError("Invalid route")
579579

580580
def set_left_input(self, input):
581-
if not input in self._input_config_table.keys():
581+
if input not in self._input_config_table:
582582
raise ValueError("Invalid input")
583583

584584
input = self._input_config_table[input]
@@ -595,7 +595,7 @@ def set_left_input(self, input):
595595
regs[_LINVOL] = input[1]
596596

597597
def set_right_input(self, input):
598-
if not input in self._input_config_table.keys():
598+
if input not in self._input_config_table:
599599
raise ValueError("Invalid input name")
600600

601601
input = self._input_config_table[input]
@@ -629,7 +629,7 @@ def config_data_format(self, sysclk, sample_rate, bits):
629629
self.regs[_IFACE1] = (_IFACE1_WL_MASK, wl << _IFACE1_WL_SHIFT)
630630

631631
def volume(self, module, volume_l=None, volume_r=None):
632-
if not module in self._volume_config_table.keys():
632+
if module not in self._volume_config_table:
633633
raise ValueError("Invalid module")
634634

635635
if volume_l is None: # get volume
@@ -644,7 +644,7 @@ def volume(self, module, volume_l=None, volume_r=None):
644644

645645
if not ((0 <= volume_l <= 100) and (0 <= volume_r <= 100)):
646646
raise ValueError("Invalid value for volume")
647-
elif not module in self._volume_config_table.keys():
647+
elif module not in self._volume_config_table:
648648
raise ValueError("Invalid module")
649649

650650
vol_max, regnum, flags = self._volume_config_table[module]

micropython/drivers/imu/bmi270/bmi270.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ def __init__(
524524
# Sanity checks
525525
if not self._use_i2c:
526526
raise ValueError("SPI mode is not supported")
527-
if not gyro_odr in ODR:
527+
if gyro_odr not in ODR:
528528
raise ValueError("Invalid gyro sampling rate: %d" % gyro_odr)
529-
if not gyro_scale in GYRO_SCALE:
529+
if gyro_scale not in GYRO_SCALE:
530530
raise ValueError("Invalid gyro scaling: %d" % gyro_scale)
531-
if not accel_odr in ODR:
531+
if accel_odr not in ODR:
532532
raise ValueError("Invalid accelerometer sampling rate: %d" % accel_odr)
533-
if not accel_scale in ACCEL_SCALE:
533+
if accel_scale not in ACCEL_SCALE:
534534
raise ValueError("Invalid accelerometer scaling: %d" % accel_scale)
535535
if self._read_reg(_CHIP_ID) != 0x24:
536536
raise OSError("No BMI270 device was found at address 0x%x" % (self.address))

micropython/drivers/imu/bmm150/bmm150.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(
8080
# Sanity checks
8181
if not self._use_i2c:
8282
raise ValueError("SPI mode is not supported")
83-
if not magnet_odr in _ODR:
83+
if magnet_odr not in _ODR:
8484
raise ValueError("Invalid sampling rate: %d" % magnet_odr)
8585

8686
# Perform soft reset, and power on.

micropython/drivers/imu/lsm6dsox/lsm6dsox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ def __init__(
130130
accel_odr = round(accel_odr, 2)
131131

132132
# Sanity checks
133-
if not gyro_odr in ODR:
133+
if gyro_odr not in ODR:
134134
raise ValueError("Invalid sampling rate: %d" % gyro_odr)
135-
if not gyro_scale in SCALE_GYRO:
135+
if gyro_scale not in SCALE_GYRO:
136136
raise ValueError("invalid gyro scaling: %d" % gyro_scale)
137-
if not accel_odr in ODR:
137+
if accel_odr not in ODR:
138138
raise ValueError("Invalid sampling rate: %d" % accel_odr)
139-
if not accel_scale in SCALE_ACCEL:
139+
if accel_scale not in SCALE_ACCEL:
140140
raise ValueError("invalid accelerometer scaling: %d" % accel_scale)
141141

142142
# Soft-reset the device.
143143
self.reset()
144144

145145
# Load and configure MLC if UCF file is provided
146-
if ucf != None:
146+
if ucf is not None:
147147
self.load_mlc(ucf)
148148

149149
# Set Gyroscope datarate and scale.

micropython/drivers/imu/lsm6dsox/lsm6dsox_mlc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def imu_int_handler(pin):
1717
INT_FLAG = True
1818

1919

20-
if INT_MODE == True:
20+
if INT_MODE is True:
2121
int_pin = Pin(24)
2222
int_pin.irq(handler=imu_int_handler, trigger=Pin.IRQ_RISING)
2323

@@ -44,5 +44,5 @@ def imu_int_handler(pin):
4444
print(UCF_LABELS[lsm.mlc_output()[0]])
4545
else:
4646
buf = lsm.mlc_output()
47-
if buf != None:
47+
if buf is not None:
4848
print(UCF_LABELS[buf[0]])

micropython/drivers/imu/lsm9ds1/lsm9ds1.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ def __init__(
9595
self.address_magnet = address_magnet
9696

9797
# Sanity checks
98-
if not gyro_odr in _ODR_IMU:
98+
if gyro_odr not in _ODR_IMU:
9999
raise ValueError("Invalid gyro sampling rate: %d" % gyro_odr)
100-
if not gyro_scale in _GYRO_SCALE:
100+
if gyro_scale not in _GYRO_SCALE:
101101
raise ValueError("Invalid gyro scaling: %d" % gyro_scale)
102102

103-
if not accel_odr in _ODR_IMU:
103+
if accel_odr not in _ODR_IMU:
104104
raise ValueError("Invalid accelerometer sampling rate: %d" % accel_odr)
105-
if not accel_scale in _ACCEL_SCALE:
105+
if accel_scale not in _ACCEL_SCALE:
106106
raise ValueError("Invalid accelerometer scaling: %d" % accel_scale)
107107

108-
if not magnet_odr in _ODR_MAGNET:
108+
if magnet_odr not in _ODR_MAGNET:
109109
raise ValueError("Invalid magnet sampling rate: %d" % magnet_odr)
110-
if not magnet_scale in _MAGNET_SCALE:
110+
if magnet_scale not in _MAGNET_SCALE:
111111
raise ValueError("Invalid magnet scaling: %d" % magnet_scale)
112112

113113
if (self.magent_id() != b"=") or (self.gyro_id() != b"h"):

micropython/mip/mip/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,8 @@ def _install_json(package_json_url, index, target, version, mpy):
123123

124124

125125
def _install_package(package, index, target, version, mpy):
126-
if (
127-
package.startswith("http://")
128-
or package.startswith("https://")
129-
or package.startswith("github:")
130-
):
131-
if package.endswith(".py") or package.endswith(".mpy"):
126+
if package.startswith(("http://", "https://", "github:")):
127+
if package.endswith((".py", ".mpy")):
132128
print("Downloading {} to {}".format(package, target))
133129
return _download_file(
134130
_rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]

0 commit comments

Comments
 (0)