Gazelle not raising error when a target py_test exists in place of a py_binary
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- build-system
调研方向
从处理冲突生成目标的 rules_python_gazelle_plugin 入口点开始,使用提供的 lib/demo 复现用例和 bazel run //:gazelle -- -strict -mode fix 命令。将 py_binary 与 py_test 之间的冲突与 py_library 与 py_test 的情况进行比较。完成标准是:py_binary 冲突被报告为错误,并且该命令以状态 1 退出,与另一个冲突保持一致。
由索引模型根据 Issue 内容生成。
描述
🐞 bug report
Affected Rule
rules_python_gazelle_plugin functionality
Is this a regression?
Still needs assessment
Description
When gazelle runs over a BUILD file and finds a py_test target where it wants to make a py_binary target, the gazelle extension flags the conflict, but it does not elevate to an error. This is not the case for other target conflicts. For example, if a py_test exists where a py_library should, a full error is raised and the exit code respects this.
When this conflict happens, no other gazelle edits are recommended for the affected target. Recommendations to other targets proceed as normal.
🔬 Minimal Reproduction
Make a simple tree like
lib/demo/
- example_lib.py
- example_bin.py
- example_test.py
The contents of each are
example_bin.py
from lib.demo import example_lib
def main() -> None:
print("Lib call:", example_lib.some_helper())
if __name__ == "__main__":
main()
example_lib.py
def some_helper() -> int:
return 52
example_test.py
import unittest
from lib.demo import example_lib
def test_thing() -> None:
assert example_lib.some_helper() == 52
if __name__ == "__main__":
unittest.main()
Now make the BUILD file with the following contents
load("@rules_python//python:defs.bzl", "py_library", "py_test")
py_test(
name = "example_bin",
srcs = ["example_bin.py"],
)
py_library(
name = "example_lib",
srcs = ["example_lib.py"],
)
py_test(
name = "example_test",
srcs = ["example_test.py"],
)
Run bazel run //:gazelle -- -strict -mode diff and see the following output
$ bazel run //:gazelle -- -strict -mode fix
(21:34:13) INFO: Current date is 2026-02-16
(21:34:13) INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
(21:34:13) INFO: Found 1 target...
Target //:gazelle up-to-date:
bazel-bin/gazelle-runner.bash
bazel-bin/gazelle
(21:34:13) INFO: Elapsed time: 0.129s, Critical Path: 0.05s
(21:34:13) INFO: 1 process: 4 action cache hit, 1 internal.
(21:34:13) INFO: Build completed successfully, 1 total action
gazelle: failed to generate target "//lib/demo:example_bin" of kind "py_binary": a target of kind "py_test" with the same name already exists
Now notice the difference in error when py_library is converted incorrectly to a py_test.
gazelle: failed to generate target "//lib/demo:example_bin" of kind "py_binary": a target of kind "py_test" with the same name already exists
gazelle: ERROR: failed to generate target "//lib/demo:example_lib" of kind "py_library": a target of kind "py_test" with the same name already exists. Use the '# gazelle:python_library_naming_convention' directive to change the naming convention.
The details are the same, but the latter scenario is reflected in the exit code with a value of 1.
🌍 Your Environment
Operating System:
debian linux
Output of bazel version:
8.4.2
Rules_python version:
1.8.3
- 主要语言
- Starlark
- 星标
- 690
- 派生
- 722
- 平均合并
- 1 天 55 分钟
- 30 天内合并 PR
- 38
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazel-contrib/rules_python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
bazel-contrib/rules_python#4179 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
bazel-contrib/rules_python#4164 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
bazel-contrib/rules_python#3821 ·
-
难度 3/5 1-2 天 新手友好度 45/100
bazel-contrib/rules_python#4181 ·
-
Release 2.4.0 未关闭type: release
难度 4/5 3-5 天 新手友好度 25/100
bazel-contrib/rules_python#4175 · 3 条评论 ·
查看 bazel-contrib/rules_python 的全部 Issue
相似的 Issue
-
Name consistency 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
eellak/triplestore#65 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
-
area-Bzlmod team-ExternalDeps type: bug untriaged
难度 2/5 1-3 小时 新手友好度 65/100
bazelbuild/bazel#31291 · 2 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
bradcypert/plum#53 ·