Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 21 additions & 20 deletions internal/pypi/pypi.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (r *Registry) URLs() core.URLBuilder { //nolint:ireturn
}

type packageResponse struct {
Info infoBlock `json:"info"`
Releases map[string][]releaseFile `json:"releases"`
Info infoBlock `json:"info"`
Releases map[string][]releaseFile `json:"releases"`
}

type infoBlock struct {
Expand All @@ -71,15 +71,15 @@ type infoBlock struct {
}

type releaseFile struct {
Digests map[string]string `json:"digests"`
URL string `json:"url"`
UploadTime string `json:"upload_time"`
Yanked bool `json:"yanked"`
YankedReason string `json:"yanked_reason"`
PackageType string `json:"packagetype"`
PythonVersion string `json:"python_version"`
RequiresPython string `json:"requires_python"`
Size int `json:"size"`
Digests map[string]string `json:"digests"`
URL string `json:"url"`
UploadTime string `json:"upload_time"`
Yanked bool `json:"yanked"`
YankedReason string `json:"yanked_reason"`
PackageType string `json:"packagetype"`
PythonVersion string `json:"python_version"`
RequiresPython string `json:"requires_python"`
Size int `json:"size"`
}

type versionInfoResponse struct {
Expand All @@ -101,16 +101,17 @@ func (r *Registry) FetchPackage(ctx context.Context, name string) (*core.Package
homepage := extractHomepage(resp.Info.ProjectURLs, resp.Info.HomePage)

return &core.Package{
Name: strings.ToLower(resp.Info.Name),
Description: resp.Info.Summary,
Homepage: homepage,
Repository: repoURL,
Licenses: extractLicense(resp.Info),
Keywords: parseKeywords(resp.Info.Keywords),
Name: strings.ToLower(resp.Info.Name),
Description: resp.Info.Summary,
Homepage: homepage,
Repository: repoURL,
Licenses: extractLicense(resp.Info),
Keywords: parseKeywords(resp.Info.Keywords),
LatestVersion: resp.Info.Version,
Metadata: map[string]any{
"classifiers": resp.Info.Classifiers,
"documentation": resp.Info.ProjectURLs["Documentation"],
"normalized_name": normalizeName(resp.Info.Name),
"classifiers": resp.Info.Classifiers,
"documentation": resp.Info.ProjectURLs["Documentation"],
"normalized_name": normalizeName(resp.Info.Name),
},
}, nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/pypi/pypi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestFetchPackage(t *testing.T) {
Summary: "Python HTTP for Humans.",
License: "Apache 2.0",
HomePage: "https://requests.readthedocs.io",
Version: "2.31.0",
Keywords: "http,web,client",
ProjectURLs: map[string]string{
"Source": "https://github.com/psf/requests",
Expand Down Expand Up @@ -63,6 +64,9 @@ func TestFetchPackage(t *testing.T) {
if len(pkg.Keywords) != 3 {
t.Errorf("expected 3 keywords, got %d", len(pkg.Keywords))
}
if pkg.LatestVersion != "2.31.0" {
t.Errorf("expected latest version '2.31.0', got %q", pkg.LatestVersion)
}
}

func TestFetchPackageEscapesName(t *testing.T) {
Expand Down