Browse Source

Avoid importlib

We already have a resource provider mechanism. So let's use this
for the desktop file too.
Michael Hanke 1 year ago
parent
commit
3ac645ccdb
4 changed files with 14 additions and 11 deletions
  1. 2 2
      datalad_gooey/gooey.py
  2. 4 5
      datalad_gooey/postinstall.py
  3. 8 3
      datalad_gooey/resource_provider.py
  4. 0 1
      setup.cfg

+ 2 - 2
datalad_gooey/gooey.py

@@ -10,8 +10,6 @@ from datalad.interface.utils import eval_results
 
 from datalad.interface.results import get_status_dict
 
-from .postinstall import perform_post_install_tasks
-
 import logging
 lgr = logging.getLogger('datalad.ext.gooey.gooey')
 
@@ -73,6 +71,8 @@ class Gooey(Interface):
 
         # if requested, perform post-install tasks and exit
         if postinstall:
+            # prevent top-level import of Qt stuff
+            from .postinstall import perform_post_install_tasks
             perform_post_install_tasks()
             return
 

+ 4 - 5
datalad_gooey/postinstall.py

@@ -1,8 +1,9 @@
 from sys import platform
 
-from importlib_resources import files  # from Python 3.10 use importlib.resources
 from platformdirs import user_data_path
 
+from .resource_provider import gooey_resources
+
 
 def perform_post_install_tasks():
     if platform == "linux":
@@ -14,7 +15,7 @@ def perform_post_install_tasks():
 
 def create_desktop_file():
     df_name = "datalad-gooey.desktop"
-    template_path = files("datalad_gooey.resources.desktop").joinpath(df_name)
+    template_path = gooey_resources.get_resource_path('desktop') / df_name
     target_path = user_data_path() / "applications" / df_name
 
     if not target_path.parent.exists():
@@ -25,9 +26,7 @@ def create_desktop_file():
 
 
 def copy_icon():
-    source_path = files(
-        "datalad_gooey.resources.icons"
-    ).joinpath('datalad_gooey_logo.svg')
+    source_path = gooey_resources.get_icon_path('datalad_gooey_logo')
     target_path = user_data_path() / "icons" / "datalad-gooey"
 
     if not target_path.parent.exists():

+ 8 - 3
datalad_gooey/resource_provider.py

@@ -24,7 +24,7 @@ class GooeyResources:
 
     def __init__(self):
         self._icons = {}
-        self._ressource_path = Path(__file__).resolve().parent / 'resources'
+        self._resource_path = Path(__file__).resolve().parent / 'resources'
 
     def get_icon(self, name):
         if name is None:
@@ -32,8 +32,7 @@ class GooeyResources:
             return QIcon()
         icon = self._icons.get(name)
         if icon is None:
-            icon = QIcon(str(
-                self._ressource_path / 'icons' / f'{name}.svg'))
+            icon = QIcon(str(self.get_icon_path(name)))
             self._icons[name] = icon
         return icon
 
@@ -41,5 +40,11 @@ class GooeyResources:
         icon_name = GooeyResources.label_to_name.get(label)
         return self.get_icon(icon_name)
 
+    def get_icon_path(self, name):
+        return self.get_resource_path('icons') / f'{name}.svg'
+
+    def get_resource_path(self, category):
+        return self._resource_path / category
+
 
 gooey_resources = GooeyResources()

+ 0 - 1
setup.cfg

@@ -18,7 +18,6 @@ install_requires =
     pyside6
     outdated
     pyqtdarktheme
-    importlib-resources
 packages = find_namespace:
 include_package_data = True