Skip to content

Commit

Permalink
Normalize package names
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Jan 19, 2024
1 parent 989c4dc commit 055d258
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/backends/python/gen_pypi_map/gen_pypi_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func cmd_test(args []string) {
return
}
fmt.Printf("Loaded %v stats\n", len(bqCache))
normalizedBqCache := make(map[string]int)

for name, count := range bqCache {
normalizedBqCache[normalizePackageName(name)] = count
}
bqCache = normalizedBqCache

packageList := []string{}
for pkgName, count := range bqCache {
if count < *testThreshold {
Expand Down
17 changes: 17 additions & 0 deletions internal/backends/python/gen_pypi_map/package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"regexp"
"strings"
)

var normalizationPattern = regexp.MustCompile(`[-_.]+`)

// normalizePackageName implements NormalizePackageName for the Python
// backends.
// See https://packaging.python.org/en/latest/specifications/name-normalization/
func normalizePackageName(name string) string {
name = strings.ToLower(name)
name = normalizationPattern.ReplaceAllString(name, "-")
return name
}

0 comments on commit 055d258

Please sign in to comment.