]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Rework PACKAGE_GLOBS to be a PackageManager classmethod
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 Oct 2025 19:35:12 +0000 (21:35 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 16 Oct 2025 07:53:33 +0000 (09:53 +0200)
mkosi/__init__.py
mkosi/config.py
mkosi/installer/__init__.py
mkosi/installer/apk.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/installer/zypper.py

index 3fd1d4f9588c23cff598020c45f7251afa9c2868..be4338ee7f66a64bed54a47fca66e2c6a217300c 100644 (file)
@@ -48,7 +48,6 @@ from mkosi.bootloader import (
 from mkosi.burn import run_burn
 from mkosi.completion import print_completion
 from mkosi.config import (
-    PACKAGE_GLOBS,
     Args,
     ArtifactOutput,
     Cacheonly,
@@ -1263,7 +1262,10 @@ def install_package_directories(context: Context, directories: Sequence[Path]) -
 
     with complete_step("Copying in extra packages…"):
         for d in directories:
-            for p in itertools.chain(*(d.glob(glob) for glob in PACKAGE_GLOBS)):
+            for p in itertools.chain.from_iterable(
+                d.glob(glob)
+                for glob in context.config.distribution.package_manager(context.config).package_globs()
+            ):
                 shutil.copy(p, context.repository, follow_symlinks=True)
 
 
index 2fbc9e7762f80ecbb7c810d2641e99e0c83f595a..87b214fcb219df8ae55604e3dc01fd35b89c3987 100644 (file)
@@ -1882,15 +1882,6 @@ class Args:
         return dataclasses.replace(cls.default(), **{k: v for k, v in j.items() if k in cls.fields()})
 
 
-PACKAGE_GLOBS = (
-    "*.rpm",
-    "*.pkg.tar*",
-    "*.deb",
-    "*.ddeb",
-    "*.apk",
-)
-
-
 @dataclasses.dataclass(frozen=True)
 class UKIProfile:
     profile: dict[str, str]
@@ -2375,7 +2366,9 @@ class Config:
             "package_directories": [
                 (p.name, p.stat().st_mtime_ns)
                 for d in self.package_directories
-                for p in sorted(flatten(d.glob(glob) for glob in PACKAGE_GLOBS))
+                for p in sorted(
+                    flatten(d.glob(glob) for glob in self.distribution.package_manager(self).package_globs())
+                )
             ],
             "repositories": sorted(self.repositories),
             "overlay": self.overlay,
index da8fa4db604e3dddab99bcd3f8472ad73d60b11d..2647fca410f9c7d57feda368819e3bb1ea48bd01 100644 (file)
@@ -25,6 +25,10 @@ class PackageManager:
     def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
         return []
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return []
+
     @classmethod
     def state_subdirs(cls, state: Path) -> list[Path]:
         return []
index 9c9b754fad56720e66e3c21f1a03ed70705753b6..6cf8749ec46fd7453accae0fb7032f1c09780776 100644 (file)
@@ -31,6 +31,10 @@ class Apk(PackageManager):
     def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
         return [(Path("."), Path("."))]
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return ["*.apk"]
+
     @classmethod
     def scripts(cls, context: Context) -> dict[str, list[PathString]]:
         return {
index cff959010dc2af43e3e9cffd5f40b5e96ea7b683..9ffec6457af742cc413038556684da8d26ccd081 100644 (file)
@@ -6,7 +6,7 @@ from collections.abc import Sequence
 from pathlib import Path
 from typing import Final, Optional
 
-from mkosi.config import PACKAGE_GLOBS, Config, ConfigFeature
+from mkosi.config import Config, ConfigFeature
 from mkosi.context import Context
 from mkosi.installer import PackageManager
 from mkosi.log import die
@@ -59,6 +59,10 @@ class Apt(PackageManager):
     def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
         return [(Path("archives"), Path("archives"))]
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return ["*.deb", "*.ddeb"]
+
     @classmethod
     def state_subdirs(cls, state: Path) -> list[Path]:
         return [state / "lists"]
@@ -286,7 +290,7 @@ class Apt(PackageManager):
 
     @classmethod
     def createrepo(cls, context: Context) -> None:
-        names = [d.name for glob in PACKAGE_GLOBS for d in context.repository.glob(glob) if "deb" in glob]
+        names = [d.name for glob in cls.package_globs() for d in context.repository.glob(glob)]
         if not names:
             return
 
index 938fdf8457f27c411c7dcdd50ce8fd523d7dd01c..3c7a6fc0e7976e58d7fe329abc3e6d490995fb6d 100644 (file)
@@ -42,6 +42,10 @@ class Dnf(PackageManager):
             for d in dirs
         ]
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return ["*.rpm"]
+
     @classmethod
     def scripts(cls, context: Context) -> dict[str, list[PathString]]:
         return {
index 1f15928e0b4b6c72922227125928a1a5f9a92588..dc42af8cf00d4ec9b0072c8fdfd07f30e7f95318 100644 (file)
@@ -38,6 +38,10 @@ class Pacman(PackageManager):
     def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
         return [(Path("pkg"), Path("pkg"))]
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return ["*.pkg.tar"]
+
     @classmethod
     def state_subdirs(cls, state: Path) -> list[Path]:
         return [state / "sync"]
index 5c656d11f04f33b5a275fa1bb717c996a736df4d..66ffcf724ecee008eb791b9b6345de6f07532ede 100644 (file)
@@ -26,6 +26,10 @@ class Zypper(PackageManager):
     def package_subdirs(cls, cache: Path) -> list[tuple[Path, Path]]:
         return [(Path("packages"), Path("packages"))]
 
+    @classmethod
+    def package_globs(cls) -> list[str]:
+        return ["*.rpm"]
+
     @classmethod
     def scripts(cls, context: Context) -> dict[str, list[PathString]]:
         install: list[PathString] = [