Skip to content

Commit d50d711

Browse files
committed
pyproject: format code with ruff
Upstream MicroPython switched from black to ruff, so we are following suit. This now includes all non-3rd-party .py files so quite a few files are reformatted that weren't being checked before.
1 parent 1e2c5a3 commit d50d711

27 files changed

+234
-222
lines changed

.github/build-each-commit.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@
5757

5858
# update only required submodules
5959
pybricks.git.submodule("update", "--init", "micropython")
60-
if args.hub in ["cityhub", "movehub", "technichub", "primehub", "essentialhub", "nxt", "ev3"]:
60+
if args.hub in [
61+
"cityhub",
62+
"movehub",
63+
"technichub",
64+
"primehub",
65+
"essentialhub",
66+
"nxt",
67+
"ev3",
68+
]:
6169
pybricks.submodule("micropython").module().git.submodule(
6270
"update", "--init", "lib/micropython-lib"
6371
)
@@ -66,7 +74,9 @@
6674
)
6775
if args.hub == "primehub" or args.hub == "essentialhub":
6876
pybricks.git.submodule("update", "--init", "--checkout", "lib/btstack")
69-
pybricks.git.submodule("update", "--init", "--checkout", "lib/STM32_USB_Device_Library")
77+
pybricks.git.submodule(
78+
"update", "--init", "--checkout", "lib/STM32_USB_Device_Library"
79+
)
7080

7181
# build the firmware
7282
subprocess.check_call(

.github/build-missing-commits.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
"update", "--init", "lib/stm32lib"
9898
)
9999
pybricks.git.submodule("update", "--init", "--checkout", "lib/btstack")
100-
pybricks.git.submodule("update", "--init", "--checkout", "lib/STM32_USB_Device_Library")
100+
pybricks.git.submodule(
101+
"update", "--init", "--checkout", "lib/STM32_USB_Device_Library"
102+
)
101103

102104
# Make mpy-cross once
103105
print("Building mpy-cross")

