bazel-contrib / bazel-contrib/rules_python
Optionally (?) regenerate `import` attributes
- Langage dominant
- Starlark
- Étoiles
- 688
- Forks
- 721
- Merge moyen
- 15 h 7 min
- PR mergées (30 j)
- 76
Description
# 🚀 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.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par la directive `python_root`, les exemples de `BUILD.bazel` et le workflow `bazel run //:gazelle` décrits ici. Comparez les approches de régénération proposées et leur interaction avec les targets non gérées et la vérification de l’arbre de travail modifié par la CI. C’est terminé lorsque le comportement choisi met à jour les `imports` obsolètes sans modifier les targets que Gazelle ne gère pas.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- build-system
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 30/100