Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Gazelle not raising error when a target py_test exists in place of a py_binary

オープン
#3,603 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
38

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazel-contrib/rules_python のほかの issue

bazel-contrib/rules_python の issue をすべて見る

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

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