Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: migrate away from packaging.version.parse #3494

Merged
merged 1 commit into from Oct 9, 2021

Conversation

neutrinoceros
Copy link
Member

@neutrinoceros neutrinoceros commented Aug 31, 2021

PR Summary

Currently, packaging.version.parse_version is implemented as

def parse(version):
    # type: (str) -> Union[LegacyVersion, Version]
    """
    Parse the given version string and return either a :class:`Version` object
    or a :class:`LegacyVersion` object depending on if the given version is
    a valid PEP 440 version or a legacy version.
    """
    try:
        return Version(version)
    except InvalidVersion:
        return LegacyVersion(version)

but LegacyVersion is deprecated since pypa/packaging#342

class LegacyVersion(_BaseVersion):
    def __init__(self, version):
        # type: (str) -> None
        self._version = str(version)
        self._key = _legacy_cmpkey(self._version)

        warnings.warn(
            "Creating a LegacyVersion has been deprecated and will be "
            "removed in the next major release",
            DeprecationWarning,
        )

and the plan for their next release is to have packaging.version.parse basically be an alias for packaging.version.Version.__init__, see pypa/packaging#407

So I'm proposing we move forward with it and stop using the parse function as it may cause confusion in the future and is more complicated to use.
Note that since we're now treating warnings as errors in CI (#3380) means that we can switch with confidence because we know that we don't currently have any such warnings to deal with.

@neutrinoceros neutrinoceros added the enhancement Making something better label Aug 31, 2021
@neutrinoceros
Copy link
Member Author

neutrinoceros commented Aug 31, 2021

A possible alternative is to build our own parse_version function with a fall back mechanism that would return an object with the same important properties as packaging.version.LegacyVersion, i.e. that would always compare as lower than any given valid version, but I think there's no incentive to do that as long as we don't encounter any issue with the current approach

@neutrinoceros neutrinoceros changed the title MNT: migrate away from packaging.version.parse_versio MNT: migrate away from packaging.version.parse Aug 31, 2021
@neutrinoceros
Copy link
Member Author

@meeseeksdev backport to yt-4.0.x

meeseeksmachine pushed a commit to meeseeksmachine/yt that referenced this pull request Nov 6, 2021
neutrinoceros pushed a commit to neutrinoceros/yt that referenced this pull request Nov 7, 2021
MNT: migrate away from packaging.version.parse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making something better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants