Skip to content

Commit

Permalink
Backwards compatibility for importlib
Browse files Browse the repository at this point in the history
Use parameter format compatible with Python <= 3.10
  • Loading branch information
marmarta committed Jan 3, 2025
1 parent b087fd9 commit 48b332d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions qubesappmenus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def _appmenus_create_onedir(self, vm, force=False, refresh_cache=True,
anything_changed = False
directory_changed = False
directory_file = self._directory_path(vm, dispvm=dispvm)
data = importlib.resources.files(__name__).joinpath(
data = importlib.resources.files(__package__).joinpath(
self.directory_template_name(vm, dispvm)).read_text()
if self.write_desktop_file(
vm,
Expand Down Expand Up @@ -384,7 +384,7 @@ def _appmenus_create_onedir(self, vm, force=False, refresh_cache=True,
if not dispvm:
vm_settings_fname = os.path.join(
appmenus_dir, self.settings_name(vm))
data = importlib.resources.files(__name__).joinpath(
data = importlib.resources.files(__package__).joinpath(
'qubes-vm-settings.desktop.template').read_text()
if self.write_desktop_file(
vm,
Expand Down Expand Up @@ -597,7 +597,7 @@ def appmenus_init(self, vm, src=None):
with open(
os.path.join(own_templates_dir, 'qubes-start.desktop'),
'wb') as qubes_start_f:
data = importlib.resources.files(__name__).joinpath(
data = importlib.resources.files(__package__).joinpath(
'qubes-start.desktop.template').read_bytes()
qubes_start_f.write(data)

Expand Down
2 changes: 1 addition & 1 deletion qubesappmenus/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def process_appmenus_templates(appmenusext, vm, appmenus):
with open(qubes_start_fname, 'wb') as qubes_start_f:
vm.log.info("Creating Start")
template_data = importlib.resources.files(
__name__).joinpath(
__package__).joinpath(
'qubes-start.desktop.template').read_bytes()
qubes_start_f.write(template_data)

Expand Down
28 changes: 14 additions & 14 deletions qubesappmenus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ def test_005_created_appvm(self):
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'evince.desktop'), 'wb') as f:
f.write(importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes())
self.ext.appmenus_create(appvm, refresh_cache=False)
self.ext.appicons_create(appvm)
evince_path = self._make_desktop_name(appvm, 'evince.desktop')
self.assertPathExists(evince_path)
with open(evince_path, 'rb') as f:
new_file_bytes = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop').read_bytes()
self.assertEqual(
new_file_bytes.replace(b'%BASEDIR%',
Expand All @@ -283,7 +283,7 @@ def test_006_created_appvm_custom(self):
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'evince.desktop'), 'wb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
f.write(evince_data)
self.ext.appmenus_create(appvm, refresh_cache=False)
Expand All @@ -292,21 +292,21 @@ def test_006_created_appvm_custom(self):
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'xterm.desktop'), 'wb') as f:
xterm_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/xterm.desktop.template').read_bytes()
f.write(xterm_data)
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'evince.desktop'), 'wb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
f.write(evince_data.replace(b'Document Viewer', b'Random Viewer'))
self.ext.appmenus_update(appvm)
evince_path = self._make_desktop_name(appvm, 'evince.desktop')
self.assertPathExists(evince_path)
with open(evince_path, 'rb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop').read_bytes()
self.assertEqual(
evince_data
Expand All @@ -319,7 +319,7 @@ def test_006_created_appvm_custom(self):
self.assertPathExists(xterm_path)
with open(xterm_path, 'rb') as f:
xterm_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/xterm.desktop').read_bytes()
self.assertEqual(xterm_data
.replace(b'%BASEDIR%', qubesappmenus.basedir.encode()),
Expand Down Expand Up @@ -347,7 +347,7 @@ def test_007_created_dispvm(self):
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'evince.desktop'), 'wb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
f.write(evince_data)
self.ext.appmenus_create(appvm, refresh_cache=False)
Expand Down Expand Up @@ -400,7 +400,7 @@ class PopenMockup(object):
self.assertEqual(service, 'qubes.GetAppmenus')
p = PopenMockup()
p.stdout = importlib.resources.files(
anchor=__name__).joinpath('test-data/appmenus.input').open(mode='rb')
__package__).joinpath('test-data/appmenus.input').open(mode='rb')
p.wait = lambda: None
p.returncode = 0
return p
Expand Down Expand Up @@ -523,7 +523,7 @@ def test_120_create_appvm(self, mock_subprocess):
'evince.desktop')
with open(old_path, 'wb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
f.write(evince_data)
appvm = TestVM('test-inst-app',
Expand Down Expand Up @@ -552,7 +552,7 @@ def test_120_create_appvm(self, mock_subprocess):
self.assertPathExists(evince_path)
with open(evince_path, 'rb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop').read_bytes()
self.assertEqual(
evince_data.replace(b'%BASEDIR%',
Expand Down Expand Up @@ -601,7 +601,7 @@ def test_121_create_appvm_with_whitelist(self, mock_subprocess):
with open(os.path.join(self.ext.templates_dirs(tpl)[0],
'evince.desktop'), 'wb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
f.write(evince_data)
with open(os.path.join(self.basedir,
Expand All @@ -621,7 +621,7 @@ def test_121_create_appvm_with_whitelist(self, mock_subprocess):
self.assertPathExists(evince_path)
with open(evince_path, 'rb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop').read_bytes()
self.assertEqual(
evince_data.replace(b'%BASEDIR%',
Expand Down Expand Up @@ -688,7 +688,7 @@ class PopenMockup(object):
self.assertPathExists(evince_path)
with open(evince_path, 'rb') as f:
evince_data = importlib.resources.files(
anchor=__name__).joinpath(
__package__).joinpath(
'test-data/evince.desktop.template').read_bytes()
self.assertEqual(
evince_data,
Expand Down

0 comments on commit 48b332d

Please sign in to comment.