From 6be38b2e9e508b2e6696304ee113035a60bf8dc7 Mon Sep 17 00:00:00 2001 From: Niklas Jensen Date: Sat, 3 Jan 2026 19:51:23 +0100 Subject: [PATCH] Protobuf python installation - automatic --- esp32/scripts/compile_protos.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/esp32/scripts/compile_protos.py b/esp32/scripts/compile_protos.py index c0fce1f..6c616d3 100644 --- a/esp32/scripts/compile_protos.py +++ b/esp32/scripts/compile_protos.py @@ -4,6 +4,24 @@ import os import sys from pathlib import Path +def ensure_protobuf_installed(): + """Ensure protobuf package is installed in the current Python environment.""" + try: + import google.protobuf + return True + except ImportError: + print("Installing required protobuf dependencies...") + result = subprocess.run( + [sys.executable, "-m", "pip", "install", "protobuf", "grpcio-tools"], + capture_output=True, + text=True + ) + if result.returncode != 0: + print(f"Failed to install protobuf: {result.stderr}") + return False + print("Protobuf dependencies installed successfully") + return True + def get_project_root(): script_dir = Path(__file__).parent.absolute() return script_dir.parent.parent @@ -42,6 +60,10 @@ def compile_nanopb(): return True def main(): + if not ensure_protobuf_installed(): + print("Error: Failed to install protobuf dependencies") + sys.exit(1) + if not compile_nanopb(): sys.exit(1) print("Proto compilation complete!")