Skip to content

Commit

Permalink
Update deprecated pkg_resources to packaging.version
Browse files Browse the repository at this point in the history
  • Loading branch information
rudra-iitm committed Jan 11, 2024
1 parent 56a447e commit 217b35f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions updatesnap/SnapModule/snapmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import requests
import yaml

import pkg_resources
import packaging.version
import debian.debian_support


Expand Down Expand Up @@ -121,14 +121,14 @@ def _get_version(self, part_name, entry, entry_format, check):
if not entry.startswith(entry_format['format'].split('%')[0]):
return None
try:
version = pkg_resources.parse_version(
version = packaging.version.parse(
entry[len(entry_format['format'].split('%')[0]):])
if (("lower-than" in entry_format) and
(version >= pkg_resources.parse_version(
(version >= packaging.version.parse(
str(entry_format["lower-than"])))):
return None
return version
except pkg_resources.extern.packaging.version.InvalidVersion:
except packaging.version.InvalidVersion:
version = debian.debian_support.Version(
entry[len(entry_format['format'].split('%')[0]):])
if (("lower-than" in entry_format) and
Expand Down Expand Up @@ -159,12 +159,12 @@ def _get_version(self, part_name, entry, entry_format, check):
if not entry.startswith(part):
return None
entry = entry[len(part):]
version = pkg_resources.parse_version(f"{major}.{minor}.{revision}")
version = packaging.version.parse(f"{major}.{minor}.{revision}")

if "ignore-version" in entry_format:
to_ignore = entry_format["ignore-version"]
if isinstance(to_ignore, str):
if version == pkg_resources.parse_version(to_ignore):
if version == packaging.version.parse(to_ignore):
return None
elif isinstance(to_ignore, list):
for ignore_version in to_ignore:
Expand All @@ -173,7 +173,7 @@ def _get_version(self, part_name, entry, entry_format, check):
"contains an element that is not a string.")
self._print_error(part_name, self._colors.critical, message)
raise ValueError(message)
if version == pkg_resources.parse_version(ignore_version):
if version == packaging.version.parse(ignore_version):
return None
else:
message = (f"The 'ignore-version' entry in {part_name} is neither a string, "
Expand All @@ -182,7 +182,7 @@ def _get_version(self, part_name, entry, entry_format, check):
raise ValueError(message)

if (("lower-than" in entry_format) and
(version >= pkg_resources.parse_version(str(entry_format["lower-than"])))):
(version >= packaging.version.parse(str(entry_format["lower-than"])))):
return None
if self._checkopt("ignore-odd-minor", entry_format) and ((minor % 2) == 1):
return None
Expand Down

0 comments on commit 217b35f

Please sign in to comment.