Incorrect max version computation

Bug #2066340 reported by Jeremy Fleischman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pkginfo
Fix Released
Undecided
Tres Seaver

Bug Description

The `MAX_METADATA_VERSION_STR` computation incorrectly assumes that string
version sort is the same as tuple version sort, which is not the case. (Ok,
actually, they are the same for the current set of metadata versions that
pkginfo supports, but this is not true for all possible versions.)

For example, consider a hypthetical future version 2.11:

    $ bzr diff
    === modified file 'pkginfo/distribution.py'
    --- old/pkginfo/distribution.py 2024-05-02 23:55:19 +0000
    +++ new/pkginfo/distribution.py 2024-05-22 04:26:33 +0000
    @@ -86,6 +86,7 @@
         '2.1': HEADER_ATTRS_2_1,
         '2.2': HEADER_ATTRS_2_2,
         '2.3': HEADER_ATTRS_2_3,
    + '2.11': HEADER_ATTRS_2_3,
     }

Note how `MAX_METADATA_VERSION` and `MAX_METADATA_VERSION_STR` are
inconsistent:

    $ python
    >>> from pkginfo import distribution
    >>> distribution.MAX_METADATA_VERSION
    (2, 11)
    >>> distribution.MAX_METADATA_VERSION_STR
    '2.3'

Here's a diff to fix the issue:

    === modified file 'pkginfo/distribution.py'
    --- old/pkginfo/distribution.py 2024-05-02 23:55:19 +0000
    +++ new/pkginfo/distribution.py 2024-05-22 04:37:48 +0000
    @@ -95,12 +95,8 @@
             [int(part) for part in metadata_version.split(".")]
         )

    -METADATA_VERSIONS = [
    - _version_tuple(key) for key in HEADER_ATTRS
    -]
    -
    -MAX_METADATA_VERSION = max(METADATA_VERSIONS)
    -MAX_METADATA_VERSION_STR = max(HEADER_ATTRS.keys())
    +MAX_METADATA_VERSION_STR = max(HEADER_ATTRS.keys(), key=_version_tuple)
    +MAX_METADATA_VERSION = _version_tuple(MAX_METADATA_VERSION_STR)

     class UnknownMetadataVersion(UserWarning):

(I tried really hard to submit this as a merge proposal, but I could not for the life of me figure out how to create a branch on launchpad).

Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in pkginfo:
assignee: nobody → Tres Seaver (tseaver)
status: New → Fix Committed
Revision history for this message
Jeremy Fleischman (jflei) wrote :

Sweet, thanks for the quick fix!

I see in https://bazaar.launchpad.net/~tseaver/pkginfo/trunk/revision/237 we're now round-tripping the version string (string -> tuple -> string). It's not entirely obvious to me that that's correct (but I *think* it is). The only counter example I can think of is a version with some leading 0s (for example, "1.01", which I think would round trip to "1.1"). But that might not be a valid version string in the first place...

Tres Seaver (tseaver)
Changed in pkginfo:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.