bazel-contrib / bazel-contrib/rules_python
Gazelle: Presence of `__main__.py` prevents other `*.py` files from being mapped as `py_binary` targets
- 主要言語
- Starlark
- スター
- 688
- フォーク
- 721
- 平均マージ
- 15時間 7分
- マージ済み PR(30日)
- 76
説明
# 🐞 bug report
### Affected Rule
Gazelle
### Is this a regression?
Still checking
### Description
Presence of `__main__.py` prevents other `*.py` files from being mapped as `py_binary` targets.
## 🔬 Minimal Reproduction
Add one file to `gazelle/python/testdata/per_file`:
```python
# gazelle/python/testdata/per_file/my_binary.py
if __name__ == "__main__":
print("hey")
```
Run the test (from the `gazelle/` dir) `bazel test //python:python_test_per_file` and see that a `py_binary` target is added. So far so good!
Now add a `__main__.py` file, no content needed: `touch gazelle/python/testdata/per_file/__main__.py`
And run the test again. You'll see that `my_binary.py` was incorrectly added as a `py_library` target.
## Other
This is the "correct" `BUILD.out` file:
```diff
--- a/gazelle/python/testdata/per_file/BUILD.out
+++ b/gazelle/python/testdata/per_file/BUILD.out
@@ -1,4 +1,4 @@
-load("@rules_python//python:defs.bzl", "py_library", "py_test")
+load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
# gazelle:python_generation_mode file
@@ -23,6 +23,19 @@ py_library(
deps = [":custom"],
)
+py_binary(
+ name = "my_binary",
+ srcs = ["my_binary.py"],
+ visibility = ["//:__subpackages__"],
+)
+
+py_binary(
+ name = "per_file_bin",
+ srcs = ["__main__.py"],
+ main = "__main__.py",
+ visibility = ["//:__subpackages__"],
+)
+
py_test(
name = "bar_test",
srcs = ["bar_test.py"],
```
コントリビューションガイド
調査の方向性
Start by running bazel test //python:python_test_per_file from the gazelle/ directory, using gazelle/python/testdata/per_file and its BUILD.out expectation as the fixture. Compare the output with and without __main__.py, then update the relevant Gazelle behavior and test expectation so my_binary.py remains a py_binary and the __main__.py target is also generated correctly.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- build-system
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 55/100