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

Deprecation warning on recent Python versions #36

Open
doccaz opened this issue Jul 12, 2024 · 3 comments
Open

Deprecation warning on recent Python versions #36

doccaz opened this issue Jul 12, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@doccaz
Copy link
Owner

doccaz commented Jul 12, 2024

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.

@doccaz doccaz added the enhancement New feature or request label Jul 12, 2024
@doccaz doccaz self-assigned this Jul 12, 2024
@doccaz
Copy link
Owner Author

doccaz commented Jul 18, 2024

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.

@doccaz
Copy link
Owner Author

doccaz commented Jul 18, 2024

As expected, the default regex is awfully complex: https://regex101.com/r/ryw6wU/1

@doccaz
Copy link
Owner Author

doccaz commented Jul 29, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant