Skip to content

Conversation

@romanroibu
Copy link
Contributor

This PR ensures all comparisons of version numbers are done with parsed version strings, and using the best practices.

@romanroibu romanroibu changed the base branch from master to develop August 24, 2020 07:24
@romanroibu
Copy link
Contributor Author

@papr @pfaion There is an open question: version_utils is using distutils.version for parsing version strings, but pupil_recording is using packaging.version internally to parse and compare version strings. Which one of these do we want to choose and use everywhere?

@papr
Copy link
Contributor

papr commented Aug 24, 2020

Please use packaging.version.parse

@romanroibu romanroibu marked this pull request as ready for review August 25, 2020 07:37
@romanroibu romanroibu requested review from papr and pfaion and removed request for pfaion August 25, 2020 07:37
Copy link
Contributor

@pfaion pfaion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@papr why do we use packaging.version.parse instead of packaging.version.Version?
It feels like the special case with LegacyVersions being sorted strictly below Version could potentially cause headaches. Are there any versions in our ecosystem that are not PEP440 compatible?

@romanroibu romanroibu requested a review from pfaion August 26, 2020 13:05
Copy link
Contributor

@pfaion pfaion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romanroibu I'm honestly not sure, if SemanticVersion is a better name here.
This strongly suggests versioning according to the Semantic Versioning scheme, but this is specifically not the case here as packaging.version.parse() will strictly order non-PEP440-compliant < PEP440-compliant, which is not the case for "semantic versions".

@pfaion
Copy link
Contributor

pfaion commented Aug 26, 2020

Specifically, Semantic Versioning is not fully compatible with PEP440: https://www.python.org/dev/peps/pep-0440/#semantic-versioning

@romanroibu
Copy link
Contributor Author

I also considered PupilVersion, but that didn't seem better since it's confusing without an explanation; it's similar reasoning to why I think Version is a bad name. I agree that Semantic Version as a name means a specific format, but it seemed the closest to what this is - which is a formatted version that caries specific meaning and can be compared. If you can think of better names, please let me know.

@romanroibu
Copy link
Contributor Author

I'd be open to calling it PEP440Version, but as @papr mentioned, not all of the versions we're using are PEP440-compatible.

@pfaion
Copy link
Contributor

pfaion commented Aug 26, 2020

I agree nothing is optimal here. I'm still angry at the Python folks for making PEP440 essentially a subset of SemVer, thereby creating so many problems. At least we are not creating our own versioning scheme again but rely on the result of packaging's parse(), which is at least well defined.

For this reason, I also don't like PupilVersion, because it exactly sounds like we built our own versioning scheme.

For simplicity, I'd probably favor Version and put a comment explaining or referencing the packaging parse() format nearby. So if someone is confused (which probably cannot be avoided anyways when talking about versioning schemes in Python), they can at least find information when looking up the definition.

@pfaion
Copy link
Contributor

pfaion commented Aug 26, 2020

It's sad that parse() outputs such a weird scheme again, as you would have to come up with something like PEP440VersionWithLegacyFallback to describe it appropriately. But if we really only use this one version type inside of Pupil, I think just calling it Version is fine, as we don't need to differentiate between different version schemes (hopefully).

@papr
Copy link
Contributor

papr commented Aug 31, 2020

How about ParsedVersion? This would make it easy to find, differentiates from packaging.version.Version, indicates that it is the output of parse(), and does not make any assumptions about the actual type of version it contains.

@pfaion
Copy link
Contributor

pfaion commented Sep 1, 2020

I'd be fine with ParsedVersion, although I'd still prefer simply Version as long as we're not working with multiple different versioning formats in parallel.

I mean either you don't think about it at all if you come across it and assume PEP440 (which will just work fine), or you are aware of the hassle in Python and look at where Version is imported from and you will immediately find the necessary information. Calling it ParsedVersion might make you look up what this is about either way, which might or might not be what we want 😄

@romanroibu romanroibu requested a review from pfaion September 1, 2020 07:58
@papr papr merged commit cf82cf3 into develop Sep 1, 2020
@papr papr deleted the better-version-comparison branch September 1, 2020 08:17
@pfaion
Copy link
Contributor

pfaion commented Sep 17, 2020

This PR requires having the packaging library at version >= 20.0, otherwise, you get the following error on Windows and macOS:

_pickle.PicklingError: Can't pickle <class 'packaging._structures.Infinity'>: it's not the same object as packaging._structures.Infinity

If you got this error, please update packaging with:

pip install -U packaging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants