bazel-contrib / bazel-contrib/rules_python

Optionally (?) regenerate `import` attributes

Đang mở
#3,177 0 bình luận 0 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

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.

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

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

Hướng nghiên cứu

Bắt đầu với chỉ thị `python_root`, các ví dụ `BUILD.bazel` và quy trình `bazel run //:gazelle` được mô tả ở đây. So sánh các cách tiếp cận tái sinh được đề xuất và cách chúng tương tác với các target không được quản lý cùng kiểm tra dirty-tree của CI. Được xem là hoàn tất khi hành vi được chọn cập nhật các `imports` đã cũ mà không sửa đổi các target mà Gazelle không quản lý.

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
Cần làm rõ
Mức phù hợp với người mới
30/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.