Skip to content

do not index py_binary unless in file mode #2989

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 5 additions & 5 deletions gazelle/python/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ var (
buildFilenames = []string{"BUILD", "BUILD.bazel"}
)

func GetActualKindName(kind string, args language.GenerateArgs) string {
if kindOverride, ok := args.Config.KindMap[kind]; ok {
func GetActualKindName(kind string, c *config.Config) string {
if kindOverride, ok := c.KindMap[kind]; ok {
return kindOverride.KindName
}
return kind
Expand Down Expand Up @@ -90,9 +90,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
}
}

actualPyBinaryKind := GetActualKindName(pyBinaryKind, args)
actualPyLibraryKind := GetActualKindName(pyLibraryKind, args)
actualPyTestKind := GetActualKindName(pyTestKind, args)
actualPyBinaryKind := GetActualKindName(pyBinaryKind, args.Config)
actualPyLibraryKind := GetActualKindName(pyLibraryKind, args.Config)
actualPyTestKind := GetActualKindName(pyTestKind, args.Config)

pythonProjectRoot := cfg.PythonProjectRoot()

Expand Down
5 changes: 5 additions & 0 deletions gazelle/python/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (*Resolver) Name() string { return languageName }
func (py *Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec {
cfgs := c.Exts[languageName].(pythonconfig.Configs)
cfg := cfgs[f.Pkg]
if !cfg.PerFileGeneration() && GetActualKindName(r.Kind(), c) == pyBinaryKind {
// Don't index py_binary in except in file mode, because all non-test Python files
// are in py_library already.
return nil
}
srcs := r.AttrStrings("srcs")
provides := make([]resolve.ImportSpec, 0, len(srcs)+1)
for _, src := range srcs {
Expand Down