Skip to content

Commit aaef244

Browse files
committed
Update
1 parent 480e327 commit aaef244

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

gazelle/python/generate.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
123123
pyFileNames.Add(f)
124124
if !hasPyBinaryEntryPointFile && f == pyBinaryEntrypointFilename {
125125
hasPyBinaryEntryPointFile = true
126+
pyLibraryFilenames.Add(f)
126127
} else if !hasPyTestEntryPointFile && f == pyTestEntrypointFilename {
127128
hasPyTestEntryPointFile = true
128129
} else if f == conftestFilename {
@@ -247,9 +248,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
247248

248249
// Remove the file from srcs if we're doing per-file library generation so
249250
// that we don't also generate a py_library target for it.
250-
if cfg.PerFileGeneration() {
251-
srcs.Remove(name)
252-
}
251+
// if cfg.PerFileGeneration() {
252+
// srcs.Remove(name)
253+
// }
253254
}
254255
sort.Strings(mainFileNames)
255256
for _, filename := range mainFileNames {
@@ -352,6 +353,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
352353
collisionErrors.Add(err)
353354
}
354355

356+
// Create the py_binary target that depends on the py_library
355357
pyBinaryTarget := newTargetBuilder(pyBinaryKind, pyBinaryTargetName, pythonProjectRoot, args.Rel, pyFileNames).
356358
setMain(pyBinaryEntrypointFilename).
357359
addVisibility(visibility).

gazelle/python/resolve.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +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-
if !indexPyBinaryImport(r, f) {
58+
if r.Kind() == "py_binary" {
5959
return nil
6060
}
6161
cfgs := c.Exts[languageName].(pythonconfig.Configs)
@@ -369,29 +369,3 @@ func convertDependencySetToExpr(set *treeset.Set) bzl.Expr {
369369
}
370370
return &bzl.ListExpr{List: deps}
371371
}
372-
373-
// indexPyBinaryImport returns whether the corresponding py_binary rule need to be indexed.
374-
// To avoid multiple labels indexing the same import,
375-
// check if there is a corresponding py_library rule with the same srcs.
376-
func indexPyBinaryImport(r *rule.Rule, f *rule.File) bool {
377-
// If the rule is not a py_binary, it should be indexed.
378-
if r.Kind() != "py_binary" {
379-
return true
380-
}
381-
pyBinarySrcs := r.AttrStrings("srcs")
382-
if len(pyBinarySrcs) == 0 {
383-
return false
384-
}
385-
for _, otherRule := range f.Rules {
386-
if otherRule.Kind() != "py_library" {
387-
continue
388-
}
389-
pyLibrarySrcs := otherRule.AttrStrings("srcs")
390-
for _, src := range pyLibrarySrcs {
391-
if src == pyBinarySrcs[0] {
392-
return false
393-
}
394-
}
395-
}
396-
return true
397-
}

0 commit comments

Comments
 (0)