From 4ea50fbb09c75c7ee45a268ac400737f2e5bfb5f Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Mon, 14 Aug 2023 12:52:02 -0700 Subject: [PATCH] Ruff: propgate config from OP (#1579) --- board/jungle/scripts/debug_console.py | 2 +- pyproject.toml | 5 +++-- python/__init__.py | 2 +- python/dfu.py | 2 +- python/serial.py | 2 +- tests/black_white_loopback_test.py | 5 +---- tests/black_white_relay_endurance.py | 4 +--- tests/black_white_relay_test.py | 4 +--- tests/debug_console.py | 5 ++--- tests/echo.py | 6 +----- tests/elm_car_simulator.py | 5 ++--- tests/gmlan_harness_test.py | 5 +---- tests/hitl/conftest.py | 2 +- tests/ir_test.py | 5 +---- tests/libpanda/safety_helpers.py | 4 ++-- tests/loopback_test.py | 6 ++---- tests/message_drop_test.py | 4 ++-- tests/rtc_test.py | 5 +---- tests/safety/common.py | 2 +- tests/spam_can.py | 4 +--- tests/standalone_test.py | 5 +---- tests/tucan_loopback.py | 6 ++---- 22 files changed, 30 insertions(+), 60 deletions(-) diff --git a/board/jungle/scripts/debug_console.py b/board/jungle/scripts/debug_console.py index f8dd24ed2..f35388796 100755 --- a/board/jungle/scripts/debug_console.py +++ b/board/jungle/scripts/debug_console.py @@ -17,7 +17,7 @@ if __name__ == "__main__": if os.getenv("SERIAL"): serials = [x for x in serials if x==os.getenv("SERIAL")] - panda_jungles = list([PandaJungle(x, claim=claim) for x in serials]) + panda_jungles = [PandaJungle(x, claim=claim) for x in serials] if not len(panda_jungles): sys.exit("no panda jungles found") diff --git a/pyproject.toml b/pyproject.toml index 53f2b5aba..bac2d7f08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml [tool.ruff] -select = ["E", "F", "W", "B"] -ignore = ["W292", "E741"] +select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"] +ignore = ["W292", "E741", "E402", "C408", "ISC003"] line-length = 160 target-version="py311" +flake8-implicit-str-concat.allow-multiline=false diff --git a/python/__init__.py b/python/__init__.py index e1b3a471e..40066af46 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -409,7 +409,7 @@ class Panda: return usb_handle, usb_serial, bootstub, bcd @classmethod - def list(cls): + def list(cls): # noqa: A003 ret = cls.usb_list() ret += cls.spi_list() return list(set(ret)) diff --git a/python/dfu.py b/python/dfu.py index bebc243ce..39303d528 100644 --- a/python/dfu.py +++ b/python/dfu.py @@ -59,7 +59,7 @@ class PandaDFU: return handle @staticmethod - def list() -> List[str]: + def list() -> List[str]: # noqa: A003 ret = PandaDFU.usb_list() ret += PandaDFU.spi_list() return list(set(ret)) diff --git a/python/serial.py b/python/serial.py index 97fe8f1d9..9ac58862b 100644 --- a/python/serial.py +++ b/python/serial.py @@ -8,7 +8,7 @@ class PandaSerial(object): self.panda.set_uart_baud(self.port, baud) self.buf = b"" - def read(self, l=1): # noqa: E741 + def read(self, l=1): tt = self.panda.serial_read(self.port) if len(tt) > 0: self.buf += tt diff --git a/tests/black_white_loopback_test.py b/tests/black_white_loopback_test.py index 8914430a1..5b2312bef 100755 --- a/tests/black_white_loopback_test.py +++ b/tests/black_white_loopback_test.py @@ -6,13 +6,10 @@ import os -import sys import time import random import argparse - -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) diff --git a/tests/black_white_relay_endurance.py b/tests/black_white_relay_endurance.py index cfdaeb330..db19e7253 100755 --- a/tests/black_white_relay_endurance.py +++ b/tests/black_white_relay_endurance.py @@ -6,13 +6,11 @@ import os -import sys import time import random import argparse -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) diff --git a/tests/black_white_relay_test.py b/tests/black_white_relay_test.py index 4a3f58f7f..90b33be68 100755 --- a/tests/black_white_relay_test.py +++ b/tests/black_white_relay_test.py @@ -5,13 +5,11 @@ import os -import sys import time import random import argparse -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) diff --git a/tests/debug_console.py b/tests/debug_console.py index a74cd846e..8755be149 100755 --- a/tests/debug_console.py +++ b/tests/debug_console.py @@ -6,8 +6,7 @@ import time import select import codecs -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda setcolor = ["\033[1;32;40m", "\033[1;31;40m"] unsetcolor = "\033[00m" @@ -24,7 +23,7 @@ if __name__ == "__main__": if os.getenv("SERIAL"): serials = [x for x in serials if x == os.getenv("SERIAL")] - pandas = list([Panda(x, claim=claim) for x in serials]) + pandas = [Panda(x, claim=claim) for x in serials] decoders = [codecs.getincrementaldecoder('utf-8')() for _ in pandas] if not len(pandas): diff --git a/tests/echo.py b/tests/echo.py index e7cf3e5b3..90bf4a8c7 100755 --- a/tests/echo.py +++ b/tests/echo.py @@ -1,9 +1,5 @@ #!/usr/bin/env python3 -import os -import sys - -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda # This script is intended to be used in conjunction with the echo_loopback_test.py test script from panda jungle. # It sends a reversed response back for every message received containing b"test". diff --git a/tests/elm_car_simulator.py b/tests/elm_car_simulator.py index 9d745a79f..27afdbad4 100755 --- a/tests/elm_car_simulator.py +++ b/tests/elm_car_simulator.py @@ -2,16 +2,15 @@ """Used to Reverse/Test ELM protocol auto detect and OBD message response without a car.""" -import sys import os +import sys import struct import binascii import time import threading from collections import deque -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def lin_checksum(dat): return sum(dat) % 0x100 diff --git a/tests/gmlan_harness_test.py b/tests/gmlan_harness_test.py index f10f98fc3..950918cff 100755 --- a/tests/gmlan_harness_test.py +++ b/tests/gmlan_harness_test.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 -import os -import sys import time -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda WHITE_GMLAN_BUS = 3 OTHER_GMLAN_BUS = 1 diff --git a/tests/hitl/conftest.py b/tests/hitl/conftest.py index c337013f0..6deb2e0ee 100644 --- a/tests/hitl/conftest.py +++ b/tests/hitl/conftest.py @@ -58,7 +58,7 @@ def init_all_pandas(): print(f"{len(_all_pandas)} total pandas") init_all_pandas() -_all_panda_serials = list(sorted(_all_pandas.keys())) +_all_panda_serials = sorted(_all_pandas.keys()) def init_jungle(): diff --git a/tests/ir_test.py b/tests/ir_test.py index 8566f3771..e41decf25 100755 --- a/tests/ir_test.py +++ b/tests/ir_test.py @@ -1,10 +1,7 @@ #!/usr/bin/env python3 -import os -import sys import time -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda power = 0 if __name__ == "__main__": diff --git a/tests/libpanda/safety_helpers.py b/tests/libpanda/safety_helpers.py index 234b8ecd0..d10a82b00 100644 --- a/tests/libpanda/safety_helpers.py +++ b/tests/libpanda/safety_helpers.py @@ -72,10 +72,10 @@ class PandaSafety(Protocol): def get_current_safety_mode(self) -> int: ... def get_current_safety_param(self) -> int: ... - def set_torque_meas(self, min: int, max: int) -> None: ... # pylint: disable=redefined-builtin + def set_torque_meas(self, min: int, max: int) -> None: ... # noqa: A002 def get_torque_meas_min(self) -> int: ... def get_torque_meas_max(self) -> int: ... - def set_torque_driver(self, min: int, max: int) -> None: ... # pylint: disable=redefined-builtin + def set_torque_driver(self, min: int, max: int) -> None: ... # noqa: A002 def get_torque_driver_min(self) -> int: ... def get_torque_driver_max(self) -> int: ... def set_desired_torque_last(self, t: int) -> None: ... diff --git a/tests/loopback_test.py b/tests/loopback_test.py index 630c55215..73bb91be7 100755 --- a/tests/loopback_test.py +++ b/tests/loopback_test.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import os -import sys import time import random import argparse @@ -9,8 +8,7 @@ import argparse from hexdump import hexdump from itertools import permutations -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) @@ -25,7 +23,7 @@ def run_test(sleep_duration): run_test_w_pandas(pandas, sleep_duration) def run_test_w_pandas(pandas, sleep_duration): - h = list([Panda(x) for x in pandas]) + h = [Panda(x) for x in pandas] print("H", h) for hh in h: diff --git a/tests/message_drop_test.py b/tests/message_drop_test.py index ed4ea0deb..99d35b043 100755 --- a/tests/message_drop_test.py +++ b/tests/message_drop_test.py @@ -16,7 +16,7 @@ if JUNGLE: # Generate unique messages NUM_MESSAGES_PER_BUS = 10000 messages = [bytes(struct.pack("Q", i)) for i in range(NUM_MESSAGES_PER_BUS)] -tx_messages = list(itertools.chain.from_iterable(map(lambda msg: [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]], messages))) +tx_messages = list(itertools.chain.from_iterable(([[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] for msg in messages))) def flood_tx(panda): print('Sending!') @@ -65,6 +65,6 @@ if __name__ == "__main__": # Check if we received everything for bus in range(3): - received_msgs = set(map(lambda m: bytes(m[2]), filter(lambda m, b=bus: m[3] == b, rx))) # type: ignore + received_msgs = {bytes(m[2]) for m in filter(lambda m, b=bus: m[3] == b, rx)} # type: ignore dropped_msgs = set(messages).difference(received_msgs) print(f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}") diff --git a/tests/rtc_test.py b/tests/rtc_test.py index 24edf0976..01c9f4ddd 100755 --- a/tests/rtc_test.py +++ b/tests/rtc_test.py @@ -1,10 +1,7 @@ #!/usr/bin/env python -import os -import sys import datetime -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda if __name__ == "__main__": p = Panda() diff --git a/tests/safety/common.py b/tests/safety/common.py index 7724705cf..f4cc519fa 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -987,7 +987,7 @@ class PandaSafetyTest(PandaSafetyTestBase): if attr.startswith('TestHonda'): # exceptions for common msgs across different hondas tx = list(filter(lambda m: m[0] not in [0x1FA, 0x30C, 0x33D], tx)) - all_tx.append(list([m[0], m[1], attr] for m in tx)) + all_tx.append([m[0], m[1], attr] for m in tx) # make sure we got all the msgs self.assertTrue(len(all_tx) >= len(test_files)-1) diff --git a/tests/spam_can.py b/tests/spam_can.py index 8c80fb45c..3154cc046 100755 --- a/tests/spam_can.py +++ b/tests/spam_can.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 import os -import sys import random -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) diff --git a/tests/standalone_test.py b/tests/standalone_test.py index dfd2c9a7a..7ec555969 100755 --- a/tests/standalone_test.py +++ b/tests/standalone_test.py @@ -1,11 +1,8 @@ #!/usr/bin/env python3 -import os -import sys import struct import time -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda if __name__ == "__main__": p = Panda() diff --git a/tests/tucan_loopback.py b/tests/tucan_loopback.py index 0780ffee0..1bf1254a1 100755 --- a/tests/tucan_loopback.py +++ b/tests/tucan_loopback.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import os -import sys import time import random import argparse @@ -9,8 +8,7 @@ import argparse from hexdump import hexdump from itertools import permutations -sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) -from panda import Panda # noqa: E402 +from panda import Panda def get_test_string(): return b"test" + os.urandom(10) @@ -25,7 +23,7 @@ def run_test(sleep_duration): run_test_w_pandas(pandas, sleep_duration) def run_test_w_pandas(pandas, sleep_duration): - h = list([Panda(x) for x in pandas]) + h = [Panda(x) for x in pandas] print("H", h) for hh in h: