bazel-contrib / bazel-contrib/rules_python

Optionally (?) regenerate `import` attributes

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

説明

# 🚀 feature request

### Relevant Rules

Gazelle

### Description

The `python_root` directive will tell Gazelle to include the `imports` attribute on generated targets. Eg:

```starlark
py_library(
...
imports = ["../../.."],
...
)
```

However, when the `BUILD.bazel` and python files are moved, these `imports` are not updated when Gazelle processes that directory again, even if there were changes to the python files/imports/whatnot.

### Describe the solution you'd like

Hmm... one of:

1. Opt-in directive that tells Gazelle that it's OK to regenerate `imports`.
2. CLI arg for regenerating imports `bazel run //:gazelle -- --regen-imports` so that it can be run as a one-off
3. Always regenerate?

### Describe alternatives you've considered

Right now I run:

```
bazel run //:buildozer 'remove imports' //...:*; bazel run //:gazelle
```

Which is fine I guess. We currently use `bazel run //:gazelle` in CI to check that Gazelle won't make any modifications (CI fails if the git tree is dirty after running that command).

The problem with the above command and running it in CI is that we have targets that are intentionally _not_ managed by Gazelle. Those get modified by the `buildozer` command and then not fixed when running Gazelle.

I could probably update the `buildozer` command to ignore those unmanaged targets, but it would be quite messy - the unmanaged targets are a clusterfrack. It would be chaining `bazel query` to get the "exclude" syntax and then passing a list of managed targets to `buildozer`. Something like:

```shell
MANAGED_TARGETS=$(bazel query '//... except //foo/bar:* except //baz:* except //abc:apple')
bazel run //:buildozer 'remove imports' ${MANAGED_TARGETS}
bazel run //:gazelle
```

And I'd have to update that `query` when a new non-managed target/package is added.

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

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

調査の方向性

ここで説明されている `python_root` ディレクティブ、`BUILD.bazel` の例、`bazel run //:gazelle` ワークフローから始めます。提案されている再生成アプローチと、それらが未管理のターゲットおよび CI の dirty-tree チェックとどのように相互作用するかを比較します。選択した動作が古い `imports` を更新し、Gazelle が管理していないターゲットを変更しなければ完了です。

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

評価

技術スタック
python
領域
build-system
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

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

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