2017-10-14 114 views
0

我很难让IntelliJ IDEA识别python中生成的protobuf源代码。如何让IntelliJ IDEA识别bazel生成的python protobufs?

我有一个原型文件,一个Python文件,并建立档案:

$ find -type f 
./WORKSPACE 
./src/proto/BUILD 
./src/proto/mymessage.proto 
./src/python/foo/BUILD 
./src/python/foo/foo.py 

我的Python脚本导入生成的Python类的protobuf的:

$ cat src/python/foo/foo.py 
from src.proto import mymessage_pb2 

message = mymessage_pb2.MyMessage() 
message.my_field = "Hello world!" 

print(message.my_field) 
产生

为原Python类这样:

$ cat src/proto/BUILD 
package(default_visibility = ["//visibility:public"]) 

genrule(
    name = "gen_mymessage_py_proto", 
    srcs = ["mymessage.proto"], 
    outs = ["mymessage_pb2.py"], 
    cmd = "protoc $(location mymessage.proto) --python_out=$(GENDIR) ", 
) 

py_library(
    name = "mymessage_py_proto", 
    srcs = [":gen_mymessage_py_proto"], 
) 

Bazel按预期运行一切:

$ bazel run src/python/foo:foo 
INFO: Analysed target //src/python/foo:foo (16 packages loaded). 
INFO: Found 1 target... 
Target //src/python/foo:foo up-to-date: 
    bazel-bin/src/python/foo/foo 
INFO: Elapsed time: 0.525s, Critical Path: 0.05s 
INFO: Build completed successfully, 5 total actions 

INFO: Running command line: bazel-bin/src/python/foo/foo 
Hello world! 

不过的IntelliJ无法识别进口: IntelliJ fails to recognize generated proto import

我能做些什么使的IntelliJ认识到这一点的进口?

+0

提交了bazel intellij插件的错误:https://github.com/bazelbuild/intellij/issues/144 –

回答

0

Bazel不支持解析genfile导入。这已被固定为issues/144的一部分。该修补程序应该在11月3日发布。