Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: Gazelle bug with merging py_binary targets in per-file mode and partial update #2619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Unreleased changes template.
{#v0-0-0-fixed}
### Fixed
* (pypi) The `ppc64le` is now pointing to the right target in the `platforms` package.
* (gazelle) No longer incorrectly merge `py_binary` targets during partial updates in
`file` generation mode. Fixed in [#2619](https://github.com/bazelbuild/rules_python/pull/2619).

{#v0-0-0-added}
### Added
Expand Down
3 changes: 2 additions & 1 deletion gazelle/python/kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (*Python) Kinds() map[string]rule.KindInfo {

var pyKinds = map[string]rule.KindInfo{
pyBinaryKind: {
MatchAny: true,
MatchAny: false,
MatchAttrs: []string{"srcs"},
NonEmptyAttrs: map[string]bool{
"deps": true,
"main": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_python//python:defs.bzl", "py_binary")

# gazelle:python_generation_mode file

py_binary(
name = "a",
srcs = ["a.py"],
visibility = ["//:__subpackages__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@rules_python//python:defs.bzl", "py_binary")

# gazelle:python_generation_mode file

py_binary(
name = "a",
srcs = ["a.py"],
visibility = ["//:__subpackages__"],
)

py_binary(
name = "b",
srcs = ["b.py"],
visibility = ["//:__subpackages__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Partial update with multiple per-file binaries

This test case asserts that when there are multiple binaries in a package, and no __main__.py, and the BUILD file already includes a py_binary for one of the files, a py_binary is generated for the other file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a Bazel workspace for the Gazelle test data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if __name__ == "__main__":
print("Hello, world!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if __name__ == "__main__":
print("Hello, world!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
expect:
exit_code: 0
Loading