Skip to content
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

Sample implementation of lazy indexing #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
29 changes: 29 additions & 0 deletions gazelle/python/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,35 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
os.Exit(1)
}

dirsToIndex := map[string]struct{}{}
for _, r := range result.Gen {
modulesRaw := r.PrivateAttr(config.GazelleImportsKey)
modules := modulesRaw.(*treeset.Set)
it := modules.Iterator()
for it.Next() {
mod := it.Value().(module)
currentDir := ""
parts := strings.Split(mod.Name, ".")
for i := range parts {
if i == 0 {
currentDir = parts[i]
} else {
currentDir = currentDir + "/" + parts[i]
}
dirsToIndex[currentDir] = struct{}{}
}
}
}

dirsToIndex[""] = struct{}{}

toIndex := make([]string, 0, len(dirsToIndex))
for dir := range dirsToIndex {
toIndex = append(toIndex, dir)
}

result.PackagesToIndex = toIndex

return result
}

Expand Down