Skip to content

Commit

Permalink
Fix links in PyPI Simple Repository API page (#30594) (#30612)
Browse files Browse the repository at this point in the history
Backport #30594 by wxiaoguang

Thanks to @Zottelchen for looking into problem and proposing the fix.

Ref: astral-sh/uv#3017 ,
https://peps.python.org/pep-0503/

This PR's change is from Zottelchen's work.

And I by the way rename the `$p` to `$pd` because `p` is used as
"package" in code, while `pd` is used as "package description".

----

Co-authored-by: Zottelchen

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
GiteaBot and wxiaoguang committed Apr 20, 2024
1 parent 60f0493 commit b4e1874
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions templates/api/packages/pypi/simple.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<title>Links for {{.PackageDescriptor.Package.Name}}</title>
</head>
<body>
{{- /* PEP 503Simple Repository API: https://peps.python.org/pep-0503/ */ -}}
<h1>Links for {{.PackageDescriptor.Package.Name}}</h1>
{{range .PackageDescriptors}}
{{$p := .}}
{{$pd := .}}
{{range .Files}}
<a href="{{$.RegistryURL}}/files/{{$p.Package.LowerName}}/{{$p.Version.Version}}/{{.File.Name}}#sha256-{{.Blob.HashSHA256}}"{{if $p.Metadata.RequiresPython}} data-requires-python="{{$p.Metadata.RequiresPython}}"{{end}}>{{.File.Name}}</a><br>
<a href="{{$.RegistryURL}}/files/{{$pd.Package.LowerName}}/{{$pd.Version.Version}}/{{.File.Name}}#sha256={{.Blob.HashSHA256}}"{{if $pd.Metadata.RequiresPython}} data-requires-python="{{$pd.Metadata.RequiresPython}}"{{end}}>{{.File.Name}}</a><br>
{{end}}
{{end}}
</body>
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api_packages_pypi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestPackagePyPI(t *testing.T) {
nodes := htmlDoc.doc.Find("a").Nodes
assert.Len(t, nodes, 2)

hrefMatcher := regexp.MustCompile(fmt.Sprintf(`%s/files/%s/%s/test\..+#sha256-%s`, root, regexp.QuoteMeta(packageName), regexp.QuoteMeta(packageVersion), hashSHA256))
hrefMatcher := regexp.MustCompile(fmt.Sprintf(`%s/files/%s/%s/test\..+#sha256=%s`, root, regexp.QuoteMeta(packageName), regexp.QuoteMeta(packageVersion), hashSHA256))

for _, a := range nodes {
for _, att := range a.Attr {
Expand Down

0 comments on commit b4e1874

Please sign in to comment.