Skip to content

Commit

Permalink
Avoid normalizing pip canonical package name
Browse files Browse the repository at this point in the history
Names in requirements.txt are the package as tracked in package metadata, not necessarily the normalized name of the package.

Example: pip install discord-py will add `discord.py` to the output of `pip freeze`.
  • Loading branch information
blast-hardcheese committed Jan 2, 2024
1 parent 7efa451 commit 8e129bc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions internal/backends/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,20 @@ func makePythonPipBackend(python string) api.LanguageBackend {
util.RunCmd([]string{"pip", "install", "-r", "requirements.txt"})
},
ListSpecfile: func() map[api.PkgName]api.PkgSpec {
flags, rawPkgs, err := ListRequirementsTxt("requirements.txt")
flags, pkgs, err := ListRequirementsTxt("requirements.txt")
if err != nil {
util.Die("%s", err.Error())
}

normalizedPkgs := make(map[api.PkgName]api.PkgSpec)
for name, spec := range rawPkgs {
normalizedPkgs[normalizePackageName(name)] = spec
}

// Stash the seen flags into a module global.
// This isn't great, but the expectation is that ListSpecfile
// is called before we run `Add`.
pipFlags = flags

return normalizedPkgs
// NB: We rely on requirements.txt being populated with the
// Python package _metadata_ name, not the PEP-503/PEP-508
// normalized version.
return pkgs
},
GuessRegexps: pythonGuessRegexps,
Guess: func(ctx context.Context) (map[api.PkgName]bool, bool) { return guess(ctx, python) },
Expand Down

0 comments on commit 8e129bc

Please sign in to comment.