Escaping versions for wheel, sdist, and .dist-info names

I just realised that there wasn’t much discussion here of what to do with distribution names, even though we ended up changing the rules there. @uranusjr was in favour of adopting the name normalisation from PEP 503, @pf_moore said “We should clean this up, but it’s not going to happen in this change”… and then the rule based on PEP 503 seems to have slipped in, while we were all focusing on the version part and where the spec lives. :confused:

This has come up because Flit has now implemented the updated spec - where . is translated to _ in the distribution name part of the .whl filename - and clashed with the rules implemented in Warehouse, which don’t allow that.

On the one hand, I think the new version is a clearly better spec in isolation. It gives us one rule for wheel filenames, sdist filenames and .dist-info directory names, and it means you can construct a wheel filename from a (PEP 503) normalised project name or an un-normalised project name and get the same result. On the other hand, it’s not what setuptools/wheel & warehouse currently do.

The change to the spec was merged on the 28th of February, so it’s been there for 9 months. Do we press forward and adapt the software to the spec? Or do we revert that part of the change as a mistake?

For extra complexity, the original spec is kind of ambiguous: the words say you replace “non-alphanumeric characters” with an underscore, which IMO would mean replacing . (".".isalnum() is False). But the code sample that accompanies it specifically exempts . from the regex-based replacement. I imagine we take the code sample as the definitive rule, so this is probably academic.

And another overlooked detail: case normalisation. The current wheel spec says:

In distribution names, any run of -_. characters (HYPHEN-MINUS, LOW LINE and FULL STOP) should be replaced with _ (LOW LINE). This is equivalent to PEP 503 normalisation followed by replacing - with _ .

But it’s not equivalent, because PEP 503 normalisation also includes lower-casing the name, which we missed here.

Honestly, I’d rather we just fixed warehouse and wheel.

It’s a nuisance this happened - and it probably demonstrates that we really shouldn’t accept any changes to a standard without a proper PEP, and a better process to ensure that all affected tools will implement the agreed changes. But where we are now, we’ve basically just got a revised version of the PEP that’s not yet implemented everywhere, which is hardly unusual.

Am I right that the blocker here is warehouse, which is blocking upload of wheels that are now valid under the new rules? If so, has an issue been raised against warehouse to track that, and do we have any idea how big of a problem it will be to make the fix?

1 Like

There’s an issue on Warehouse and even a pull request from @uranusjr.

It appears to be easy to allow the now valid names, with . replaced with _. But we presumably can’t immediately enforce the new normalisation rule in Warehouse, because setuptools/wheel would have to be changed first to make filenames this way. So we might need some extra complexity to prevent uploading two wheels for the same distribution & version with the same tag.