Generated code has non-existent relative import
まだ誰も着手していません。
評価
調査の方向性
記載された proto import、buf template、および buf generate --template buf.gen.additional.yaml --include-imports を使って問題を再現します。生成された mypackage.py と出力ツリーを調査し、失敗している from .google import protobuf を期待される import と比較します。記載された Google パッケージについて、生成された import を解決できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
from .google import protobuf which doesn't exist
Reproduction Steps
I’m facing an issue with the imported packages, my protofile has some import like this:
syntax = "proto3";
package mypackage;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/field_mask.proto";
import "google/api/resource.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
//import "validate/validate.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
I’m running the code generation with buf:
version: v1
managed:
enabled: true
plugins:
# Python
- plugin: buf.build/community/danielgtaylor-betterproto:v1.2.5
out: _gen/pythonbproto2
and the command to run it is: buf generate --template buf.gen.additional.yaml --include-imports
The generated files are like this:
tree mypackage/api/proto/_gen/pythonbproto2
├── __init__.py
├── google
│ ├── __init__.py
│ └── api.py
├── grpc
│ ├── __init__.py
│ └── gateway
│ ├── __init__.py
│ └── protoc_gen_openapiv2
│ ├── __init__.py
│ └── options.py
└── mypackage
However the generated file mypackage.py is expecting a relative dir called google.protobuf which couldn’t be found, it has only the api.py not protobuf.
from .google import protobuf
Expected Results
The imported packages are properly handled. In the normal protoc way of generation, google.protobuf is a package and is imported directly like this: from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
Actual Results
A relative import which doesn't exist: from .google import protobuf
System Information
protoc --version
libprotoc 24.3
buf --version
1.21.0
version: v1
managed:
enabled: true
plugins:
# Python
- plugin: buf.build/community/danielgtaylor-betterproto:v1.2.5
out: _gen/pythonbproto2
I'm not able to use normal command line to generate this:
protoc -I . --python_betterproto_out=lib mypackage.proto
google/api/annotations.proto: File not found.
google/api/client.proto: File not found.
google/api/field_behavior.proto: File not found.
google/api/resource.proto: File not found.
protoc-gen-openapiv2/options/annotations.proto: File not found.
mypackage.proto:5:1: Import "google/api/annotations.proto" was not found or had errors.
mypackage.proto:6:1: Import "google/api/client.proto" was not found or had errors.
mypackage.proto:7:1: Import "google/api/field_behavior.proto" was not found or had errors.
mypackage.proto:9:1: Import "google/api/resource.proto" was not found or had errors.
mypackage.proto:13:1: Import "protoc-gen-openapiv2/options/annotations.proto" was not found or had errors.
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- [] I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 235
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
danielgtaylor/python-betterproto のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
bug investigation needed
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
danielgtaylor/python-betterproto#676 · コメント 3 件 ·
danielgtaylor/python-betterproto の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
volcengine/OpenViking#6445 ·
メンテナーはふだん 1 日以内に返信
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be edited対応中かも @ManyaJain111 が今日担当しました。 オープンbug enhancement possible-duplicate
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
AOSSIE-Org/PictoPy#1637 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
deepspeedai/DeepSpeed#8884 ·
メンテナーはふだん 3 日以内に返信
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
flagos-ai/FlagQuantum#718 ·
メンテナーはふだん 1 日以内に返信
-
bug CI-failure high priority
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
vllm-project/afd-plugin#483 ·
メンテナーはふだん 1 日以内に返信