switch to ruff linter (#1564)

* switch to ruff linter

* cleanup
This commit is contained in:
Adeeb Shihadeh
2023-08-06 14:29:28 -07:00
committed by GitHub
parent 33a95d6bea
commit fc506e7b39
8 changed files with 34 additions and 46 deletions

View File

@@ -1,36 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-yaml
- id: check-merge-conflict
- id: check-symlinks
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args:
- --select=F,E112,E113,E304,E501,E502,E701,E702,E703,E71,E72,E731,W191,W6
- --exclude=tests/gmbitbang/*
- --max-line-length=160
- --statistics
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
- -rn
- -sn
- -j0
- --disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,W0719,W1203,W1514,E1136
- --generated-members="usb1.*"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-yaml
- id: check-merge-conflict
- id: check-symlinks
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.282
hooks:
- id: ruff

View File

@@ -112,7 +112,7 @@ to ensure that the behavior remains unchanged.
* compiling the code and flashing it through USB.
* receiving, sending, and forwarding CAN messages on all buses, over USB.
In addition, we run the [pylint](https://www.pylint.org/) and [flake8](https://github.com/PyCQA/flake8) linters on all python files within the panda repo.
In addition, we run the [ruff linter](https://github.com/astral-sh/ruff) on all python files within the panda repo.
## Hardware

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# flake8: noqa
import binascii
from panda import Panda
@@ -16,7 +15,8 @@ def tesla_tester():
print("Setting Panda to output mode...")
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
# BDY 0x248 is the MCU_commands message, which includes folding mirrors, opening the trunk, frunk, setting the cars lock state and more. For our test, we will edit the 3rd byte, which is MCU_lockRequest. 0x01 will lock, 0x02 will unlock:
# BDY 0x248 is the MCU_commands message, which includes folding mirrors, opening the trunk, frunk, setting the cars lock state and more.
# For our test, we will edit the 3rd byte, which is MCU_lockRequest. 0x01 will lock, 0x02 will unlock:
print("Unlocking Tesla...")
p.can_send(0x248, b"\x00\x00\x02\x00\x00\x00\x00\x00", body_bus_num)

6
pyproject.toml Normal file
View File

@@ -0,0 +1,6 @@
# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
[tool.ruff]
select = ["E", "F", "W"]
ignore = ["W292", "E741"]
line-length = 160
target-version="py311"

View File

@@ -1,3 +1,4 @@
ruff
libusb1==2.0.1
numpy
hexdump>=3.3
@@ -7,11 +8,9 @@ pytest
pytest-timeouts
parameterized
requests
flake8==3.7.9
cffi==1.14.3
crcmod
pre-commit==2.13.0
pylint==2.15.4
scons==4.4.0
flaky
spidev

View File

@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# flake8: noqa
"""Used to Reverse/Test ELM protocol auto detect and OBD message response without a car."""
@@ -100,8 +99,10 @@ class ELMCarSimulator():
print("Invalid bytes at start of message")
print(" BUFF", lin_buff)
continue
if len(lin_buff) < msglen + 4: continue
if lin_checksum(lin_buff[:-1]) != lin_buff[-1]: continue
if len(lin_buff) < msglen + 4:
continue
if lin_checksum(lin_buff[:-1]) != lin_buff[-1]:
continue
self.__lin_process_msg(lin_buff[0] & 0xF8, # Priority
lin_buff[1], lin_buff[2], lin_buff[3:-1])
lin_buff = bytearray()

View File

@@ -553,7 +553,7 @@ class MeasurementSafetyTest(PandaSafetyTestBase):
@abc.abstractmethod
def _speed_msg(self, speed):
pass
def common_measurement_test(self, msg_func, min_value, max_value, factor, get_min_func, get_max_func):
for val in np.arange(min_value, max_value, 0.5):
for i in range(6):
@@ -571,7 +571,7 @@ class MeasurementSafetyTest(PandaSafetyTestBase):
def test_vehicle_speed_measurements(self):
self.common_measurement_test(self._speed_msg, 0, 80, VEHICLE_SPEED_FACTOR, self.safety.get_vehicle_speed_min, self.safety.get_vehicle_speed_max)
def test_steering_angle_measurements(self):
self.common_measurement_test(self._angle_meas_msg, -180, 180, self.DEG_TO_CAN, self.safety.get_angle_meas_min, self.safety.get_angle_meas_max)

View File

@@ -25,7 +25,7 @@ SUBARU_CAM_BUS = 2
def lkas_tx_msgs(alt_bus):
return [[MSG_SUBARU_ES_LKAS, SUBARU_MAIN_BUS],
return [[MSG_SUBARU_ES_LKAS, SUBARU_MAIN_BUS],
[MSG_SUBARU_ES_Distance, alt_bus],
[MSG_SUBARU_ES_DashStatus, SUBARU_MAIN_BUS],
[MSG_SUBARU_ES_LKAS_State, SUBARU_MAIN_BUS],