Skip to content

Commit

Permalink
Sample implementation of lazy indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-torok committed Aug 26, 2024
1 parent 2f46873 commit 8ec3e6f
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 8ec3e6f

Please sign in to comment.