bazel-contrib / bazel-contrib/rules_python

Feat: Gazelle directive `# gazelle:python_ignore_target target`

Đang mở
#3,105 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
gazelle
Ngôn ngữ chính
Starlark
Star
688
Fork
721
Merge trung bình
15 giờ 7 phút
Pull request đã merge (30 ngày)
76

Mô tả

# 🚀 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách xem xét các chỉ thị Gazelle hiện có được mô tả trong issue, bao gồm cách rules_python_gazelle_plugin xử lý `# gazelle:ignore import` và hành vi thu thập target của Gazelle. Đọc ngữ cảnh từ các issue #3046 và bazel-gazelle #1176 trước khi quyết định `ignore_target` hay `python_ignore_target` phù hợp hơn. Được xem là hoàn tất khi hành vi của chỉ thị, việc tra cứu target, cách xử lý target bị thiếu và phạm vi của wildcard được đặc tả và được bao phủ bằng các test phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
build-system
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.