danielgtaylor / danielgtaylor/python-betterproto

ProtoContentBase.proto_file is always the first file of a package

オープン
#209 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

I have a large protobuf package whose messages, etc. are defined over multiple files. However, `ProtoContentBase.proto_file` always refers to the *first* file of the package passed to `protoc`. As a result, when I run `protoc` the comments attached to each class and field are from the first file.

I hacked a solution to this by adding `proto_input_file` to `ProtoContentBase` and passing this as an argument all the way from `generate_code` through `read_protobuf_type`/`read_protobuf_service`, then adding:

- To `OutputTempate`:
```python
@property
def input_files_dict(self) -> Dict[str, FileDescriptorProto]:
"""Dictionary mapping filenames to their FileDescriptorProto objects

Returns
-------
Dict[str, FileDescriptorProto]
Dictionary mapping filenames to their FileDescriptorProto objects
"""
return {f.name: f for f in self.input_files}
```

- to `ProtoContentBase`
```python
@property
def proto_file(self) -> FieldDescriptorProto:
template = self.output_file
return template.input_files_dict[self.proto_input_file]
```

I'd be delighted to contribute a proper fix and open a PR for it, but it'd be good to hear if there's a better approach to solving the problem.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

generate_code が read_protobuf_type と read_protobuf_service にコンテキストを渡す方法を追跡し、次に ProtoContentBase.proto_file と OutputTempate を調べます。複数ファイルのパッケージが各メッセージおよびフィールドのソース記述子をどのように選択するかを確認します。各要素を定義しているファイルから生成コメントが取得され、常に最初の入力ファイルから取得される状態でなければ完了とはみなしません。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。