]> git.mar77i.info Git - localapps/commitdiff
Simplify apps registry
authormar77i <mar77i@protonmail.ch>
Sat, 24 Jan 2026 03:14:43 +0000 (04:14 +0100)
committermar77i <mar77i@protonmail.ch>
Sat, 24 Jan 2026 03:15:15 +0000 (04:15 +0100)
localapps.py

index 197e0e2955affca9c8d71398a7b603595a7b0ab8..41ede009f27da0008f0b9d652e1aa36ecf49daf0 100755 (executable)
@@ -9,22 +9,9 @@ from stat import S_IXGRP, S_IXOTH, S_IXUSR
 from subprocess import check_output
 
 
-class IterableHolder(type):
-    def __init__(self, name, bases, namespace, attr_name=None):
-        super().__init__(name, bases, namespace)
-        self.attr_name = attr_name
-
-    def __new__(cls, *args, **kwargs):
-        kwargs.pop("attr_name", None)
-        return super().__new__(cls, *args, **kwargs)
-
-    def __iter__(self):
-        return iter(getattr(self, self.attr_name))
-
-
-class AppBase(metaclass=IterableHolder, attr_name="registry"):
+class AppBase:
     NAME: str
-    APPS_DIR = Path("~/local_apps").expanduser()
+    APPS_DIR = Path("~/apps").expanduser()
     BIN_PATH: Path
     registry: list[type[AppBase]] = []
 
@@ -146,7 +133,7 @@ class LocalAppsManager:
         getattr(self, self.args.action)()
 
     def list(self):
-        for app in AppBase:
+        for app in AppBase.registry:
             latest = app.get_latest_version()
             assert latest is not None
             print(app.NAME, "latest", latest, end="")
@@ -157,7 +144,7 @@ class LocalAppsManager:
             print(" installed", installed)
 
     def upgrade(self):
-        for app in AppBase:
+        for app in AppBase.registry:
             installed = app.get_installed_version()
             if installed is None:
                 continue
@@ -165,7 +152,9 @@ class LocalAppsManager:
 
     def get_pending_apps(self):
         app_names = [app_name.upper() for app_name in self.args.app_names]
-        pending_apps = [app for app in AppBase if app.NAME.upper() in app_names]
+        pending_apps = [
+            app for app in AppBase.registry if app.NAME.upper() in app_names
+        ]
         if len(pending_apps) != len(app_names):
             missing_apps = [
                 app_name