Uploaded image for project: 'Funtoo Linux'
  1. Funtoo Linux
  2. FL-10934

Many autogens broken due to upstream packaging.version change

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Important (Ebuild) Important (Ebuild)
    • None
    • None
    • None

      There are many autogens broken due to an upstream packaging.version change. Packaging is a third-party python module, although it is pretty much a "core" module for Python.

      Recently, the primary maintainer of packaging decided to start throwing InvalidVersion exceptions whenever version.parse() or the Version() constructor encounters a version it can't parse. This was previously not the case.

      This actual breakage occurred on December 7, 2022's release of packaging 22.

      Any autogens with code similar to this are at risk of failing:

      sorted_list = sorted(tuple_list, key=lambda tup: version.parse(tup[1]))

      The whole sorted() thing is not a good idea in general practice because while terse, it doesn't allow for proper exception handling in the lambda. Any invalid version in tup[1] will result in the entire autogen failing. This code relies on packaging.version handling any arbitrary string you throw at it – this is no longer the case. It now throws exceptions.

      You will probably want to write something like this instead:

             # Do NOT use sorted() below. We need to catch individual exceptions below:
             unsorted_list = []
             for url, v_str in tuple_list:
                     try:
                             v_obj = version.parse(v_str)
                     except version.InvalidVersion:
                             pass
                     unsorted_list.append((url, v_str, v_obj))
             sorted_list = sorted(unsorted_list, key=lambda tup: tup[2]) 

      The offending decision upstream was to fundamentally change their API by deprecating LegacyVersion. Previously to version 22, any unrecognized version would still return a LegacyVersion object, which would be sorted to be "less than" any recognized version. Now, the InvalidVersion exception is simply thrown.

      Due to the unstable nature of packaging upstream API, it may make sense to put some helper functions in metatools which are used instead of directly using this python module.

            drobbins drobbins
            drobbins drobbins
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: