Skip to content

Commit

Permalink
Use packaging.version instead of pkg_resources (sezanzeb#966)
Browse files Browse the repository at this point in the history
pkg_resources is deprecated, this removes one set of uses.

Signed-off-by: Stephen Kitt <steve@sk2.org>
  • Loading branch information
skitt authored Oct 5, 2024
1 parent 7586ad9 commit cf01699
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 2 additions & 4 deletions inputremapper/configs/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import enum
from collections import namedtuple
from packaging import version
from typing import Optional, Callable, Tuple, TypeVar, Union, Any, Dict

import pkg_resources
from evdev.ecodes import (
EV_KEY,
EV_ABS,
Expand Down Expand Up @@ -84,9 +84,7 @@
# TODO: remove pydantic VERSION check as soon as we no longer support
# Ubuntu 20.04 and with it the ancient pydantic 1.2

needs_workaround = pkg_resources.parse_version(
str(VERSION)
) < pkg_resources.parse_version("1.7.1")
needs_workaround = version.parse(str(VERSION)) < version.parse("1.7.1")


EMPTY_MAPPING_NAME: str = _("Empty Mapping")
Expand Down
22 changes: 11 additions & 11 deletions inputremapper/configs/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import re
import shutil
from pathlib import Path
from packaging import version
from typing import Iterator, Tuple, Dict, List

import pkg_resources
from evdev.ecodes import (
EV_KEY,
EV_ABS,
Expand Down Expand Up @@ -86,15 +86,15 @@ def config_version():
config_path = os.path.join(CONFIG_PATH, "config.json")

if not os.path.exists(config_path):
return pkg_resources.parse_version("0.0.0")
return version.parse("0.0.0")

with open(config_path, "r") as file:
config = json.load(file)

if "version" in config.keys():
return pkg_resources.parse_version(config["version"])
return version.parse(config["version"])

return pkg_resources.parse_version("0.0.0")
return version.parse("0.0.0")


def _config_suffix():
Expand Down Expand Up @@ -481,27 +481,27 @@ def migrate():

v = config_version()

if v < pkg_resources.parse_version("0.4.0"):
if v < version.parse("0.4.0"):
_config_suffix()
_preset_path()

if v < pkg_resources.parse_version("1.2.2"):
if v < version.parse("1.2.2"):
_mapping_keys()

if v < pkg_resources.parse_version("1.4.0"):
if v < version.parse("1.4.0"):
global_uinputs.prepare_all()
_add_target()

if v < pkg_resources.parse_version("1.4.1"):
if v < version.parse("1.4.1"):
_otherwise_to_else()

if v < pkg_resources.parse_version("1.5.0"):
if v < version.parse("1.5.0"):
_remove_logs()

if v < pkg_resources.parse_version("1.6.0-beta"):
if v < version.parse("1.6.0-beta"):
_convert_to_individual_mappings()

# add new migrations here

if v < pkg_resources.parse_version(VERSION):
if v < version.parse(VERSION):
_update_version()
6 changes: 3 additions & 3 deletions tests/unit/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import unittest
import shutil
import json
import pkg_resources
from packaging import version

from evdev.ecodes import (
EV_KEY,
Expand Down Expand Up @@ -380,7 +380,7 @@ def test_add_version(self):
file.write("{}")

migrate()
self.assertEqual(pkg_resources.parse_version(VERSION), config_version())
self.assertEqual(version.parse(VERSION), config_version())

def test_update_version(self):
path = os.path.join(CONFIG_PATH, "config.json")
Expand All @@ -389,7 +389,7 @@ def test_update_version(self):
json.dump({"version": "0.1.0"}, file)

migrate()
self.assertEqual(pkg_resources.parse_version(VERSION), config_version())
self.assertEqual(version.parse(VERSION), config_version())

def test_config_version(self):
path = os.path.join(CONFIG_PATH, "config.json")
Expand Down

0 comments on commit cf01699

Please # to comment.