bazel-contrib / bazel-contrib/rules_python

[Gazelle][proto] How to automatically resolve protobuf target

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

説明

# 🐞 bug report

### Affected Rule

gazelle resolve

### Is this a regression?
No

### Description

I have a python file with a proto definition imported. When I try to use gazelle to auto generate py_library target, it fails to validate dependency. I look into some code in bazel_gazelle/resolve/index.go, no proto target defined in there.

## 🔬 Minimal Reproduction

  

import a.b.c_pb2

and then run bazel run :py_gazelle

## 🔥 Exception or Error

  

gazelle: ERROR: failed to validate dependencies for target "//:check": "a.b.c_pb2" at line 11 from "check.py" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive.
3. Ignore it with a comment '# gazelle:ignore a.b.c_pb2' in the Python file.

"a.b" at line 11 from "check.py" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive.
3. Ignore it with a comment '# gazelle:ignore a.b' in the Python file.

"a" at line 11 from "check.py" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Instruct Gazelle to resolve to a known dependency using the gazelle:resolve directive.
3. Ignore it with a comment '# gazelle:ignore a' in the Python file.


## 🌍 Your Environment

**Operating System:**

  

ubuntu 20.04

**Output of `bazel version`:**

  

Bazelisk version: v1.16.0
Build label: 6.2.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 2 16:59:58 2023 (1685725198)
Build timestamp: 1685725198
Build timestamp as int: 1685725198

**Rules_python version:**

  

0.25

**Anything else relevant?**
rules_python_gazelle_plugin version
0.28

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

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

調査の方向性

bazel_gazelle/resolve/index.go から始め、`bazel run :py_gazelle` を使って、示されている `import a.b.c_pb2` の例で失敗を再現してください。`gazelle resolve` が Python の依存関係をどのように検証しているかを追跡し、protobuf によって生成されたターゲットをどのように認識すべきかを特定してください。完了の条件は、手動の resolve ディレクティブなしで、この例が有効な `py_library` 依存関係を生成することです。

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

評価

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

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

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