I am trying to set up a simple Python repository based on these instructions.
I have created the required directory structure, but pip
won't find any versions. After looking deeper into the topic and referring to PEP 503 - Simple Repository API I found out that the structure of the automatically generated HTML site should be:
<!DOCTYPE html>
<html>
<body>
<a href="/frob/">frob</a>
<a href="/spamspamspam/">spamspamspam</a>
</body>
</html>
The same PEP also says:
The text of the anchor tag MUST be the normalized name of the project and the href attribute MUST link to the URL for that particular project.
In my case it looks like that:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /</title>
</head>
<body>
<h1>Index of /</h1>
<ul><li><a href="packet_name/"> packet_name/</a></li>
</ul>
</body></html>
Note the whitespace in the beginning and slash at the end of the <a>
tag. It is
<a href="packet_name/"> packet_name/</a>
but should be
<a href="packet_name/">packet_name</a>
The .htaccess file currently looks like this:
Options +Indexes
IndexOptions SuppressColumnSorting -FancyIndexing
IndexIgnore ..
Is there a way to instruct Apache to serve a directory layout as required by PEP 503?
Turns out that not the format of the link was the problem, but the normalized folder structure. PEP 503 expects the folder on the root level to be normalized. Consider the name of the project to be foo_bar
. Then, the directory layout must be:
.
|- foo-bar
|-- foo_bar-0.1.tar.gz
Note that the folder got "normalized" by replacing the ., -, or _
characters with a single -
. Afterwards the .htaccess
file and the autogenerated index works just fine.
This is the relevant part of PEP 503:
is PEP references the concept of a "normalized" project name. As per PEP 426 the only valid characters in a name are the ASCII alphabet, ASCII numbers, ., -, and _. The name should be lowercased with all runs of the characters ., -, or _ replaced with a single - character. This can be implemented in Python with the re module: