Version normalization

Came up in A question about src layout · Discussion #110 · ofek/hatch · GitHub

Should build backends perform any normalization of versions for the names of wheels/sdists/.dist-info directories? Currently I use packaging.utils.canonicalize_version for normalization.

As a thought experiment, say a user defines the version as 1.0.0.0.0. Are we comfortable with using that? If not, do we want that to become 1.0.0? If so, is that only to match SemVer? And so on…

PEP 440 already answers this, doesn’t it? There’s a whole section on normalization. And 1.0.0.0.0 definitely does not become 1.0.0 – PEP 440 versions don’t have any bias to specific numbers of dots.

Got it, thanks. Do package indices like PyPI prevent duplicate uploads of semantically identical but distinct versions?

It definitely performs PEP 440 normalization and at least checks against that, but I’m not an expert and I’m not sure if it actually checks for PEP 440 equivalence of every version, i.e. such that packaging.version.parse(new_version) not in [packaging.version.parse(previous_versions) for previous_version in previous_versions]. I’d suggest trying on TestPyPI with the example you gave.