Skip to content

Commit 42dc456

Browse files
committed
Address comments
1 parent 5ad7d30 commit 42dc456

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

gazelle/python/generate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ func (py *Python) getRulesWithInvalidSrcs(args language.GenerateArgs, validFiles
523523
return strings.HasPrefix(src, "@") || strings.HasPrefix(src, "//") || strings.HasPrefix(src, ":")
524524
}
525525
for _, existingRule := range args.File.Rules {
526-
if existingRule.Kind() != pyBinaryKind {
526+
actualPyBinaryKind := GetActualKindName(pyBinaryKind, args)
527+
if existingRule.Kind() != actualPyBinaryKind {
527528
continue
528529
}
529530
var hasValidSrcs bool
@@ -538,7 +539,7 @@ func (py *Python) getRulesWithInvalidSrcs(args language.GenerateArgs, validFiles
538539
}
539540
}
540541
if !hasValidSrcs {
541-
invalidRules = append(invalidRules, newTargetBuilder(existingRule.Kind(), existingRule.Name(), args.Config.RepoRoot, args.Rel, nil, false).build())
542+
invalidRules = append(invalidRules, newTargetBuilder(pyBinaryKind, existingRule.Name(), "", "", nil, false).build())
542543
}
543544
}
544545
return invalidRules

gazelle/python/kinds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var pyKinds = map[string]rule.KindInfo{
4646
SubstituteAttrs: map[string]bool{},
4747
MergeableAttrs: map[string]bool{
4848
"srcs": true,
49+
"imports": true,
4950
},
5051
ResolveAttrs: map[string]bool{
5152
"deps": true,

gazelle/python/testdata/remove_invalid_binary/BUILD.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ py_library(
77
py_binary(
88
name = "remove_invalid_binary",
99
srcs = ["__main__.py"],
10+
imports = ["."],
11+
data = ["testdata/test.txt"],
1012
visibility = ["//:__subpackages__"],
1113
)

gazelle/python/testdata/respect_kind_mapping/BUILD.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@rules_python//python:defs.bzl", "py_library")
22

33
# gazelle:map_kind py_test my_test :mytest.bzl
4+
# gazelle:map_kind py_binary my_bin :mytest.bzl
45

56
py_library(
67
name = "respect_kind_mapping",
@@ -13,3 +14,8 @@ my_test(
1314
main = "__test__.py",
1415
deps = [":respect_kind_mapping"],
1516
)
17+
18+
my_bin(
19+
name = "my_bin_gets_removed",
20+
srcs = ["__main__.py"],
21+
)

gazelle/python/testdata/respect_kind_mapping/BUILD.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@rules_python//python:defs.bzl", "py_library")
22
load(":mytest.bzl", "my_test")
33

44
# gazelle:map_kind py_test my_test :mytest.bzl
5+
# gazelle:map_kind py_binary my_bin :mytest.bzl
56

67
py_library(
78
name = "respect_kind_mapping",

0 commit comments

Comments
 (0)