Ruff: propgate config from OP (#1579)

This commit is contained in:
Justin Newberry
2023-08-14 12:52:02 -07:00
committed by GitHub
parent 05295dc42a
commit 4ea50fbb09
22 changed files with 30 additions and 60 deletions

View File

@@ -17,7 +17,7 @@ if __name__ == "__main__":
if os.getenv("SERIAL"): if os.getenv("SERIAL"):
serials = [x for x in serials if x==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): if not len(panda_jungles):
sys.exit("no panda jungles found") sys.exit("no panda jungles found")

View File

@@ -1,6 +1,7 @@
# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
[tool.ruff] [tool.ruff]
select = ["E", "F", "W", "B"] select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"]
ignore = ["W292", "E741"] ignore = ["W292", "E741", "E402", "C408", "ISC003"]
line-length = 160 line-length = 160
target-version="py311" target-version="py311"
flake8-implicit-str-concat.allow-multiline=false

View File

@@ -409,7 +409,7 @@ class Panda:
return usb_handle, usb_serial, bootstub, bcd return usb_handle, usb_serial, bootstub, bcd
@classmethod @classmethod
def list(cls): def list(cls): # noqa: A003
ret = cls.usb_list() ret = cls.usb_list()
ret += cls.spi_list() ret += cls.spi_list()
return list(set(ret)) return list(set(ret))

View File

@@ -59,7 +59,7 @@ class PandaDFU:
return handle return handle
@staticmethod @staticmethod
def list() -> List[str]: def list() -> List[str]: # noqa: A003
ret = PandaDFU.usb_list() ret = PandaDFU.usb_list()
ret += PandaDFU.spi_list() ret += PandaDFU.spi_list()
return list(set(ret)) return list(set(ret))

View File

@@ -8,7 +8,7 @@ class PandaSerial(object):
self.panda.set_uart_baud(self.port, baud) self.panda.set_uart_baud(self.port, baud)
self.buf = b"" self.buf = b""
def read(self, l=1): # noqa: E741 def read(self, l=1):
tt = self.panda.serial_read(self.port) tt = self.panda.serial_read(self.port)
if len(tt) > 0: if len(tt) > 0:
self.buf += tt self.buf += tt

View File

@@ -6,13 +6,10 @@
import os import os
import sys
import time import time
import random import random
import argparse import argparse
from panda import Panda
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)

View File

@@ -6,13 +6,11 @@
import os import os
import sys
import time import time
import random import random
import argparse import argparse
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)

View File

@@ -5,13 +5,11 @@
import os import os
import sys
import time import time
import random import random
import argparse import argparse
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)

View File

@@ -6,8 +6,7 @@ import time
import select import select
import codecs import codecs
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
setcolor = ["\033[1;32;40m", "\033[1;31;40m"] setcolor = ["\033[1;32;40m", "\033[1;31;40m"]
unsetcolor = "\033[00m" unsetcolor = "\033[00m"
@@ -24,7 +23,7 @@ if __name__ == "__main__":
if os.getenv("SERIAL"): if os.getenv("SERIAL"):
serials = [x for x in serials if x == 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] decoders = [codecs.getincrementaldecoder('utf-8')() for _ in pandas]
if not len(pandas): if not len(pandas):

View File

@@ -1,9 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os from panda import Panda
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
from panda import Panda # noqa: E402
# This script is intended to be used in conjunction with the echo_loopback_test.py test script from panda jungle. # 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". # It sends a reversed response back for every message received containing b"test".

View File

@@ -2,16 +2,15 @@
"""Used to Reverse/Test ELM protocol auto detect and OBD message response without a car.""" """Used to Reverse/Test ELM protocol auto detect and OBD message response without a car."""
import sys
import os import os
import sys
import struct import struct
import binascii import binascii
import time import time
import threading import threading
from collections import deque from collections import deque
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def lin_checksum(dat): def lin_checksum(dat):
return sum(dat) % 0x100 return sum(dat) % 0x100

