bazel-contrib / bazel-contrib/rules_python

(feat request) Add a gazelle directive for using `requirement()` for pip-installable dependencies

オープン
#1,789 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る
Can Close? gazelle
主要言語
Starlark
スター
688
フォーク
721
平均マージ
15時間 7分
マージ済み PR(30日)
76

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start by locating Gazelle's Python dependency generation and how requirements.bzl is integrated. Review the existing directive handling and dependency-label generation before deciding where the per-package setting belongs. Done means the directive supports true, false, and the requested reset behavior, with coverage for generated labels, requirement() calls, and the load statement.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
build-system
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。