From: DaanDeMeyer Date: Tue, 23 Dec 2025 19:58:15 +0000 (+0100) Subject: Remove unneeded lambdas X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a44e1831b68b97e7d0109cf434cb60c6eadb7d7;p=thirdparty%2Fmkosi.git Remove unneeded lambdas --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 5299dda1d..ac6705e7f 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3916,7 +3916,7 @@ def setup_workspace(args: Args, config: Config) -> Iterator[Path]: workspace.chmod(stat.S_IMODE(workspace.stat().st_mode) & ~(stat.S_ISGID | stat.S_ISUID)) # Explicitly pass the "root" subdirectory first because on btrfs it's likely a subvolume and this # allows us to delete it with btrfs subvolume delete instead of a costly rm -rf. - stack.callback(lambda: rmtree(workspace / "root", workspace, sandbox=config.sandbox)) + stack.callback(rmtree, workspace / "root", workspace, sandbox=config.sandbox) (workspace / "tmp").mkdir(mode=0o1777) with scopedenv({"TMPDIR": os.fspath(workspace / "tmp")}): @@ -4240,9 +4240,7 @@ def run_shell(args: Args, config: Config) -> None: # Make sure the latest nspawn settings are always used. if config.nspawn_settings: if not (config.output_dir_or_cwd() / f"{name}.nspawn").exists(): - stack.callback( - lambda: (config.output_dir_or_cwd() / f"{name}.nspawn").unlink(missing_ok=True) - ) + stack.callback((config.output_dir_or_cwd() / f"{name}.nspawn").unlink, missing_ok=True) copyfile2(config.nspawn_settings, config.output_dir_or_cwd() / f"{name}.nspawn") # If we're booting a directory image that wasn't built by root, we always make an ephemeral diff --git a/mkosi/qemu.py b/mkosi/qemu.py index 89d71e3f5..5a6c4a6ab 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -771,7 +771,7 @@ def finalize_initrd(config: Config) -> Iterator[Optional[Path]]: elif config.initrds: initrd = config.output_dir_or_cwd() / f"initrd-{uuid.uuid4().hex}" join_initrds(config.initrds, initrd) - stack.callback(lambda: initrd.unlink()) + stack.callback(initrd.unlink) yield initrd else: yield None diff --git a/tests/test_initrd.py b/tests/test_initrd.py index 77a88fc88..2cc618975 100644 --- a/tests/test_initrd.py +++ b/tests/test_initrd.py @@ -67,14 +67,14 @@ def test_initrd_lvm(config: ImageConfig) -> None: lodev = run( ["losetup", "--show", "--find", "--partscan", lvm], stdout=subprocess.PIPE ).stdout.strip() - stack.callback(lambda: run(["losetup", "--detach", lodev])) + stack.callback(run, ["losetup", "--detach", lodev]) run(["sfdisk", "--label", "gpt", lodev], input="type=E6D6D379-F507-44C2-A23C-238F2A3DF928 bootable") run(["lvm", "pvcreate", "--devicesfile", "", f"{lodev}p1"]) run(["lvm", "pvs", "--devicesfile", ""]) run(["lvm", "vgcreate", "--devicesfile", "", "-An", "vg_mkosi", f"{lodev}p1"]) run(["lvm", "vgchange", "--devicesfile", "", "-ay", "vg_mkosi"]) run(["lvm", "vgs", "--devicesfile", ""]) - stack.callback(lambda: run(["lvm", "vgchange", "--devicesfile", "", "-an", "vg_mkosi"])) + stack.callback(run, ["lvm", "vgchange", "--devicesfile", "", "-an", "vg_mkosi"]) run(["lvm", "lvcreate", "--devicesfile", "", "-An", "-l", "100%FREE", "-n", "lv0", "vg_mkosi"]) run(["lvm", "lvs", "--devicesfile", ""]) run(["udevadm", "wait", "--timeout=30", "/dev/vg_mkosi/lv0"]) @@ -82,7 +82,7 @@ def test_initrd_lvm(config: ImageConfig) -> None: src = Path(stack.enter_context(tempfile.TemporaryDirectory())) run(["systemd-dissect", "--mount", "--mkdir", Path(image.output_dir) / "image.raw", src]) - stack.callback(lambda: run(["systemd-dissect", "--umount", "--rmdir", src])) + stack.callback(run, ["systemd-dissect", "--umount", "--rmdir", src]) dst = Path(stack.enter_context(tempfile.TemporaryDirectory())) stack.enter_context(mount(Path("/dev/vg_mkosi/lv0"), dst)) @@ -165,7 +165,7 @@ def test_initrd_luks_lvm(config: ImageConfig, passphrase: Path) -> None: lodev = run( ["losetup", "--show", "--find", "--partscan", lvm], stdout=subprocess.PIPE ).stdout.strip() - stack.callback(lambda: run(["losetup", "--detach", lodev])) + stack.callback(run, ["losetup", "--detach", lodev]) run(["sfdisk", "--label", "gpt", lodev], input="type=E6D6D379-F507-44C2-A23C-238F2A3DF928 bootable") run( [ @@ -179,14 +179,14 @@ def test_initrd_luks_lvm(config: ImageConfig, passphrase: Path) -> None: ] ) # fmt: skip run(["cryptsetup", "--key-file", passphrase, "luksOpen", f"{lodev}p1", "lvm_root"]) - stack.callback(lambda: run(["cryptsetup", "close", "lvm_root"])) + stack.callback(run, ["cryptsetup", "close", "lvm_root"]) luks_uuid = run(["cryptsetup", "luksUUID", f"{lodev}p1"], stdout=subprocess.PIPE).stdout.strip() run(["lvm", "pvcreate", "--devicesfile", "", "/dev/mapper/lvm_root"]) run(["lvm", "pvs", "--devicesfile", ""]) run(["lvm", "vgcreate", "--devicesfile", "", "-An", "vg_mkosi", "/dev/mapper/lvm_root"]) run(["lvm", "vgchange", "--devicesfile", "", "-ay", "vg_mkosi"]) run(["lvm", "vgs", "--devicesfile", ""]) - stack.callback(lambda: run(["lvm", "vgchange", "--devicesfile", "", "-an", "vg_mkosi"])) + stack.callback(run, ["lvm", "vgchange", "--devicesfile", "", "-an", "vg_mkosi"]) run(["lvm", "lvcreate", "--devicesfile", "", "-An", "-l", "100%FREE", "-n", "lv0", "vg_mkosi"]) run(["lvm", "lvs", "--devicesfile", ""]) run(["udevadm", "wait", "--timeout=30", "/dev/vg_mkosi/lv0"]) @@ -194,7 +194,7 @@ def test_initrd_luks_lvm(config: ImageConfig, passphrase: Path) -> None: src = Path(stack.enter_context(tempfile.TemporaryDirectory())) run(["systemd-dissect", "--mount", "--mkdir", Path(image.output_dir) / "image.raw", src]) - stack.callback(lambda: run(["systemd-dissect", "--umount", "--rmdir", src])) + stack.callback(run, ["systemd-dissect", "--umount", "--rmdir", src]) dst = Path(stack.enter_context(tempfile.TemporaryDirectory())) stack.enter_context(mount(Path("/dev/vg_mkosi/lv0"), dst))