From 0e8432602d92aa015ae100044b5c196e32ccf87b Mon Sep 17 00:00:00 2001 From: Manu <3916435+m3nu@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:04:25 +0100 Subject: [PATCH] Remove pkg_resources use (#2098) --- package/vorta.spec | 1 - setup.cfg | 20 +++++++++----------- src/vorta/borg/_compatibility.py | 22 +++++++++++----------- tests/integration/conftest.py | 8 ++++---- tests/integration/test_diff.py | 8 ++++---- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/package/vorta.spec b/package/vorta.spec index 4559bc0d..663cfb01 100644 --- a/package/vorta.spec +++ b/package/vorta.spec @@ -30,7 +30,6 @@ a = Analysis([os.path.join(SRC_DIR, '__main__.py')], 'vorta.keyring.darwin', 'vorta.keyring.kwallet', 'vorta.keyring.secretstorage', - 'pkg_resources.py2_warn', ], hookspath=[], runtime_hooks=[], diff --git a/setup.cfg b/setup.cfg index f0c94da3..7b9d5074 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,10 +15,7 @@ classifiers = Operating System :: MacOS Operating System :: POSIX License :: OSI Approved :: GNU General Public License v3 (GPLv3) - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3 Topic :: System :: Archiving :: Backup Topic :: System :: Systems Administration Topic :: Utilities @@ -37,17 +34,18 @@ package_dir = include_package_data = true python_requires = >=3.8 install_requires = - platformdirs >=3.0.0, <5.0.0; sys_platform == 'darwin' # for macOS: breaking changes in 3.0.0, - platformdirs >=2.6.0, <5.0.0; sys_platform != 'darwin' # for others: 2.6+ works consistently. - pyqt6 + packaging peewee + platformdirs >=2.6.0, <5.0.0; sys_platform != 'darwin' # for others: 2.6+ works consistently. + platformdirs >=3.0.0, <5.0.0; sys_platform == 'darwin' # for macOS: breaking changes in 3.0.0, psutil - setuptools - secretstorage; sys_platform != 'darwin' pyobjc-core < 10; sys_platform == 'darwin' pyobjc-framework-Cocoa < 10; sys_platform == 'darwin' - pyobjc-framework-LaunchServices < 10; sys_platform == 'darwin' pyobjc-framework-CoreWLAN < 10; sys_platform == 'darwin' + pyobjc-framework-LaunchServices < 10; sys_platform == 'darwin' + pyqt6 + secretstorage; sys_platform != 'darwin' + setuptools tests_require = pytest pytest-qt @@ -97,7 +95,7 @@ extension-pkg-whitelist=PyQt6 load-plugins= [pylint.messages control] -disable= W0503,W0511,C0301,R0903,R0201,W0212,C0114,C0115,C0116,C0103,E0611,E1120,C0415,R0914,R0912,R0915 +disable= W0511,C0301,R0903,W0212,C0114,C0115,C0116,C0103,E0611,E1120,C0415,R0914,R0912,R0915 [pylint.format] max-line-length=120 diff --git a/src/vorta/borg/_compatibility.py b/src/vorta/borg/_compatibility.py index 327a83a6..a6056303 100644 --- a/src/vorta/borg/_compatibility.py +++ b/src/vorta/borg/_compatibility.py @@ -1,13 +1,13 @@ -from pkg_resources import parse_version +from packaging.version import Version MIN_BORG_FOR_FEATURE = { - 'BLAKE2': parse_version('1.1.4'), - 'ZSTD': parse_version('1.1.4'), - 'JSON_LOG': parse_version('1.1.0'), - 'DIFF_JSON_LINES': parse_version('1.1.16'), - 'COMPACT_SUBCOMMAND': parse_version('1.2.0a1'), - 'V122': parse_version('1.2.2'), - 'V2': parse_version('2.0.0b10'), + "BLAKE2": Version("1.1.4"), + "ZSTD": Version("1.1.4"), + "JSON_LOG": Version("1.1.0"), + "DIFF_JSON_LINES": Version("1.1.16"), + "COMPACT_SUBCOMMAND": Version("1.2.0a1"), + "V122": Version("1.2.2"), + "V2": Version("2.0.0b10"), # add new version-checks here. } @@ -19,12 +19,12 @@ class BorgCompatibility: to customize Borg commands by version in the future. """ - version = '1.1.0' - path = '' + version = "1.1.0" + path = "" def set_version(self, version, path): self.version = version self.path = path def check(self, feature_name): - return parse_version(self.version) >= MIN_BORG_FOR_FEATURE[feature_name] + return Version(self.version) >= MIN_BORG_FOR_FEATURE[feature_name] diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 54d9b23e..ff92b388 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -2,8 +2,8 @@ import subprocess import pytest +from packaging.version import Version from peewee import SqliteDatabase -from pkg_resources import parse_version import vorta import vorta.application @@ -45,7 +45,7 @@ def borg_version(): # test window does not automatically set borg version borg_compat.set_version(borg_version, borg_compat.path) - parsed_borg_version = parse_version(borg_version) + parsed_borg_version = Version(borg_version) return borg_version, parsed_borg_version @@ -54,7 +54,7 @@ def create_test_repo(tmpdir_factory, borg_version): repo_path = tmpdir_factory.mktemp('repo') source_files_dir = tmpdir_factory.mktemp('borg_src') - is_borg_v2 = borg_version[1] >= parse_version('2.0.0b1') + is_borg_v2 = borg_version[1] >= Version('2.0.0b1') if is_borg_v2: subprocess.run(['borg', '-r', str(repo_path), 'rcreate', '--encryption=none'], check=True) @@ -225,7 +225,7 @@ def min_borg_version(borg_version, request): if request.node.get_closest_marker('min_borg_version'): parsed_borg_version = borg_version[1] - if parsed_borg_version < parse_version(request.node.get_closest_marker('min_borg_version').args[0]): + if parsed_borg_version < Version(request.node.get_closest_marker('min_borg_version').args[0]): pytest.skip( 'skipped due to borg version requirement for test: {}'.format( request.node.get_closest_marker('min_borg_version').args[0] diff --git a/tests/integration/test_diff.py b/tests/integration/test_diff.py index 6d5ac491..9e64b718 100644 --- a/tests/integration/test_diff.py +++ b/tests/integration/test_diff.py @@ -3,7 +3,7 @@ """ import pytest -from pkg_resources import parse_version +from packaging.version import Version import vorta.borg import vorta.utils @@ -343,7 +343,7 @@ def test_archive_diff_lines( ): """Test that the diff lines are parsed correctly for supported borg versions""" parsed_borg_version = borg_version[1] - supports_fifo = parsed_borg_version > parse_version("1.1.18") + supports_fifo = parsed_borg_version > Version("1.1.18") supports_chrdev = create_test_repo[2] params = BorgDiffJob.prepare( @@ -372,8 +372,8 @@ def test_archive_diff_lines( item for item in expected if ( - ("min_version" not in item or parse_version(item["min_version"]) <= parsed_borg_version) - and ("max_version" not in item or parse_version(item["max_version"]) >= parsed_borg_version) + ("min_version" not in item or Version(item["min_version"]) <= parsed_borg_version) + and ("max_version" not in item or Version(item["max_version"]) >= parsed_borg_version) and (item["data"]["file_type"] != FileType.FIFO or supports_fifo) and (item["data"]["file_type"] != FileType.CHRDEV or supports_chrdev) )