Skip to content

Commit d37082d

Browse files
committed
update
1 parent 694c11f commit d37082d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

gazelle/python/resolve.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ func (*Resolver) Name() string { return languageName }
5555
// If nil is returned, the rule will not be indexed. If any non-nil slice is
5656
// returned, including an empty slice, the rule will be indexed.
5757
func (py *Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec {
58-
// To avoid multiple labels indexing the same import,
59-
// check if there is a corresponding py_library rule with the same srcs.
60-
if r.Kind() == "py_binary" && !indexPyBinaryImport(r, f) {
58+
if !indexPyBinaryImport(r, f) {
6159
return nil
6260
}
6361
cfgs := c.Exts[languageName].(pythonconfig.Configs)
@@ -323,7 +321,14 @@ func convertDependencySetToExpr(set *treeset.Set) bzl.Expr {
323321
return &bzl.ListExpr{List: deps}
324322
}
325323

324+
// indexPyBinaryImport returns whether the corresponding py_binary rule need to be indexed.
325+
// To avoid multiple labels indexing the same import,
326+
// check if there is a corresponding py_library rule with the same srcs.
326327
func indexPyBinaryImport(r *rule.Rule, f *rule.File) bool {
328+
// If the rule is not a py_binary, it should be indexed.
329+
if r.Kind() != "py_binary" {
330+
return true
331+
}
327332
pyBinarySrcs := r.AttrStrings("srcs")
328333
if len(pyBinarySrcs) == 0 {
329334
return false

0 commit comments

Comments
 (0)