From 132b1a66b03a9247f4c4c8fb0dfca35185c835e6 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 16 Aug 2024 22:24:44 -0700 Subject: [PATCH] Bump pre-commit hooks, more coverage (similar to openpilot) (#1078) * pytest defaults * move some stuff to pyproject * bump codespell * more like openpilot --- .pre-commit-config.yaml | 9 +++------ opendbc/can/tests/test_checksums.py | 2 +- opendbc/dbc/generator/generator.py | 4 ++-- pyproject.toml | 31 ++++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d0e67ec84..df68399b4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,19 +9,16 @@ repos: - id: check-executables-have-shebangs - id: check-shebang-scripts-are-executable - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell exclude: '\.dbc$' - args: - - --check-hidden - - --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.9.0 + rev: v1.11.1 hooks: - id: mypy - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.2 + rev: v0.5.7 hooks: - id: ruff - repo: https://github.com/MarcoGorelli/cython-lint diff --git a/opendbc/can/tests/test_checksums.py b/opendbc/can/tests/test_checksums.py index c347f3a68b..e584ba30a5 100644 --- a/opendbc/can/tests/test_checksums.py +++ b/opendbc/can/tests/test_checksums.py @@ -22,7 +22,7 @@ def test_honda_checksum(self): checksum_std = [11, 10, 9, 8] checksum_ext = [4, 3, 2, 1] - for std, ext in zip(checksum_std, checksum_ext): + for std, ext in zip(checksum_std, checksum_ext, strict=True): msgs = [ packer.make_can_msg("LKAS_HUD", 0, values), packer.make_can_msg("LKAS_HUD_A", 0, values), diff --git a/opendbc/dbc/generator/generator.py b/opendbc/dbc/generator/generator.py index 214c8fb1a5..d0f41fc80a 100755 --- a/opendbc/dbc/generator/generator.py +++ b/opendbc/dbc/generator/generator.py @@ -27,13 +27,13 @@ def create_dbc(src_dir: str, filename: str, output_path: str): dbc_file_out.write('CM_ "AUTOGENERATED FILE, DO NOT EDIT";\n') for include_filename in includes: - include_file_header = '\n\nCM_ "Imported file %s starts here";\n' % include_filename + include_file_header = f'\n\nCM_ "Imported file {include_filename} starts here";\n' dbc_file_out.write(include_file_header) include_file = read_dbc(src_dir, include_filename) dbc_file_out.write(include_file) - dbc_file_out.write('\nCM_ "%s starts here";\n' % filename) + dbc_file_out.write(f'\nCM_ "{filename} starts here";\n') core_dbc = include_pattern.sub('', dbc_file_in) dbc_file_out.write(core_dbc) diff --git a/pyproject.toml b/pyproject.toml index d9eab2a37c..8c6257cddc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,19 +9,48 @@ requires-python = ">=3.9" urls = { "homepage" = "https://github.com/commaai/opendbc" } +[tool.pytest.ini_options] +addopts = "-Werror --strict-config --strict-markers --durations=10 -n auto" +python_files = "test_*.py" +testpaths = [ + "opendbc" +] + +[tool.codespell] +quiet-level = 3 +builtin = "clear,rare,informal,code,names,en-GB_to_en-US" +check-hidden = true + [tool.cython-lint] max-line-length = 120 ignore = ["E111", "E114"] [tool.mypy] +# helpful warnings +warn_redundant_casts=true +warn_unreachable=true +warn_unused_ignores=true + +# restrict dynamic typing +warn_return_any=true + explicit_package_bases=true # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml [tool.ruff] line-length = 160 +indent-width = 2 target-version="py311" [tool.ruff.lint] -select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"] +select = [ + "E", "F", "W", "PIE", "C4", "ISC", "A", "B", + "NPY", # numpy + "UP", # pyupgrade + "TRY302", "TRY400", "TRY401", # try/excepts + "RUF008", "RUF100", + "TID251", + "PLR1704", +] ignore = ["W292", "E741", "E402", "C408", "ISC003"] flake8-implicit-str-concat.allow-multiline=false