Skip to content

Commit

Permalink
proto generation updates (esphome#4653)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Jun 12, 2023
1 parent 0a407c5 commit f7c0ec6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
]
}
2 changes: 2 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
17 changes: 17 additions & 0 deletions script/api_protobuf/api_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

import re
import os
from pathlib import Path
from textwrap import dedent
from subprocess import call
Expand Down Expand Up @@ -944,3 +945,19 @@ def build_service_message_type(mt):
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

0 comments on commit f7c0ec6

Please sign in to comment.