bazel-contrib / bazel-contrib/rules_python

Stop adding repos to sys.path (set experimental_python_import_all_repositories to false)

Đang mở
#2,943 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
cleanup core-rules
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ả

Right now, repo roots are added to sys.path. This is problematic for a variety of reasons

* It causes the repos with external pip deps to end up on sys.path, which are just spam and just cause problems.
* For the main repo and other external repos, they should be using the `imports` attribute on their public targets instead.

The situation is a bit complicated because the flag (and its default) are defined in bazel, while the implementation is in rules_python. Also, there's a decent reliance on this behavior in the broader ecosystem because it's been around for a long time, even though it was never a good idea to rely on it. With the advent of bzlmod, the reliance would only get worse (adding repo roots to path is helpful under bzlmod).

I think the venv site-packages work we've done will help this problem -- it allows mapping an arbitrary directory into site-packages, which should make materializing external repos under arbitrary names more flexible.

I think the steps needed are:
1. [ ] Add a flag in rules_python to replace the bazel-builtin one.
2. [ ] Let bazel remove their flag when appropriate. Note that doing this will force users to upgrade to a version of rules_python with (1)
3. [ ] Disable adding repo roots for pip-generated repos. Do this by adding a marker file in the repo root (under the hood, these repos are added by doing listdir() on the runfiles root)
4. [ ] Add an allowlist for which external repos are added to sys.path. We don't control non-pip repos, so need another mechanism to specify this. A flag that points to a target with repo names to allow being added onto sys.path is good compromise.
5. [ ] Disable the behavior by default; users can use the allowlist to aid migration.
6. [ ] Eventually remove the allowlist.

The old builtin flag (`--foo`) can be mapped to the new repo-flag (`--@bla//:foo`) using `--flag_alias`

This is the rules_python side of https://github.com/bazelbuild/bazel/issues/2636

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 đọc issue Bazel được liên kết và lần theo cách flag được định nghĩa trong Bazel so với cách nó được triển khai trong rules_python. Thực hiện sáu bước migration, bao gồm flag thay thế, marker pip-repository và allowlist; được xem là hoàn tất khi repo roots không còn được thêm theo mặc định và allowlist hỗ trợ migration.

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