From cb43bb5f0d52a5c628581bf12ca3c86041b913fe Mon Sep 17 00:00:00 2001 From: Ayala Shachar Date: Fri, 10 Nov 2023 12:50:56 +0200 Subject: [PATCH] Remove usage of pkg_resources (deprecated) --- backslash/__version__.py | 5 +++-- backslash/_compat.py | 12 ++++++++++++ backslash/contrib/slash_plugin.py | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 backslash/_compat.py diff --git a/backslash/__version__.py b/backslash/__version__.py index 670fce2..bef6e1f 100644 --- a/backslash/__version__.py +++ b/backslash/__version__.py @@ -1,3 +1,4 @@ -import pkg_resources +from ._compat import get_distribution -__version__ = pkg_resources.get_distribution('backslash').version + +__version__ = get_distribution("backslash").version diff --git a/backslash/_compat.py b/backslash/_compat.py new file mode 100644 index 0000000..beb589b --- /dev/null +++ b/backslash/_compat.py @@ -0,0 +1,12 @@ +import sys + +if sys.version_info < (3, 8): + # pylint: disable=unused-import + import pkg_resources + + get_distribution = pkg_resources.get_distribution +else: + # pylint: disable=unused-import + import importlib.metadata + + get_distribution = importlib.metadata.distribution diff --git a/backslash/contrib/slash_plugin.py b/backslash/contrib/slash_plugin.py index ede235d..cf316d0 100644 --- a/backslash/contrib/slash_plugin.py +++ b/backslash/contrib/slash_plugin.py @@ -5,7 +5,6 @@ import itertools import json import os -import pkg_resources import socket import sys import time @@ -28,6 +27,7 @@ from urlobject import URLObject as URL from requests import HTTPError from shlex import quote as shellquote +from packaging.version import parse as parse_version from ..client import Backslash as BackslashClient from ..exceptions import ParamsTooLarge from ..utils import ensure_dir @@ -327,7 +327,7 @@ def get_tests_to_resume(self, session_id, filters_dict): def _get_test_info(self, test): if test.__slash__.is_interactive() and \ - pkg_resources.parse_version(slash.__version__) < pkg_resources.parse_version('1.6.0'): + parse_version(slash.__version__) < parse_version('1.6.0'): returned = { 'file_name': '', 'class_name': '',