From 1ea0a5a62798503cc2e031b2d24e7608b97fc445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Wed, 28 Feb 2024 09:51:55 +0100 Subject: [PATCH] Don't use deprecated pkg_resources parse_version from pkg_resources is deprecated. This commit switches to packaging.version.Version. The use of parse_version or packaging.version.Version is not optimal. Any version that is not PEP440 compliant will raise an InvalidVersion exception. Package names at SUSE are NOT PEP440 compliant, for example "apparmor-parser-2.12.2-lp150.6.14.1". For further details see: https://packaging.pypa.io/en/stable/version.html. --- obs_img_utils/api.py | 12 ++++++------ obs_img_utils/web_content.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/obs_img_utils/api.py b/obs_img_utils/api.py index 53407c8..26c6dec 100644 --- a/obs_img_utils/api.py +++ b/obs_img_utils/api.py @@ -26,7 +26,7 @@ from collections import namedtuple from distutils.dir_util import mkpath -from pkg_resources import parse_version +import packaging.version as pv from urllib.error import ContentTooShortError, URLError from obs_img_utils.exceptions import ( @@ -479,15 +479,15 @@ def _version_compare(self, current, expected, condition): current = 'unknown' if condition == '>=': - return parse_version(current) >= parse_version(expected) + return pv.Version(current) >= pv.Version(expected) elif condition == '<=': - return parse_version(current) <= parse_version(expected) + return pv.Version(current) <= pv.Version(expected) elif condition == '==': - return parse_version(current) == parse_version(expected) + return pv.Version(current) == pv.Version(expected) elif condition == '>': - return parse_version(current) > parse_version(expected) + return pv.Version(current) > pv.Version(expected) elif condition == '<': - return parse_version(current) < parse_version(expected) + return pv.Version(current) < pv.Version(expected) else: raise PackageVersionExceptionOBS( 'Invalid version compare expression: "{0}"'.format(condition) diff --git a/obs_img_utils/web_content.py b/obs_img_utils/web_content.py index 20341c6..fb5a4ef 100644 --- a/obs_img_utils/web_content.py +++ b/obs_img_utils/web_content.py @@ -27,7 +27,7 @@ urlopen, Request ) -from pkg_resources import parse_version +import packaging.version as pv class WebContent(object): @@ -174,7 +174,7 @@ def _pick_highest_version_release(self, possible_filenames, regex): chosen_tuple = (filename, extension) continue - if parse_version(new_version) > parse_version(highest_version): + if pv.Version(new_version) > pv.Version(highest_version): highest_version = new_version chosen_tuple = (filename, extension) return chosen_tuple