import os
import re
import subprocess
-from collections.abc import Iterable, Iterator
+from collections.abc import Iterable, Iterator, Reversible
from pathlib import Path
from mkosi.context import Context
]
-def globs_match_filename(name, globs, *, match_default: bool = False) -> bool:
+def globs_match_filename(
+ name: str,
+ globs: Reversible[str],
+ *,
+ match_default: bool = False,
+) -> bool:
# Check whether the path matches any of the globs
for glob in reversed(globs):
return match_default
-def globs_match_module(name, globs) -> bool:
+def globs_match_module(
+ name: str,
+ globs: Reversible[str],
+) -> bool:
# Strip '.ko' suffix and an optional compression suffix
name = re.sub(r"\.ko(\.(gz|xz|zst))?$", "", name)
# Check whether the suffixless-path matches any of the globs
return globs_match_filename(name, globs)
-def globs_match_firmware(name, globs, *, match_default: bool = False) -> bool:
+def globs_match_firmware(
+ name: str,
+ globs: Reversible[str],
+ *,
+ match_default: bool = False,
+) -> bool:
# Strip any known compression suffixes
name = re.sub(r"\.(gz|xz|zst)$", "", name)
# Check whether the suffixless-path matches any of the globs
from mkosi import kmod
-def test_globs_match_module():
+def test_globs_match_module() -> None:
assert kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["ahci"])
assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz.2", ["ahci"])
assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["ata"])
assert not kmod.globs_match_module("drivers/ata/ahci.ko.xz", ["-*"])
-def test_normalize_module_glob():
+def test_normalize_module_glob() -> None:
assert kmod.normalize_module_glob("raid[0-9]") == "raid[0-9]"
assert kmod.normalize_module_glob("raid[0_9]") == "raid[0_9]"
assert kmod.normalize_module_glob("raid[0_9]a_z") == "raid[0_9]a-z"