From f7c0ec65959723c7ec63fe9cce2add83c95268ed Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 12 Jun 2023 17:00:34 +1200 Subject: [PATCH] proto generation updates (#4653) --- .vscode/tasks.json | 18 ++++++++++++++++++ requirements_test.txt | 2 ++ script/api_protobuf/api_protobuf.py | 17 +++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 307dd496f0..acf1f29410 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -36,6 +36,24 @@ ] } ] + }, + { + "label": "Generate proto files", + "type": "shell", + "command": "${command:python.interpreterPath}", + "args": [ + "./script/api_protobuf/api_protobuf.py" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "never", + "close": true, + "panel": "new" + }, + "problemMatcher": [] } ] } diff --git a/requirements_test.txt b/requirements_test.txt index c099250bd7..d5235d733b 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -11,3 +11,5 @@ pytest-mock==3.10.0 pytest-asyncio==0.21.0 asyncmock==0.4.2 hypothesis==5.49.0 + +clang-format==13.0.1 ; platform_machine != 'armv7l' diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index dba6f47d43..5a0c92350d 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -18,6 +18,7 @@ will be generated, they still need to be formatted """ import re +import os from pathlib import Path from textwrap import dedent from subprocess import call @@ -944,3 +945,19 @@ with open(root / "api_pb2_service.cpp", "w") as f: f.write(cpp) prot.unlink() + +try: + import clang_format + + def exec_clang_format(path): + clang_format_path = os.path.join( + os.path.dirname(clang_format.__file__), "data", "bin", "clang-format" + ) + call([clang_format_path, "-i", path]) + + exec_clang_format(root / "api_pb2_service.h") + exec_clang_format(root / "api_pb2_service.cpp") + exec_clang_format(root / "api_pb2.h") + exec_clang_format(root / "api_pb2.cpp") +except ImportError: + pass