.github/download-commit-metadata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def main():
6565
)
6666
sizes = {
6767
item["RowKey"]: {
68-
k: v.value if isinstance(v, EntityProperty) else v for k, v in item.items() if k in HUBS
68+
k: v.value if isinstance(v, EntityProperty) else v
69+
for k, v in item.items()
70+
if k in HUBS
6971
}
7072
for item in firmware_size_table.query_entities(
7173
"PartitionKey eq 'size'",

bricks/ev3/make_bootable_image.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
def make_firmware(uboot_blob: bytes, uimage_blob: bytes) -> bytes:
26-
2726
if len(uboot_blob) > UBOOT_MAX_SIZE:
2827
print(
2928
f"u-boot file is bigger than 256KiB ({len(uboot_blob)} bytes), it is not safe to use.",
@@ -32,13 +31,18 @@ def make_firmware(uboot_blob: bytes, uimage_blob: bytes) -> bytes:
3231
exit(1)
3332

3433
if len(uimage_blob) > UIMAGE_MAX_SIZE:
35-
print(f"uImage file is too big ({len(uimage_blob)} > {UIMAGE_MAX_SIZE}).", file=sys.stderr)
34+
print(
35+
f"uImage file is too big ({len(uimage_blob)} > {UIMAGE_MAX_SIZE}).",
36+
file=sys.stderr,
37+
)
3638
exit(1)
3739

3840
# Gets combined size, rounded to nearest expected size.
3941
combined_size = UIMAGE_OFFSET + len(uimage_blob)
4042
combined_size = (
41-
(combined_size + FIRMWARE_ROUND_SIZE) // FIRMWARE_ROUND_SIZE * FIRMWARE_ROUND_SIZE
43+
(combined_size + FIRMWARE_ROUND_SIZE)
44+
// FIRMWARE_ROUND_SIZE
45+
* FIRMWARE_ROUND_SIZE
4246
)
4347

4448
# Put it all together.
@@ -59,9 +63,11 @@ def make_firmware(uboot_blob: bytes, uimage_blob: bytes) -> bytes:
5963
parser.add_argument("output", help="The output file")
6064
args = parser.parse_args()
6165

62-
with open(args.uboot, "rb") as uboot_file, open(args.uimage, "rb") as uimage_file, open(
63-
args.output, "wb"
64-
) as output_file:
66+
with (
67+
open(args.uboot, "rb") as uboot_file,
68+
open(args.uimage, "rb") as uimage_file,
69+
open(args.output, "wb") as output_file,
70+
):
6571
combined = make_firmware(uboot_file.read(), uimage_file.read())
6672
output_file.write(combined)
6773
print(f"Created {args.output} with size {len(combined) // 1024} KB.")

bricks/primehub/modules/_imu_calibrate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ def wait_for_stationary(side):
3636

3737

3838
def roll_over_axis(axis, new_side):
39-
4039
global bias, bias_count
4140

4241
print("Roll it towards you, without lifting the hub up!")
4342

4443
angle_start = hub.imu.rotation(axis, calibrated=False)
4544
while hub.imu.up(calibrated=False) != new_side or not hub.imu.stationary():
46-
4745
_, _, z = hub.imu.orientation() * axis
4846
if abs(z) > 0.07:
4947
print(hub.imu.orientation() * axis)
5048
raise RuntimeError("Lifted it!")
5149
wait(100)
5250

53-
uncalibrated_90_deg_rotation = abs(hub.imu.rotation(axis, calibrated=False) - angle_start)
51+
uncalibrated_90_deg_rotation = abs(
52+
hub.imu.rotation(axis, calibrated=False) - angle_start
53+
)
5454
if abs(uncalibrated_90_deg_rotation - 90) > 10:
5555
raise RuntimeError("Not 90 deg!")
5656

lib/pbio/doc/control/motor_model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def make_model(name, *, V, tau_0, tau_x, w_0, w_x, i_0, i_x, a, Lm, h):
151151
model[L] = Lm
152152

153153
# Substitute parameters into model to get numeric system matrices
154-
exponent_numeric = numpy.array(exponent.subs(model).evalf().tolist()).astype(numpy.float64)
154+
exponent_numeric = numpy.array(exponent.subs(model).evalf().tolist()).astype(
155+
numpy.float64
156+
)
155157

156158
# Get matrix exponential and system matrices
157159
exponential = scipy.linalg.expm(exponent_numeric * h)
@@ -196,7 +198,6 @@ def make_model(name, *, V, tau_0, tau_x, w_0, w_x, i_0, i_x, a, Lm, h):
196198

197199

198200
if __name__ == "__main__":
199-
200201
print(HEADER)
201202

202203
print(

lib/pbio/test/animator/data_parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@
3737

3838
# Write the CSS component with frames.
3939
with open("../results/frames.css", "w") as frame_file:
40-
4140
for info in FRAME_INFO:
42-
4341
# CSS rows for each frame.
4442
frames = "".join(
4543
[
46-
f"{i * 100 // (len(angles) - 1)}% {{transform: translate({info.x}px, {info.y}px) rotate( {int(row[info.index])// info.gearing}deg );}}\n"
44+
f"{i * 100 // (len(angles) - 1)}% {{transform: translate({info.x}px, {info.y}px) rotate( {int(row[info.index]) // info.gearing}deg );}}\n"
4745
for i, row in enumerate(angles)
4846
]
4947
)

poetry.lock

Lines changed: 32 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ pygithub = "^1.58.1"
3434

3535
[tool.poetry.group.lint.dependencies]
3636
micropython-uncrustify = "^1.0.0.post1"
37-
black = "^22.3.0"
37+
ruff = "^0.12.1"
38+
39+
[tool.ruff]
40+
extend-exclude = ["lib/btstack/", "micropython/"]
3841

3942
[build-system]
4043
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)