@@ -55,9 +55,7 @@ func (*Resolver) Name() string { return languageName }
55
55
// If nil is returned, the rule will not be indexed. If any non-nil slice is
56
56
// returned, including an empty slice, the rule will be indexed.
57
57
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 ) {
61
59
return nil
62
60
}
63
61
cfgs := c .Exts [languageName ].(pythonconfig.Configs )
@@ -323,7 +321,14 @@ func convertDependencySetToExpr(set *treeset.Set) bzl.Expr {
323
321
return & bzl.ListExpr {List : deps }
324
322
}
325
323
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.
326
327
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
+ }
327
332
pyBinarySrcs := r .AttrStrings ("srcs" )
328
333
if len (pyBinarySrcs ) == 0 {
329
334
return false
0 commit comments