From fc506e7b3980b91c97a9eade7c2dadbf8c53e150 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 6 Aug 2023 14:29:28 -0700 Subject: [PATCH] switch to ruff linter (#1564) * switch to ruff linter * cleanup --- .pre-commit-config.yaml | 52 ++++++++++++------------------------- README.md | 2 +- examples/tesla_tester.py | 4 +-- pyproject.toml | 6 +++++ requirements.txt | 3 +-- tests/elm_car_simulator.py | 7 ++--- tests/safety/common.py | 4 +-- tests/safety/test_subaru.py | 2 +- 8 files changed, 34 insertions(+), 46 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b040d11..183e7746 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 1b325d80..3c8760b4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/tesla_tester.py b/examples/tesla_tester.py index c849b637..966e39d1 100644 --- a/examples/tesla_tester.py +++ b/examples/tesla_tester.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..0a5a4e5c --- /dev/null +++ b/pyproject.toml @@ -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" diff --git a/requirements.txt b/requirements.txt index 274170fd..6693a0af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tests/elm_car_simulator.py b/tests/elm_car_simulator.py index 8c8360a1..9d745a79 100755 --- a/tests/elm_car_simulator.py +++ b/tests/elm_car_simulator.py @@ -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() diff --git a/tests/safety/common.py b/tests/safety/common.py index f926e409..afce6c18 100644 --- a/tests/safety/common.py +++ b/tests/safety/common.py @@ -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) diff --git a/tests/safety/test_subaru.py b/tests/safety/test_subaru.py index a1e9e9a9..17cfc511 100755 --- a/tests/safety/test_subaru.py +++ b/tests/safety/test_subaru.py @@ -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],