Skip to content

Commit

Permalink
Add a lower bound to the modules we accumulate
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Jan 24, 2024
1 parent 5f16c3a commit a27837e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/backends/python/gen_pypi_map/install_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func InstallDiff(metadata PackageData) ([]string, error) {
return nil, err
}

var fewestSlashes *int
modules := make(map[string]bool)
filepath.WalkDir(root, func(fpath string, entry os.DirEntry, err error) error {
if err != nil {
Expand All @@ -87,7 +88,17 @@ func InstallDiff(metadata PackageData) ([]string, error) {
}
relpath = strings.TrimSuffix(relpath, string(filepath.Separator))
module := strings.ReplaceAll(relpath, string(filepath.Separator), ".")
modules[module] = true

// Do our best to find the lowest-common module root to avoid ballooning search space
// A good example of this is flask-mysql, which installs into flaskext.mysql
currentSlashes := strings.Count(relpath, string(filepath.Separator))
if fewestSlashes == nil || currentSlashes < *fewestSlashes {
fewestSlashes = &currentSlashes
modules = make(map[string]bool)
modules[module] = true
} else if currentSlashes == *fewestSlashes {
modules[module] = true
}
}
}

Expand Down

0 comments on commit a27837e

Please sign in to comment.