Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated pkg_resources library #288

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Homepage: https://www.qubes-os.org/
#Vcs-Git: git://github.com/QubesOS/qubes-core-admin-client.git
#Vcs-Browser: https://github.com/QubesOS/qubes-core-admin-client
X-Python-Version: >= 2.7
X-Python3-Version: >= 3.4
X-Python3-Version: >= 3.8

Package: qubes-core-admin-client
Architecture: any
Expand Down
26 changes: 15 additions & 11 deletions qubesadmin/tests/backup/backupcompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import re

import multiprocessing
import pkg_resources
import importlib.resources
import sys

import qubesadmin.backup.core2
Expand Down Expand Up @@ -759,17 +759,17 @@ def assertCorrectlyConverted(self, backup_app, expected_data):
self.assertEqual(backup_app.globals, expected_data['globals'])

def test_000_qubes_xml_r2(self):
xml_data = pkg_resources.resource_string(__name__, 'v3-qubes.xml')
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v3-qubes.xml"
with tempfile.NamedTemporaryFile() as qubes_xml:
qubes_xml.file.write(xml_data)
qubes_xml.file.write(xml_path.read_bytes())
backup_app = qubesadmin.backup.core2.Core2Qubes(qubes_xml.name)
self.assertCorrectlyConverted(backup_app, parsed_qubes_xml_r2)

def test_010_qubes_xml_r4(self):
self.maxDiff = None
xml_data = pkg_resources.resource_string(__name__, 'v4-qubes.xml')
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v4-qubes.xml"
with tempfile.NamedTemporaryFile() as qubes_xml:
qubes_xml.file.write(xml_data)
qubes_xml.file.write(xml_path.read_bytes())
backup_app = qubesadmin.backup.core3.Core3Qubes(qubes_xml.name)
self.assertCorrectlyConverted(backup_app, parsed_qubes_xml_v4)

Expand Down Expand Up @@ -878,8 +878,8 @@ def create_v1_files(self, r2b2=False):
self.create_private_img(self.fullpath("appvms/test-work/private.img"))
with open(self.fullpath("appvms/test-work/firewall.xml"), "wb") as \
f_firewall:
f_firewall.write(
pkg_resources.resource_string(__name__, 'v3-firewall.xml'))
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v3-firewall.xml"
f_firewall.write(xml_path.read_bytes())

# StandaloneVM
os.mkdir(self.fullpath("appvms/test-standalonevm"))
Expand Down Expand Up @@ -1042,8 +1042,8 @@ def create_v4_files(self):
# setup firewall only on one VM
with open(self.fullpath("appvms/test-work/firewall.xml"), "wb") as \
f_firewall:
f_firewall.write(
pkg_resources.resource_string(__name__, 'v4-firewall.xml'))
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v4-firewall.xml"
f_firewall.write(xml_path.read_bytes())

# StandaloneVMs
for vm in ('test-standalonevm', 'test-hvm'):
Expand Down Expand Up @@ -1235,7 +1235,9 @@ def create_v3_backup(self, encrypted=True, compressed=True):
self.append_backup_stream("backup-header", output)
self.append_backup_stream("backup-header.hmac", output)
with open(self.fullpath("qubes.xml"), "wb") as f:
qubesxml = pkg_resources.resource_string(__name__, 'v3-qubes.xml')
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v3-qubes.xml"

qubesxml = xml_path.read_bytes()
if encrypted:
for vmname, subdir in MANGLED_SUBDIRS_R2.items():
qubesxml = re.sub(r"[a-z-]*/{}".format(vmname).encode(),
Expand Down Expand Up @@ -1300,7 +1302,9 @@ def create_v4_backup(self, compressed="gzip", big=False):
self.append_backup_stream("backup-header", output)
self.append_backup_stream("backup-header.hmac", output)
with open(self.fullpath("qubes.xml"), "wb") as f:
qubesxml = pkg_resources.resource_string(__name__, 'v4-qubes.xml')
xml_path = importlib.resources.files("qubesadmin") / "tests/backup/v4-qubes.xml"

qubesxml = xml_path.read_bytes()
for vmname, subdir in MANGLED_SUBDIRS_R4.items():
qubesxml = re.sub(
r'backup-path">[a-z-]*/{}'.format(vmname).encode(),
Expand Down
4 changes: 2 additions & 2 deletions qubesadmin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
"""Get a single entry point of given type,
raise TypeError when there are multiple.
"""
import pkg_resources
epoints = tuple(pkg_resources.iter_entry_points(group, name))
import importlib.metadata
epoints = tuple(importlib.metadata.entry_points(group=group, name=name))

Check warning on line 94 in qubesadmin/utils.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/utils.py#L93-L94

Added lines #L93 - L94 were not covered by tests
if not epoints:
raise KeyError(name)
if len(epoints) > 1:
Expand Down