-
Notifications
You must be signed in to change notification settings - Fork 15.8k
Open
Labels
Description
Opening here since this is apparently a bug in protobuf and not grpc. I'm trying to generate gRPC interfaces with a custom package prefix. However a subset of generated files have invalid imports.
What version of gRPC and what language are you using?
1.73.1 With python 3.13.5
What operating system (Linux, Windows,...) and version?
OSX 15.5
What runtime / compiler are you using (e.g. python version or version of gcc)
python 3.13.5
What did you do?
Run the following make file
# Makefile for updating BOS+ API proto files in pyasic
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
REPO_URL := https://github.com/braiins/bos-plus-api.git
TEMP_DIR := .tmp_bos_api
PROTO_SOURCE_DIR := $(TEMP_DIR)/proto
TARGET_BASE := pyasic/web/braiins_os/proto
# Python module for protoc
PROTOC := python -m grpc_tools.protoc
.PHONY: bos-plus-api clean
bos-plus-api:
@echo "=== Updating BOS+ API proto files ==="
@echo "1. Removing old proto directory …"
@rm -rf $(TARGET_BASE)
@echo "2. Cloning BOS+ API repository …"
@rm -rf $(TEMP_DIR)
@git clone --quiet $(REPO_URL) $(TEMP_DIR)
@echo "3. Creating target directory …"
@mkdir -p $(TARGET_BASE)
@echo "4. Generating proto files …"
@find $(PROTO_SOURCE_DIR) -name '*.proto' | while read proto; do \
echo "Processing $$proto"; \
$(PROTOC) \
--proto_path=$(TARGET_BASE)=$(PROTO_SOURCE_DIR) \
--proto_path=$(PROTO_SOURCE_DIR) \
--python_out=. \
--grpc_python_out=. \
--pyi_out=. \
$$proto; \
done
@echo "5. Creating __init__.py files …"
@find $(TARGET_BASE) -type d -exec touch {}/__init__.py \;
@echo "6. Cleaning up …"
@rm -rf $(TEMP_DIR)
@echo "✓ BOS+ API proto files updated successfully!"
@echo " Generated files: $$(find $(TARGET_BASE) -name '*_pb2.py' | wc -l) Python files"
@echo " Type stubs: $$(find $(TARGET_BASE) -name '*.pyi' | wc -l) stub files"
clean:
@rm -rf $(TARGET_BASE) $(TEMP_DIR)
@echo "Cleaned generated files and temporary directory"
like this:
make bos-plus-api
What did you expect to see?
All bos.*
imports are prefixed with pyasic.web.braiins_os.proto
What did you see instead?
Only *pb2_grpc.py
files have entirely correct import prefix, other generated files like *pb2.pyi
and *pb2.py
are missing some of the correct import prefixes.
For example:
miner_pb2_grpc.py
has the correct python package import prefix path:
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings
from pyasic.web.braiins_os.proto.bos.v1 import miner_pb2 as pyasic_dot_web_dot_braiins__os_dot_proto_dot_bos_dot_v1_dot_miner__pb2
...
miner.pb2.pyi
however does not:
from bos.v1 import common_pb2 as _common_pb2
from bos.v1 import cooling_pb2 as _cooling_pb2
from bos.v1 import pool_pb2 as _pool_pb2
from bos.v1 import units_pb2 as _units_pb2
from bos.v1 import work_pb2 as _work_pb2
from google.protobuf import wrappers_pb2 as _wrappers_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from collections.abc import Iterable as _Iterable, Mapping as _Mapping
from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union
...
miner_pb2.py
appears to have a strange mix of correct and incorrect import path prefixes:
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: pyasic/web/braiins_os/proto/bos/v1/miner.proto
# Protobuf Python Version: 6.31.0
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import runtime_version as _runtime_version
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
_runtime_version.ValidateProtobufRuntimeVersion(
_runtime_version.Domain.PUBLIC,
6,
31,
0,
'',
'pyasic/web/braiins_os/proto/bos/v1/miner.proto'
)
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
from bos.v1 import common_pb2 as bos_dot_v1_dot_common__pb2
from bos.v1 import cooling_pb2 as bos_dot_v1_dot_cooling__pb2
from bos.v1 import pool_pb2 as bos_dot_v1_dot_pool__pb2
from bos.v1 import units_pb2 as bos_dot_v1_dot_units__pb2
from bos.v1 import work_pb2 as bos_dot_v1_dot_work__pb2
from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n.pyasic/web/braiins_os/proto/bos/v1/miner.proto\x12\x0e\x62raiins.bos.v1\x1a\x13\x62os/v1/common.proto\x1a\x14\x62os/v1/cooling.proto\x1a\x11\x62os/v1/pool.proto\x1a\x12\x62os/v1/units.proto\x1a\x11\x62os/v1/work.proto\x1a\x1egoogle/protobuf/wrappers.proto\"\x8c\x01\n\rMinerIdentity\x12)\n\x05\x62rand\x18\x01 \x01(\x0e\x32\x1a.braiins.bos.v1.MinerBrand\x12-\n\x05model\x18\x02 \x01(\x0e\x32\x1a.braiins.bos.v1.MinerModelB\x02\x18\x01\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x13\n\x0bminer_model\x18\x04 \x01(\t\">\n\nBosVersion\x12\x0f\n\x07\x63urrent\x18\x01 \x01(\t\x12\r\n\x05major\x18\x02 \x01(\t\x12\x10\n\x08\x62os_plus\x18\x03 \x01(\x08\"7\n\tErrorCode\x12\x0c\n\x04\x63ode\x18\x01 \x01(\t\x12\x0e\n\x06reason\x18\x02 \x01(\t\x12\x0c\n\x04hint\x18\x03 \x01(\t\"(\n\tComponent\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05index\x18\x02 \x01(\r\"\x8f\x01\n\nMinerError\x12\x11\n\ttimestamp\x18\x01 \x01(\t\x12\x0f\n\x07message\x18\x02 \x01(\t\x12.\n\x0b\x65rror_codes\x18\x03 \x03(\x0b\x32\x19.braiins.bos.v1.ErrorCode\x12-\n\ncomponents\x18\x04 \x03(\x0b\x32\x19.braiins.bos.v1.Component\"\x17\n\x15GetMinerStatusRequest\"E\n\x16GetMinerStatusResponse\x12+\n\x06status\x18\x01 \x01(\x0e\x32\x1b.braiins.bos.v1.MinerStatus\"\x18\n\x16GetMinerDetailsRequest\"\xeb\x02\n\x07PsuInfo\x12\x32\n\x07version\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt32ValueH\x00\x88\x01\x01\x12\x35\n\nfw_version\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.UInt32ValueH\x01\x88\x01\x01\x12\x1a\n\rserial_number\x18\x03 \x01(\tH\x02\x88\x01\x01\x12\x17\n\nmodel_name\x18\x04 \x01(\tH\x03\x88\x01\x01\x12\x31\n\x0bmin_voltage\x18\x05 \x01(\x0b\x32\x17.braiins.bos.v1.VoltageH\x04\x88\x01\x01\x12\x31\n\x0bmax_voltage\x18\x06 \x01(\x0b\x32\x17.braiins.bos.v1.VoltageH\x05\x88\x01\x01\x42\n\n\x08_versionB\r\n\x0b_fw_versionB\x10\n\x0e_serial_numberB\r\n\x0b_model_nameB\x0e\n\x0c_min_voltageB\x0e\n\x0c_max_voltage\"\x8c\x05\n\x17GetMinerDetailsResponse\x12\x0b\n\x03uid\x18\x01 \x01(\t\x12\x35\n\x0eminer_identity\x18\x02 \x01(\x0b\x32\x1d.braiins.bos.v1.MinerIdentity\x12*\n\x08platform\x18\x03 \x01(\x0e\x32\x18.braiins.bos.v1.Platform\x12)\n\x08\x62os_mode\x18\x04 \x01(\x0e\x32\x17.braiins.bos.v1.BosMode\x12/\n\x0b\x62os_version\x18\x05 \x01(\x0b\x32\x1a.braiins.bos.v1.BosVersion\x12\x10\n\x08hostname\x18\x06 \x01(\t\x12\x13\n\x0bmac_address\x18\x07 \x01(\t\x12\x19\n\rsystem_uptime\x18\x08 \x01(\x04\x42\x02\x18\x01\x12\x36\n\x10sticker_hashrate\x18\t \x01(\x0b\x32\x1c.braiins.bos.v1.GigaHashrate\x12\x19\n\x11\x62osminer_uptime_s\x18\n \x01(\x04\x12\x17\n\x0fsystem_uptime_s\x18\x0b \x01(\x04\x12+\n\x06status\x18\x0c \x01(\x0e\x32\x1b.braiins.bos.v1.MinerStatus\x12\x16\n\x0ekernel_version\x18\r \x01(\t\x12.\n\x08psu_info\x18\x0e \x01(\x0b\x32\x17.braiins.bos.v1.PsuInfoH\x00\x88\x01\x01\x12G\n\x18\x63ontrol_board_soc_family\x18\x0f \x01(\x0e\x32%.braiins.bos.v1.ControlBoardSocFamily\x12\x1a\n\rserial_number\x18\x10 \x01(\tH\x01\x88\x01\x01\x42\x0b\n\t_psu_infoB\x10\n\x0e_serial_number\"\x7f\n\x0fMinerPowerStats\x12\x37\n\x18\x61pproximated_consumption\x18\x01 \x01(\x0b\x32\x15.braiins.bos.v1.Power\x12\x33\n\nefficiency\x18\x02 \x01(\x0b\x32\x1f.braiins.bos.v1.PowerEfficiency\"\x16\n\x14GetMinerStatsRequest\"\xb2\x01\n\x15GetMinerStatsResponse\x12-\n\npool_stats\x18\x01 \x01(\x0b\x32\x19.braiins.bos.v1.PoolStats\x12\x34\n\x0bminer_stats\x18\x02 \x01(\x0b\x32\x1f.braiins.bos.v1.WorkSolverStats\x12\x34\n\x0bpower_stats\x18\x03 \x01(\x0b\x32\x1f.braiins.bos.v1.MinerPowerStats\"\x12\n\x10GetErrorsRequest\"?\n\x11GetErrorsResponse\x12*\n\x06\x65rrors\x18\x01 \x03(\x0b\x32\x1a.braiins.bos.v1.MinerError\"\xee\x04\n\tHashboard\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0f\n\x07\x65nabled\x18\x02 \x01(\x08\x12\x31\n\x0b\x63hips_count\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt32Value\x12\x30\n\x0f\x63urrent_voltage\x18\x04 \x01(\x0b\x32\x17.braiins.bos.v1.Voltage\x12\x34\n\x11\x63urrent_frequency\x18\x05 \x01(\x0b\x32\x19.braiins.bos.v1.Frequency\x12<\n\x11highest_chip_temp\x18\x06 \x01(\x0b\x32!.braiins.bos.v1.TemperatureSensor\x12/\n\nboard_temp\x18\x07 \x01(\x0b\x32\x1b.braiins.bos.v1.Temperature\x12.\n\x05stats\x18\x08 \x01(\x0b\x32\x1f.braiins.bos.v1.WorkSolverStats\x12\x12\n\x05model\x18\t \x01(\tH\x00\x88\x01\x01\x12\x36\n\x11lowest_inlet_temp\x18\n \x01(\x0b\x32\x1b.braiins.bos.v1.Temperature\x12\x38\n\x13highest_outlet_temp\x18\x0b \x01(\x0b\x32\x1b.braiins.bos.v1.Temperature\x12\x1a\n\rserial_number\x18\x0c \x01(\tH\x01\x88\x01\x01\x12\x17\n\nboard_name\x18\r \x01(\tH\x02\x88\x01\x01\x12\x16\n\tchip_type\x18\x0e \x01(\tH\x03\x88\x01\x01\x42\x08\n\x06_modelB\x10\n\x0e_serial_numberB\r\n\x0b_board_nameB\x0c\n\n_chip_type\"P\n\x18GetSupportArchiveRequest\x12\x34\n\x06\x66ormat\x18\x01 \x01(\x0e\x32$.braiins.bos.v1.SupportArchiveFormat\"/\n\x19GetSupportArchiveResponse\x12\x12\n\nchunk_data\x18\x01 \x01(\x0c\"\x16\n\x14GetHashboardsRequest\"F\n\x15GetHashboardsResponse\x12-\n\nhashboards\x18\x01 \x03(\x0b\x32\x19.braiins.bos.v1.Hashboard\"a\n\x17\x45nableHashboardsRequest\x12/\n\x0bsave_action\x18\x01 \x01(\x0e\x32\x1a.braiins.bos.v1.SaveAction\x12\x15\n\rhashboard_ids\x18\x02 \x03(\t\"T\n\x18\x45nableHashboardsResponse\x12\x38\n\nhashboards\x18\x01 \x03(\x0b\x32$.braiins.bos.v1.HashboardEnableState\"b\n\x18\x44isableHashboardsRequest\x12/\n\x0bsave_action\x18\x01 \x01(\x0e\x32\x1a.braiins.bos.v1.SaveAction\x12\x15\n\rhashboard_ids\x18\x02 \x03(\t\"U\n\x19\x44isableHashboardsResponse\x12\x38\n\nhashboards\x18\x01 \x03(\x0b\x32$.braiins.bos.v1.HashboardEnableState\"6\n\x14HashboardEnableState\x12\n\n\x02id\x18\x01 \x01(\t\x12\x12\n\nis_enabled\x18\x02 \x01(\x08*\xf8\x01\n\x08Platform\x12\x18\n\x14PLATFORM_UNSPECIFIED\x10\x00\x12\x13\n\x0fPLATFORM_AM1_S9\x10\x01\x12\x14\n\x10PLATFORM_AM2_S17\x10\x02\x12\x14\n\x10PLATFORM_AM3_BBB\x10\x03\x12\x14\n\x10PLATFORM_AM3_AML\x10\x04\x12 \n\x1cPLATFORM_STM32MP157C_II1_AM2\x10\x05\x12\x1b\n\x17PLATFORM_CVITEK_BM1_AM2\x10\x06\x12\x19\n\x15PLATFORM_ZYNQ_BM3_AM2\x10\x07\x12!\n\x1dPLATFORM_STM32MP157C_II2_BMM1\x10\x08*\xf3\x01\n\x15\x43ontrolBoardSocFamily\x12(\n$CONTROL_BOARD_SOC_FAMILY_UNSPECIFIED\x10\x00\x12#\n\x1f\x43ONTROL_BOARD_SOC_FAMILY_CVITEK\x10\x01\x12 \n\x1c\x43ONTROL_BOARD_SOC_FAMILY_BBB\x10\x02\x12 \n\x1c\x43ONTROL_BOARD_SOC_FAMILY_AML\x10\x03\x12!\n\x1d\x43ONTROL_BOARD_SOC_FAMILY_ZYNQ\x10\x04\x12$\n CONTROL_BOARD_SOC_FAMILY_BRAIINS\x10\x05*\x87\x01\n\x07\x42osMode\x12\x18\n\x14\x42OS_MODE_UNSPECIFIED\x10\x00\x12\x14\n\x10\x42OS_MODE_UPGRADE\x10\x01\x12\x15\n\x11\x42OS_MODE_RECOVERY\x10\x02\x12\x0f\n\x0b\x42OS_MODE_SD\x10\x03\x12\x11\n\rBOS_MODE_NAND\x10\x04\x12\x11\n\rBOS_MODE_EMMC\x10\x05*_\n\nMinerBrand\x12\x1b\n\x17MINER_BRAND_UNSPECIFIED\x10\x00\x12\x18\n\x14MINER_BRAND_ANTMINER\x10\x01\x12\x1a\n\x16MINER_BRAND_WHATSMINER\x10\x02*\xb5\x05\n\nMinerModel\x12\x1b\n\x17MINER_MODEL_UNSPECIFIED\x10\x00\x12\x1b\n\x17MINER_MODEL_ANTMINER_S9\x10\x01\x12\x1c\n\x18MINER_MODEL_ANTMINER_X17\x10\x02\x12\x1c\n\x18MINER_MODEL_ANTMINER_S17\x10\x03\x12!\n\x1dMINER_MODEL_ANTMINER_S17_PLUS\x10\x04\x12 \n\x1cMINER_MODEL_ANTMINER_S17_PRO\x10\x05\x12\x1d\n\x19MINER_MODEL_ANTMINER_S17E\x10\x06\x12\x1c\n\x18MINER_MODEL_ANTMINER_T17\x10\x07\x12\x1d\n\x19MINER_MODEL_ANTMINER_T17E\x10\x08\x12!\n\x1dMINER_MODEL_ANTMINER_T17_PLUS\x10\t\x12\x1c\n\x18MINER_MODEL_ANTMINER_X19\x10\n\x12\x1c\n\x18MINER_MODEL_ANTMINER_S19\x10\x0b\x12 \n\x1cMINER_MODEL_ANTMINER_S19_PRO\x10\x0c\x12!\n\x1dMINER_MODEL_ANTMINER_S19_PLUS\x10\r\x12\x1d\n\x19MINER_MODEL_ANTMINER_S19J\x10\x0e\x12!\n\x1dMINER_MODEL_ANTMINER_S19J_PRO\x10\x0f\x12\x1d\n\x19MINER_MODEL_ANTMINER_S19A\x10\x10\x12!\n\x1dMINER_MODEL_ANTMINER_S19A_PRO\x10\x11\x12\x1e\n\x1aMINER_MODEL_ANTMINER_S19XP\x10\x12\x12\x1c\n\x18MINER_MODEL_ANTMINER_T19\x10\x13\x12&\n\"MINER_MODEL_ANTMINER_S19J_PRO_PLUS\x10\x14\x1a\x02\x18\x01*\xb4\x01\n\x0bMinerStatus\x12\x1c\n\x18MINER_STATUS_UNSPECIFIED\x10\x00\x12\x1c\n\x18MINER_STATUS_NOT_STARTED\x10\x01\x12\x17\n\x13MINER_STATUS_NORMAL\x10\x02\x12\x17\n\x13MINER_STATUS_PAUSED\x10\x03\x12\x1a\n\x16MINER_STATUS_SUSPENDED\x10\x04\x12\x1b\n\x17MINER_STATUS_RESTRICTED\x10\x05*\xa8\x01\n\x14SupportArchiveFormat\x12&\n\"SUPPORT_ARCHIVE_FORMAT_UNSPECIFIED\x10\x00\x12\x1e\n\x1aSUPPORT_ARCHIVE_FORMAT_ZIP\x10\x01\x12\x1e\n\x1aSUPPORT_ARCHIVE_FORMAT_BOS\x10\x02\x12(\n$SUPPORT_ARCHIVE_FORMAT_ZIP_ENCRYPTED\x10\x03\x32\xa0\x06\n\x0cMinerService\x12\x61\n\x0eGetMinerStatus\x12%.braiins.bos.v1.GetMinerStatusRequest\x1a&.braiins.bos.v1.GetMinerStatusResponse0\x01\x12\x62\n\x0fGetMinerDetails\x12&.braiins.bos.v1.GetMinerDetailsRequest\x1a\'.braiins.bos.v1.GetMinerDetailsResponse\x12\\\n\rGetMinerStats\x12$.braiins.bos.v1.GetMinerStatsRequest\x1a%.braiins.bos.v1.GetMinerStatsResponse\x12P\n\tGetErrors\x12 .braiins.bos.v1.GetErrorsRequest\x1a!.braiins.bos.v1.GetErrorsResponse\x12\\\n\rGetHashboards\x12$.braiins.bos.v1.GetHashboardsRequest\x1a%.braiins.bos.v1.GetHashboardsResponse\x12j\n\x11GetSupportArchive\x12(.braiins.bos.v1.GetSupportArchiveRequest\x1a).braiins.bos.v1.GetSupportArchiveResponse0\x01\x12\x65\n\x10\x45nableHashboards\x12\'.braiins.bos.v1.EnableHashboardsRequest\x1a(.braiins.bos.v1.EnableHashboardsResponse\x12h\n\x11\x44isableHashboards\x12(.braiins.bos.v1.DisableHashboardsRequest\x1a).braiins.bos.v1.DisableHashboardsResponseB=Z;github.com/braiins/bos-plus-api/braiins/bos/v1;bos_proto_v1b\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'pyasic.web.braiins_os.proto.bos.v1.miner_pb2', _globals)
...