Hi!
I need create script (python) to build python classes from set of proto files.
I found example here
grpc_tools/command.py#L35I took the code
from grpc_tools import protoc
...
for file_name in proto_file_names:
file_path = os.path.join(proto_dir, file_name)
check_path_exist(file_path)
proto_files.append(file_path)
for proto_file in proto_files:
command = [
'grpc_tools.protoc',
'--proto_path={}'.format(proto_path),
'--python_out={}'.format(current_directory),
'--grpc_python_out={}'.format(current_directory),
] + [proto_file]
if protoc.main(command) != 0:
sys.stderr.write('warning: {} failed\n'.format(command))
and get following errors while run script (I have a lot of such)
google/protobuf/descriptor.proto: File not found.
full/path/to/my/file.proto: Import "google/protobuf/descriptor.proto" was not found or had errors.
full/path/to/my/file.proto:45:8: "google.protobuf.EnumValueOptions" is not defined.
full/path/to/my/file.proto: "google.protobuf.EnumValueOptions" is not defined.
full/path/to/my/file.proto: "google.protobuf.EnumValueOptions" is not defined.
full/path/to/my/file.proto:51:8: "google.protobuf.EnumOptions" is not defined.
But when I run command line
python -m grpc_tools.protoc -I../../.. --python_out=. --grpc_python_out=. path/to/my/files/*.proto
All is ok. There are no any errors.
Same issue appears for any single proto file (not full set) containing some imports.
I think it somehow related to import paths but I can not find way to fix it. All parameters and current working directory for both (command line and python script) ways are the same.