bazel-contrib / bazel-contrib/rules_python

Gazelle generates py_proto_library with imports attribute when in a non-root python_root

オープン
#3,494 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
gazelle
主要言語
Starlark
スター
688
フォーク
721
平均マージ
15時間 7分
マージ済み PR(30日)
76

説明

# 🐞 bug report

### Affected Rule

`gazelle`

### Is this a regression?

No, I believe it's a new feature introduced by https://github.com/bazel-contrib/rules_python/issues/2994 and it seems to be not working as expected in the specific situation of this report.

### Description

When using gazelle to generate [`py_proto_library`](https://github.com/bazel-contrib/rules_python/issues/2994), it doesn't work as expected when the proto file is in a subfolder of a python root that differs from the repo root (specified with the directive `# gazelle:python_root`).

Gazelle generates the target with an `imports` attribute, which is not supported and thus the target fails to build.

## 🔬 Minimal Reproduction

https://github.com/regb/issue-reports/tree/main/rules_python/py_proto_imports

## 🔥 Exception or Error

Gazelle runs smoothly but generates the invalid targets, then running build generate this error:



$ bazel build ...
ERROR: /home/regb/vcs/issue-reports/rules_python/py_proto_imports/src/mypackage/BUILD.bazel:10:17: //src/mypackage:example_py_pb2: no such attribute 'imports' in 'py_proto_library' rule
ERROR: package contains errors: src/mypackage
ERROR: package contains errors: src/mypackage: //src/mypackage:example_py_pb2: no such attribute 'imports' in 'py_proto_library' rule
WARNING: Target pattern parsing failed.
ERROR: Skipping '...': Error evaluating '...': error loading package 'src/mypackage': Package 'src/mypackage' contains errors
ERROR: Error evaluating '...': error loading package 'src/mypackage': Package 'src/mypackage' contains errors
INFO: Elapsed time: 0.136s
INFO: 0 processes.
ERROR: Build did NOT complete successfully

## 🌍 Your Environment

**Operating System:**

  

Ubuntun 22.04

**Output of `bazel version`:**

  

8.5.0

**Rules_python version:**

  

1.7.0 (also tested 1.6.3)

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

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

調査の方向性

regb/issue-reports/rules_python/py_proto_imports の最小再現から始め、src/mypackage 配下に生成された BUILD.bazel を調べます。# gazelle:python_root ディレクティブと、生成された py_proto_library ターゲットに注目してください。Gazelle に続けて bazel build ... を実行します。生成されたターゲットにサポートされていない imports 属性が含まれなくなり、ビルドが成功すれば完了です。

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

評価

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

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

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