Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-complete etc support for protobuf generated code #6379

Open
cnsgsz opened this issue Apr 8, 2024 · 4 comments
Open

auto-complete etc support for protobuf generated code #6379

cnsgsz opened this issue Apr 8, 2024 · 4 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: python Python rules integration P3 We're not considering working on this, but happy to review a PR. (No assignee) product: CLion CLion plugin product: PyCharm PyCharm plugin type: bug

Comments

@cnsgsz
Copy link

cnsgsz commented Apr 8, 2024

Description of the bug:

Clion cannot find protobuf generated code.

from xxx import foo_pb2

# Without "noinspection PyUnresolvedReferences", clion warns "cannot find `FooProto` in foo_pb2.py.
pb = foo_pb2.FooProto.FromString(record.numpy())

This also makes auto-complete etc not possible for protobuf code.

Which category does this issue belong to?

CLion, PyCharm

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Define any proto and use py_proto_library that comes with the protobuf library.

Example from tensorflow's workspace files:

    tf_http_archive(
        name = "com_google_protobuf",
        patch_file = ["//third_party/protobuf:protobuf.patch"],
        sha256 = "f66073dee0bc159157b0bd7f502d7d1ee0bc76b3c1eac9836927511bdc4b3fc1",
        strip_prefix = "protobuf-3.21.9",
        system_build_file = "//third_party/systemlibs:protobuf.BUILD",
        system_link_files = {
            "//third_party/systemlibs:protobuf.bzl": "protobuf.bzl",
            "//third_party/systemlibs:protobuf_deps.bzl": "protobuf_deps.bzl",
        },
        urls = tf_mirror_urls("https://github.com/protocolbuffers/protobuf/archive/v3.21.9.zip"),
    )

In BUILD:

load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")

py_proto_library(
    name = "foo_py_proto",
    srcs = ["foo.proto"],
)

Example foo.proto:

syntax = "proto3";

package xxx;

message FooProto {
...
}

Which Intellij IDE are you using? Please provide the specific version.

Clion 2023.3.4 and PyCharm professional 2023.3.4

What programming languages and tools are you using? Please provide specific versions.

python3.10

What Bazel plugin version are you using?

2024.1.30.0.1-api-version-233

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

It's not clear to me if this is a pycharm/clion issue, or bazel plugin issue, or protobuf (rule) issue. See this pycharm/clion issue.

In my generated foo_pb2.py, I don't see FooProto explicitly defined. globals() might be doing something magical that confuses clion/pycharm?

# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: xxx/foo.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x14...proto3')

_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'xxx.foo_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:

  DESCRIPTOR._options = None
...
# @@protoc_insertion_point(module_scope)

@cnsgsz cnsgsz added awaiting-maintainer Awaiting review from Bazel team on issues type: bug labels Apr 8, 2024
@github-actions github-actions bot added product: CLion CLion plugin product: PyCharm PyCharm plugin labels Apr 8, 2024
@iancha1992 iancha1992 added the lang: python Python rules integration label Apr 8, 2024
@tpasternak
Copy link
Contributor

@ujohnny @LeFrosch do you have capacity to handle it?

@tpasternak
Copy link
Contributor

I can confirm I can reproduce the problem, however sadly I have to assign P3 as I don't have capacity to fix it soon

@tpasternak tpasternak added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Aug 22, 2024
@tpasternak
Copy link
Contributor

However, I think this might be caused by the fact that py_proto_library from creates the class dynamically as you mentioned, so I'm not sure if this will ever work. Are there any other generators that create regular python class files?

@tpasternak
Copy link
Contributor

tpasternak commented Aug 22, 2024

Btw I'm not sure if we can do a lot about that on IJ side, however it seems that you could configure your project in a way it would produce more ide-readable python proto outputs. Btw there is a related ticked in the protocolbuffers project protocolbuffers/protobuf#16115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: python Python rules integration P3 We're not considering working on this, but happy to review a PR. (No assignee) product: CLion CLion plugin product: PyCharm PyCharm plugin type: bug
Projects
None yet
Development

No branches or pull requests

6 participants