Deprecate and remove implicit py_binary zipapp support
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- build-system
Hướng nghiên cứu
Tìm trong repository các chuỗi build_python_zip và python_zip_file, sau đó kiểm tra các tệp BUILD được tham chiếu, các triển khai my_rule.bzl và các transition trong rule.bzl. So sánh từng cách sử dụng với các trường hợp migration trong issue này và xác định các target Bazel bị ảnh hưởng. Hoàn thành có nghĩa là các đường dẫn zipapp ngầm định legacy đã được xóa hoặc migrate sang py_zipapp_binary hoặc py_zipapp_test mà không làm hỏng các build liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The implicit zipapp support of py_binary and py_test is being deprecated and removed. It is replaced by the py_zipapp_binary and py_zipapp_test rules. There are several ways the implicit zipapp logic may be activated.
For reference, these are the two loads you're most likely to need:
load("@rules_python//python/zipapp:py_zipapp_binary.bzl", "py_zipapp_binary")
load("@rules_python//python/zipapp:py_zipapp_test.bzl", "py_zipapp_test")
The flag name you want to look for is build_python_zip.
Windows-specific note: Windows enables zipapp by default, so the absence of the flag is the same as
--build_python_zip=true!
Migration guide
This guide tries to give information on how to handle all possible cases of what may need to be migrated. Most changes are small, should be transparent, and can be done incrementally.
In practice, the most likely scenario you'll need to fix is using the
--build_python_zip flag on the command line -- see the "Migrate explicit --build_python_zip" section for that case.
Disable legacy zipapp flag
Add common --build_python_zip=false --@rules_python//python/config_settings:build_python_zip=false to your .bazelrc
Windows-specific note: Windows enables zipapp by default
Migrate explicit --build_python_zip usage
TLDR: Replace --build_python_zip on the command line with a py_zipapp_binary target in a BUILD file.
Replace this:
# File: BUILD
py_binary(name="bin")
# Command line
bazel build //:bin --build_python_zip
With this:
# File: BUILD
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name="bin")
py_zipapp_binary(name = "bin_zipapp", binary=":bin")
# Command line
bazel build //:bin_zipapp
Migrate py_binary using config_settings with py_zipapp rule
TLDR: Add py_zipapp_binary for each py_binary you want as a zipapp
Replace this:
py_binary(
name = "bin"
config_settings = {
"@rules_python//python/config:build_python_zip": "true",
"//command_line_option:build_python_zip": "true",
},
...
)
With this:
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(
name = "bin"
...
)
py_zipapp_binary(
name = "bin.zipapp",
binary = ":bin",
)
Migrate filegroup using python_zip_file output group
Replace this:
TLDR: Add py_zipapp_binary and point the filegroup to it.
py_binary(name = "bin", ...)
filegroup(
name = "bin_zip_file",
output_group = "python_zip_file",
srcs = [":bin"],
)
With this:
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name = "bin", ...)
py_zipapp_binary(name = "bin_zipapp", binary=":bin")
filegroup(
name = "bin_zip_file",
output_group = "python_zip_file",
srcs = [":bin_zipapp"],
)
Migrate Starlark using python_zip_file output group
TLDR: Add py_zipapp target and use it as the input target instead.
Replace this:
# File: my_rule.bzl
def _my_rule_impl(ctx):
zip_file = ctx.attr.binary[OutputGroupInfo]["python_zip_file"].to_list()[0]
# File: BUILD.bazel
py_binary(name="bin", ...)
my_rule(name = "mytarget", binary=":bin", ...)
With this:
# File: my_rule.bzl
def _my_rule_impl(ctx):
zip_file = ctx.attr.binary[OutputGroupInfo]["python_zip_file"].to_list()[0]
# File: BUILD.bazel
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name="bin", ...)
py_zipapp_binary(name = "bin_zipapp", binary=":bin")
my_rule(name = "mytarget", binary=":bin_zipapp", ...)
Migration transitions setting build_python_zip flags
TLDR: Remove the build_python_zip flags from the transition and refactor into a separate target.
Replace this:
# File: rule.bzl
my_transition = transition(
outputs = [
"//command_line_settings:build_python_zip",
"@rules_python//python/config_settings:build_python_zip",
],
...
)
my_rule(cfg = my_transition, ...)
# File: BUILD
py_binary(name="bin", ...)
my_rule(target=":bin")
With this:
# File: rule.bzl
my_transition = transition(
outputs = [],
...
)
my_rule(cfg = my_transition, ...)
# File: BUILD
load("@rules_python//python/zipapp:py_zipapp_binary", "py_zipapp_binary")
py_binary(name="bin", ...)
py_zipapp_binary(name="bin_zipapp", binary=":bin")
my_rule(target=":bin_zipapp")
- Ngôn ngữ chính
- Starlark
- Star
- 690
- Fork
- 722
- Merge trung bình
- 1 ngày 55 phút
- Pull request đã merge (30 ngày)
- 38
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bazel-contrib/rules_python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
bazel-contrib/rules_python#4179 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bazel-contrib/rules_python#4164 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bazel-contrib/rules_python#3821 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
bazel-contrib/rules_python#4181 ·
-
Release 2.4.0 Đang mởtype: release
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bazel-contrib/rules_python#4175 · 3 bình luận ·
Tất cả issue của bazel-contrib/rules_python
Issue tương tự
-
Name consistency Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
eellak/triplestore#65 · 1 bình luận ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
area-Bzlmod team-ExternalDeps type: bug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
bazelbuild/bazel#31291 · 2 bình luận ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
bradcypert/plum#53 ·