bazel-contrib / bazel-contrib/rules_python
Feat: Gazelle directive `# gazelle:python_ignore_target target`
- 主要语言
- Starlark
- 星标
- 688
- 派生
- 721
- 平均合并
- 15 小时 7 分钟
- 30 天内合并 PR
- 76
描述
# 🚀 feature request
### Relevant Rules
gazelle
### Description
Gazelle can skip files/directories via `# gazelle:exclude file` and can ignore entire `BUILD.bazel` files with `# gazelle:ignore`. `rules_python_gazelle_plugin` also adds a `# gazelle:ignore import` annotation that can be added to `.py` files.
Gazelle can also force deps to be kept around with the `# keep` comment within a target.
However, there's not currently (that I'm aware of) any way to tell gazelle to ignore an entire _target_.
Ignoring an entire target can be useful when there are hand-written targets or ones that don't follow the rest of the directives (such as additional file-level targets when the generation mode is package). Having such a directive will also unblock the issues I raised on @yushan26's PR #3046, allowing them to expand the scope from just py_binary targets to all targets.
### Describe the solution you'd like
New directive: `# gazelle:ignore_target target`.
Or if we don't want do potentially shadow a future directive from bazel_gazelle, `# gazelle:python_ignore_target target`. We could also bike shed about "ignore" vs "exclude".
If `target` isn't found, the directive has no effect. Maybe it logs a warning, but that's it.
Should wildcards be allowed? For an MVP I don't think so. That adds complexity with, at least for my direct use case, little gain.
### Describe alternatives you've considered
You may ask: "How is this different from a `# keep` comment at the start of a target?"
```starlark
# keep: this cannot be managed by Gazelle because
py_library(
...
)
```
The main difference is that the directive can be set in any parent BUILD.bazel file, thus allowing people to have a central location for all such directives:
```starlark
# gazelle:python_ignore_target //foo/bar:baz
# gazelle:python_ignore_target //foo/bar:baz_test
# gazelle:python_ignore_target //a/b/c/d:e
```
Admittedly it's a pretty weak argument for having a new directive.
There may also be subtle differences with how gazelle collects targets and generates new ones (eg https://github.com/bazel-contrib/bazel-gazelle/issues/1176) but I haven't fully investigated those yet.
贡献指南
调研方向
首先检查 issue 中描述的现有 Gazelle 指令,包括 rules_python_gazelle_plugin 对 `# gazelle:ignore import` 的处理方式,以及 Gazelle 的目标收集行为。在决定 `ignore_target` 还是 `python_ignore_target` 更合适之前,阅读 issues #3046 和 bazel-gazelle #1176 中的上下文。完成的标准是:指令行为、目标查找、缺失目标处理方式和通配符范围均已明确,并由适当的测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- build-system
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100