bazel-contrib / bazel-contrib/rules_python
(feat request) Add a gazelle directive for using `requirement()` for pip-installable dependencies
- 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
+ requirements.bzl
### Description
Gazelle generates deps using the library labels directly, rather than using `requirement()` (possibly because of the [drawbacks of `requirement()`](https://github.com/bazelbuild/rules_python/issues/414)).
```starlark
# using labels
py_library(
name = "foo",
srcs = ["foo.py"],
deps = ["@pip_parse_name//boto3"],
)
```
```starlark
# using `requirement()` function
load("@pip_parse_name//:requirements.bzl", "requirement")
py_library(
name = "foo",
srcs = ["foo.py"],
deps = [requirement("boto3")],
)
```
It would be great if we could configure this on a per-package basis. Users would then be able to opt-in to using `requirement()`, making the transition from manually-built BUILD files to gazelle-generated files much easier (as the diff will be much smaller or nonexistent[^1]).
[^1]: The [docs](https://rules-python.readthedocs.io/en/latest/pypi-dependencies.html#using-third-party-packages) guide users to use `requirement()` initially, and I'm not sure how many people opt to use labels instead.
### Describe the solution you'd like
Add a new directive `gazelle:python_use_pip_requirement_function` (or similar name) that accepts 3 values:
+ **`false` (the default):** Use library labels directly. Same as current behavior.
+ **`true`:** Use `requirement("library")`
+ **`DEFAULT` or `RESET`:** reset to the default as defined by `rules_python`.
Example:
```starlark
# no directive set. Use labels directly.
py_library(
...,
deps = ["@pip_parse_name//boto3"],
)
# gazelle:python_use_pip_requirement_function false
py_library(
...,
deps = ["@pip_parse_name//boto3"],
)
# gazelle:python_use_pip_requirement_function true
load("@pip_parse_name//:requirements.bzl", "requirement")
py_library(
...,
deps = [requirement("boto3")],
)
# gazelle:python_use_pip_requirement_function DEFAULT
py_library(
...,
deps = ["@pip_parse_name//boto3"],
)
```
### Describe alternatives you've considered
None 🙃. I'm happy to hear some though.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách xác định phần tạo dependency Python của Gazelle và cách requirements.bzl được tích hợp. Xem lại cách xử lý directive hiện có và việc tạo dependency-label trước khi quyết định thiết lập theo từng package nên nằm ở đâu. Hoàn thành khi directive hỗ trợ true, false và hành vi reset được yêu cầu, với coverage cho các label được tạo, các lệnh gọi requirement() và câu lệnh load.
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
- 35/100