Skip to content

Commit

Permalink
Don't use deprecated pkg_resources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schaefi committed Feb 28, 2024
1 parent 4795937 commit 1ea0a5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions obs_img_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions obs_img_utils/web_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
urlopen,
Request
)
from pkg_resources import parse_version
import packaging.version as pv


class WebContent(object):
Expand Down Expand Up @@ -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

0 comments on commit 1ea0a5a

Please sign in to comment.