Skip to content

Deprecation warning on recent Python versions #36

Open

Description

@doccaz

Users are getting this warning on newer Python versions:

$ ./vercheck.py -l
./vercheck.py:13: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.version import LooseVersion

This is due to PEP 632, which will deprecate the Distutils package in the near future.
We need to re-implement the same features with setuptools.

Activity

  1. added
    enhancement
    on Jul 12, 2024
  2. self-assigned this
    on Jul 12, 2024
  3. doccaz commented on Jul 18, 2024

    @doccaz
    OwnerAuthor

    PEP632 states that you must use the packaging.version.Version() class to substitute the distutils one.
    I made a quick script to read one of vercheck's CSV reports and try out a simple comparison with two versions to validate this:

    #!/usr/bin/python3
    
    import sys
    from distutils.version import LooseVersion
    
    from packaging.version import Version
    
    
    def main():
        
        args = sys.argv
        
        filename = args[1]
        print(f'reading {filename}')
        with open(filename, 'r') as f:
            lines=f.readlines()
            
        versions=[]
        
        for line in lines:
            versions.append([line.split(',')[1], line.split(',')[2]])
            
        try:
            for old,new in versions:
                print(f"comparing if version [{old}] < [{new}])")
                print(f"[distutils]: {LooseVersion(old) < LooseVersion(new)}")
                print(f"[packaging]: {Version(old) < Version(new)}")
        except Exception as e:
            print(f'----> comparison failed: {e}')
        return
        
    if __name__ == '__main__':
        main()
    

    Running it yields not so good results...

    erico@suselab-erico:~/Projetos/scc-tools> ./testversions.py vercheck-different-scc_rmt_231027_1743.csv 
    reading vercheck-different-scc_rmt_231027_1743.csv
    comparing if version [84.87+git20180409.04c9dae-150300.10.3.1] < [84.87+git20180409.04c9dae-150300.10.20.1])
    /home/erico/Projetos/scc-tools/./testversions.py:26: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
      print(f"[distutils]: {LooseVersion(old) < LooseVersion(new)}")
    [distutils]: True
    [packaging]: True
    comparing if version [84.87+git20180409.04c9dae-150300.10.3.1] < [84.87+git20180409.04c9dae-150300.10.20.1])
    [distutils]: True
    [packaging]: True
    comparing if version [3.0.4-150500.11.3.1] < [3.0.4-150500.11.9.1])
    [distutils]: True
    ----> comparison failed: Invalid version: '3.0.4-150500.11.3.1'
    
    

    Apparently packaging.version uses a fixed regex that doesn't recognize the "150500" that SLE uses.
    According to this, you can just override the regex by assigning a new value to packaging.version.VERSION_PATTERN first.

  4. doccaz commented on Jul 18, 2024

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

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions