danielgtaylor / danielgtaylor/python-betterproto

betterproto-2.0.0b5 fails to generate message classes when proto package name contains upper case letters

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

説明

## Steps to reproduce

### Install `betterproto-2.0.0b5` + tooling:

```bash
pip install --pre betterproto[compiler]
pip install grpcio-tools
```
other versions:
> grpcio==1.50.0
grpcio-tools==1.50.0
grpclib==0.4.3

### Create an `example.proto`
```proto
syntax = "proto3";

package mypackage; // this is the only change to the MWE from README.md

message EchoRequest {
string value = 1;
// Number of extra times to echo
uint32 extra_times = 2;
}

message EchoResponse {
repeated string values = 1;
}

message EchoStreamResponse {
string value = 1;
}

service Echo {
rpc Echo(EchoRequest) returns (EchoResponse);
rpc EchoStream(EchoRequest) returns (stream EchoStreamResponse);
}
```

### Create the directory
```bash
mkdir lib
```

### Generate Python Code:
```bash
python -m grpc_tools.protoc -I . --python_betterproto_out=lib example.proto
```

Check that `lib/mypackage/__init__.py` contains _no_ unresolvable imports. ✔

Up to here, this is just the MWE from `README.md` with a different but all-lower package name.

### Introduce Upper Case Letters in the Package Name

Now modify the above `example.proto` and change the all-lower case `package mypackage` in line 3 to an UpperCamel `package MyPackage`.

Repeat the next steps up to the code generation (don't forget to clean up `lib` before re-generating).

The newly generate `lib/MyPackage/__init__.py` now contains unresolvable imports:
```python
from .. import (
MyPackageEchoResponse as _MyPackageEchoResponse__,
MyPackageEchoStreamResponse as _MyPackageEchoStreamResponse__,
)
```

The `lib/__init__.py` does not contain anything to import.
No classes `MyPackageEchoResponse` or `MyPackageEchoStreamResponse` have been generated ❌

## Expected Behaviour
The code generation shall work for mixed casing package names.

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

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

調査の方向性

example.proto の再現から始め、package を MyPackage に変更した後、ドキュメントに記載された grpc_tools.protoc コマンドを実行します。lib/MyPackage/__init__.py と lib/__init__.py を確認します。生成された import が解決され、MyPackageEchoResponse クラスと MyPackageEchoStreamResponse クラスが存在すれば完了です。

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

評価

技術スタック
grpc, python
領域
compilers, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

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

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