View File

@@ -1,11 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import sys
import time import time
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
WHITE_GMLAN_BUS = 3 WHITE_GMLAN_BUS = 3
OTHER_GMLAN_BUS = 1 OTHER_GMLAN_BUS = 1

View File

@@ -58,7 +58,7 @@ def init_all_pandas():
print(f"{len(_all_pandas)} total pandas") print(f"{len(_all_pandas)} total pandas")
init_all_pandas() init_all_pandas()
_all_panda_serials = list(sorted(_all_pandas.keys())) _all_panda_serials = sorted(_all_pandas.keys())
def init_jungle(): def init_jungle():

View File

@@ -1,10 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import sys
import time import time
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
power = 0 power = 0
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -72,10 +72,10 @@ class PandaSafety(Protocol):
def get_current_safety_mode(self) -> int: ... def get_current_safety_mode(self) -> int: ...
def get_current_safety_param(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_min(self) -> int: ...
def get_torque_meas_max(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_min(self) -> int: ...
def get_torque_driver_max(self) -> int: ... def get_torque_driver_max(self) -> int: ...
def set_desired_torque_last(self, t: int) -> None: ... def set_desired_torque_last(self, t: int) -> None: ...

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
import time import time
import random import random
import argparse import argparse
@@ -9,8 +8,7 @@ import argparse
from hexdump import hexdump from hexdump import hexdump
from itertools import permutations from itertools import permutations
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)
@@ -25,7 +23,7 @@ def run_test(sleep_duration):
run_test_w_pandas(pandas, sleep_duration) run_test_w_pandas(pandas, sleep_duration)
def 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) print("H", h)
for hh in h: for hh in h:

View File

@@ -16,7 +16,7 @@ if JUNGLE:
# Generate unique messages # Generate unique messages
NUM_MESSAGES_PER_BUS = 10000 NUM_MESSAGES_PER_BUS = 10000
messages = [bytes(struct.pack("Q", i)) for i in range(NUM_MESSAGES_PER_BUS)] 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): def flood_tx(panda):
print('Sending!') print('Sending!')
@@ -65,6 +65,6 @@ if __name__ == "__main__":
# Check if we received everything # Check if we received everything
for bus in range(3): 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) dropped_msgs = set(messages).difference(received_msgs)
print(f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}") print(f"Bus {bus} dropped msgs: {len(list(dropped_msgs))} / {len(messages)}")

View File

@@ -1,10 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys
import datetime import datetime
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
if __name__ == "__main__": if __name__ == "__main__":
p = Panda() p = Panda()

View File

@@ -987,7 +987,7 @@ class PandaSafetyTest(PandaSafetyTestBase):
if attr.startswith('TestHonda'): if attr.startswith('TestHonda'):
# exceptions for common msgs across different hondas # exceptions for common msgs across different hondas
tx = list(filter(lambda m: m[0] not in [0x1FA, 0x30C, 0x33D], tx)) 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 # make sure we got all the msgs
self.assertTrue(len(all_tx) >= len(test_files)-1) self.assertTrue(len(all_tx) >= len(test_files)-1)

View File

@@ -1,10 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
import random import random
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)

View File

@@ -1,11 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import sys
import struct import struct
import time import time
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
if __name__ == "__main__": if __name__ == "__main__":
p = Panda() p = Panda()

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
import time import time
import random import random
import argparse import argparse
@@ -9,8 +8,7 @@ import argparse
from hexdump import hexdump from hexdump import hexdump
from itertools import permutations from itertools import permutations
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) from panda import Panda
from panda import Panda # noqa: E402
def get_test_string(): def get_test_string():
return b"test" + os.urandom(10) return b"test" + os.urandom(10)
@@ -25,7 +23,7 @@ def run_test(sleep_duration):
run_test_w_pandas(pandas, sleep_duration) run_test_w_pandas(pandas, sleep_duration)
def 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) print("H", h)
for hh in h: for hh in h: