osv.dev icon indicating copy to clipboard operation
osv.dev copied to clipboard

Strange behaviour in PyPI versions

Open rtfpessoa opened this issue 2 years ago • 7 comments

Describe the bug

Strange behaviour in PyPI versions:

ie: in package networkx PyPI has version 3.3 but in deps.dev it is 3.3.0, while for other versions like 1.0-py2.6 it seems to not normalize it to 1.0.0-py2.6, possibly due to it having three . which seems wrong as the version seems to be a valid SemVer with -py2.6 being the pre-release.

Expected behaviour

Ideally I would expect it to support the same exact versions as PyPI. If not, can you explain the reason and how can I follow the same rules?

rtfpessoa avatar Aug 06 '24 12:08 rtfpessoa

@sarnesjo would you be able to speak to how deps.dev handles PyPI versions and normalization?

PyPI allows different version strings to encode the same logical version. For matching PyPI version numbers generally, https://packaging.python.org/en/latest/specifications/version-specifiers/#version-scheme has the details on how to compare them (implemented in https://packaging.pypa.io/en/stable/version.html#packaging.version.Version).

oliverchang avatar Aug 07 '24 00:08 oliverchang

Paul from deps.dev explained why they did this here: https://github.com/google/deps.dev/issues/89

cuixq avatar Aug 07 '24 01:08 cuixq

Thanks @cuixq ! I'll close this since there's an answer there.

oliverchang avatar Aug 07 '24 01:08 oliverchang

PyPI allows different version strings to encode the same logical version. For matching PyPI version numbers generally, https://packaging.python.org/en/latest/specifications/version-specifiers/#version-scheme has the details on how to compare them (implemented in https://packaging.pypa.io/en/stable/version.html#packaging.version.Version).

I am aware about this, just not clear why the API has a different version than the original since for things like keys that leads to strange behaviors.

Thanks for the issue sharing context, will take a look.

rtfpessoa avatar Aug 07 '24 13:08 rtfpessoa

👋 Based on the other thread I got the idea now and I really like that you are considering to keep the original version.

@cuixq, as you probably have more context the only part that is still not clear to me is why 1.0-py2.6 is not parsed with -py2.6 as pre-release. Do you have any reference to this decision?

rtfpessoa avatar Aug 07 '24 13:08 rtfpessoa

@rtfpessoa I think @PFCM has the most context to answer your question, do you mind raising this question with deps.dev instead?

cuixq avatar Aug 08 '24 00:08 cuixq

Hello, I can help with this. The reason why 1.0-py2.6 does not get padded to 1.0.0-py2.6 is because according to https://packaging.python.org/en/latest/specifications/version-specifiers/#pre-releases py2.6 is not a valid pre-release identifier; there's only a very specific set of things which are allowed after the version by the latest rules. The means the version number fails to parse, so as a general policy we tend to fall back to using the exact string.

Depending just how keen you are to get into the details, the code we (deps.dev) use for parsing and normalising is here: https://github.com/google/deps.dev/tree/main/util/semver

PFCM avatar Aug 08 '24 03:08 PFCM