Looks, like adding one more path 
'--proto_path={}'.format(os.path.join(proto_path, 'contrib/libs/protobuf')) 
to command fix my problem

четверг, 27 июля 2017 г., 11:00:29 UTC+3 пользователь 
[email protected] написал:
>
> Hi!
>
> I need create script (python) to build python classes from set of proto 
> files.
>
> I found example here grpc_tools/command.py#L35 
> <https://github.com/grpc/grpc/blob/5253c8f9a899450397a5e46e4923d01ac9a66a27/tools/distrib/python/grpcio_tools/grpc_tools/command.py#L35>
>
> I 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/b16e1250-2733-4389-b2e8-4efde295d786%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to