【发布时间】:2017-10-14 00:27:11
【问题描述】:
我很难让 IntelliJ IDEA 识别 python 中生成的 protobuf 源。
我有一个 proto 文件、一个 python 文件和 BUILD 文件:
$ find -type f
./WORKSPACE
./src/proto/BUILD
./src/proto/mymessage.proto
./src/python/foo/BUILD
./src/python/foo/foo.py
我的 python 脚本为 protobuf 导入生成的 python 类:
$ 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)
proto 的 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 识别此导入?
【问题讨论】:
-
提交了 bazel intellij 插件的错误:github.com/bazelbuild/intellij/issues/144
标签: python intellij-idea protocol-buffers bazel