From 9b0adebec844bde7e8834c0f433b091b10030452 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 14 Aug 2024 20:29:14 -0700 Subject: [PATCH] docs: remove common import (#33310) * add opcar * fix references * actually better to split this so opendbc will test docs conventions, and openpilot will test diffing * not exe * clean up old-commit-hash: 424b657376d91d27fdc73d95862c1bbbe4de2b74 --- .github/PULL_REQUEST_TEMPLATE/car_port.md | 2 +- .github/pull_request_template.md | 2 +- .importlinter | 5 ----- pyproject.toml | 1 + selfdrive/car/docs.py | 21 ------------------ selfdrive/car/tests/test_docs.py | 19 +---------------- selfdrive/opcar/__init__.py | 1 + selfdrive/opcar/docs.py | 21 ++++++++++++++++++ selfdrive/opcar/tests/__init__.py | 0 selfdrive/opcar/tests/test_docs.py | 26 +++++++++++++++++++++++ 10 files changed, 52 insertions(+), 46 deletions(-) mode change 100755 => 100644 selfdrive/car/docs.py create mode 100644 selfdrive/opcar/__init__.py create mode 100755 selfdrive/opcar/docs.py create mode 100644 selfdrive/opcar/tests/__init__.py create mode 100644 selfdrive/opcar/tests/test_docs.py diff --git a/.github/PULL_REQUEST_TEMPLATE/car_port.md b/.github/PULL_REQUEST_TEMPLATE/car_port.md index c7aa2b96c2..c1581d2055 100644 --- a/.github/PULL_REQUEST_TEMPLATE/car_port.md +++ b/.github/PULL_REQUEST_TEMPLATE/car_port.md @@ -8,7 +8,7 @@ assignees: '' **Checklist** -- [ ] added entry to CAR in selfdrive/car/*/values.py and ran `selfdrive/car/docs.py` to generate new docs +- [ ] added entry to CAR in selfdrive/car/*/values.py and ran `selfdrive/opcar/docs.py` to generate new docs - [ ] test route added to [routes.py](https://github.com/commaai/openpilot/blob/master/selfdrive/car/tests/routes.py) - [ ] route with openpilot: - [ ] route with stock system: diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2b4a5ed48f..9e0c54218e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -44,7 +44,7 @@ Explain how you tested this bug fix. **Checklist** -- [ ] added entry to CAR in selfdrive/car/*/values.py and ran `selfdrive/car/docs.py` to generate new docs +- [ ] added entry to CAR in selfdrive/car/*/values.py and ran `selfdrive/opcar/docs.py` to generate new docs - [ ] test route added to [routes.py](https://github.com/commaai/openpilot/blob/master/selfdrive/car/tests/routes.py) - [ ] route with openpilot: - [ ] route with stock system: diff --git a/.importlinter b/.importlinter index eb2c5c971a..75f4b11d4d 100644 --- a/.importlinter +++ b/.importlinter @@ -25,9 +25,6 @@ forbidden_modules = openpilot.tinygrad ignore_imports = # remove these - openpilot.selfdrive.car.tests.test_docs -> openpilot.common.basedir - openpilot.selfdrive.car.docs -> openpilot.common.basedir - openpilot.selfdrive.car.gm.interface -> openpilot.common.basedir openpilot.selfdrive.car.interfaces -> openpilot.common.basedir @@ -48,8 +45,6 @@ ignore_imports = openpilot.selfdrive.car.tests.test_models -> openpilot.common.params openpilot.selfdrive.car.tests.test_models -> openpilot.common.basedir openpilot.selfdrive.car.card -> openpilot.selfdrive.pandad - openpilot.selfdrive.car.tests.test_docs -> openpilot.selfdrive.debug.dump_car_docs - openpilot.selfdrive.car.tests.test_docs -> openpilot.selfdrive.debug.print_docs_diff openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.pandad openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.pandad openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.test.fuzzy_generation diff --git a/pyproject.toml b/pyproject.toml index 0606317089..884c305ab3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -145,6 +145,7 @@ testpaths = [ "common", "selfdrive/pandad", "selfdrive/car", + "selfdrive/opcar", "selfdrive/controls", "selfdrive/locationd", "selfdrive/monitoring", diff --git a/selfdrive/car/docs.py b/selfdrive/car/docs.py old mode 100755 new mode 100644 index 7bf6a6ad22..17f8947522 --- a/selfdrive/car/docs.py +++ b/selfdrive/car/docs.py @@ -1,13 +1,9 @@ -#!/usr/bin/env python3 -import argparse from collections import defaultdict import jinja2 -import os from enum import Enum from natsort import natsorted from cereal import car -from openpilot.common.basedir import BASEDIR from openpilot.selfdrive.car import gen_empty_fingerprint from openpilot.selfdrive.car.docs_definitions import CarDocs, Column, CommonFootnote, PartType from openpilot.selfdrive.car.car_helpers import interfaces, get_interface_attr @@ -21,10 +17,6 @@ def get_all_footnotes() -> dict[Enum, int]: return {fn: idx + 1 for idx, fn in enumerate(all_footnotes)} -CARS_MD_OUT = os.path.join(BASEDIR, "docs", "CARS.md") -CARS_MD_TEMPLATE = os.path.join(BASEDIR, "selfdrive", "car", "CARS_template.md") - - def get_all_car_docs() -> list[CarDocs]: all_car_docs: list[CarDocs] = [] footnotes = get_all_footnotes() @@ -65,16 +57,3 @@ def generate_cars_md(all_car_docs: list[CarDocs], template_fn: str) -> str: group_by_make=group_by_make, footnotes=footnotes, Column=Column) return cars_md - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Auto generates supported cars documentation", - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - - parser.add_argument("--template", default=CARS_MD_TEMPLATE, help="Override default template filename") - parser.add_argument("--out", default=CARS_MD_OUT, help="Override default generated filename") - args = parser.parse_args() - - with open(args.out, 'w') as f: - f.write(generate_cars_md(get_all_car_docs(), args.template)) - print(f"Generated and written to {args.out}") diff --git a/selfdrive/car/tests/test_docs.py b/selfdrive/car/tests/test_docs.py index 40ad07b283..52d8976517 100644 --- a/selfdrive/car/tests/test_docs.py +++ b/selfdrive/car/tests/test_docs.py @@ -1,16 +1,12 @@ from collections import defaultdict -import os import pytest import re -from openpilot.common.basedir import BASEDIR from openpilot.selfdrive.car.car_helpers import interfaces -from openpilot.selfdrive.car.docs import CARS_MD_OUT, CARS_MD_TEMPLATE, generate_cars_md, get_all_car_docs +from openpilot.selfdrive.car.docs import get_all_car_docs from openpilot.selfdrive.car.docs_definitions import Cable, Column, PartType, Star from openpilot.selfdrive.car.honda.values import CAR as HONDA from openpilot.selfdrive.car.values import PLATFORMS -from openpilot.selfdrive.debug.dump_car_docs import dump_car_docs -from openpilot.selfdrive.debug.print_docs_diff import print_car_docs_diff class TestCarDocs: @@ -18,19 +14,6 @@ class TestCarDocs: def setup_class(cls): cls.all_cars = get_all_car_docs() - def test_generator(self): - generated_cars_md = generate_cars_md(self.all_cars, CARS_MD_TEMPLATE) - with open(CARS_MD_OUT) as f: - current_cars_md = f.read() - - assert generated_cars_md == current_cars_md, "Run selfdrive/car/docs.py to update the compatibility documentation" - - def test_docs_diff(self): - dump_path = os.path.join(BASEDIR, "selfdrive", "car", "tests", "cars_dump") - dump_car_docs(dump_path) - print_car_docs_diff(dump_path) - os.remove(dump_path) - def test_duplicate_years(self, subtests): make_model_years = defaultdict(list) for car in self.all_cars: diff --git a/selfdrive/opcar/__init__.py b/selfdrive/opcar/__init__.py new file mode 100644 index 0000000000..ddc217f21b --- /dev/null +++ b/selfdrive/opcar/__init__.py @@ -0,0 +1 @@ +# This folder will be renamed back to car after the opendbc car split diff --git a/selfdrive/opcar/docs.py b/selfdrive/opcar/docs.py new file mode 100755 index 0000000000..99bf0b055b --- /dev/null +++ b/selfdrive/opcar/docs.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import argparse +import os + +from openpilot.common.basedir import BASEDIR +from openpilot.selfdrive.car.docs import get_all_car_docs, generate_cars_md + +CARS_MD_OUT = os.path.join(BASEDIR, "docs", "CARS.md") +CARS_MD_TEMPLATE = os.path.join(BASEDIR, "selfdrive", "car", "CARS_template.md") + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Auto generates supported cars documentation", + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument("--template", default=CARS_MD_TEMPLATE, help="Override default template filename") + parser.add_argument("--out", default=CARS_MD_OUT, help="Override default generated filename") + args = parser.parse_args() + + with open(args.out, 'w') as f: + f.write(generate_cars_md(get_all_car_docs(), args.template)) + print(f"Generated and written to {args.out}") diff --git a/selfdrive/opcar/tests/__init__.py b/selfdrive/opcar/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/selfdrive/opcar/tests/test_docs.py b/selfdrive/opcar/tests/test_docs.py new file mode 100644 index 0000000000..f200bc292d --- /dev/null +++ b/selfdrive/opcar/tests/test_docs.py @@ -0,0 +1,26 @@ +import os + +from openpilot.common.basedir import BASEDIR +from openpilot.selfdrive.car.docs import generate_cars_md, get_all_car_docs +from openpilot.selfdrive.debug.dump_car_docs import dump_car_docs +from openpilot.selfdrive.debug.print_docs_diff import print_car_docs_diff +from openpilot.selfdrive.opcar.docs import CARS_MD_OUT, CARS_MD_TEMPLATE + + +class TestCarDocs: + @classmethod + def setup_class(cls): + cls.all_cars = get_all_car_docs() + + def test_generator(self): + generated_cars_md = generate_cars_md(self.all_cars, CARS_MD_TEMPLATE) + with open(CARS_MD_OUT) as f: + current_cars_md = f.read() + + assert generated_cars_md == current_cars_md, "Run selfdrive/opcar/docs.py to update the compatibility documentation" + + def test_docs_diff(self): + dump_path = os.path.join(BASEDIR, "selfdrive", "car", "tests", "cars_dump") + dump_car_docs(dump_path) + print_car_docs_diff(dump_path) + os.remove(dump_path)