From 035dc97fd84e72b5dcc017c9593584656ab6e509 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 7 Oct 2024 10:39:21 +0200 Subject: [PATCH 1/2] Make find_binary()'s root argument optional Makes it a little easier to use. --- mkosi/run.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mkosi/run.py b/mkosi/run.py index 6674118b7..6248f83be 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -302,7 +302,13 @@ def preexec() -> None: make_foreground_process(new_process_group=False) -def find_binary(*names: PathString, root: Path = Path("/"), extra: Sequence[Path] = ()) -> Optional[Path]: +def find_binary( + *names: PathString, + root: Optional[Path] = None, + extra: Sequence[Path] = (), +) -> Optional[Path]: + root = root or Path("/") + if root != Path("/"): path = ":".join( itertools.chain( From ad135a8217563ee0e22efde220961856c780a716 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 7 Oct 2024 10:39:38 +0200 Subject: [PATCH 2/2] Make tools tree available in tests For use with find_binary() to check if binaries exist in the tools tree. --- tests/__init__.py | 2 ++ tests/conftest.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index 7a7ab89c5..419138b00 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -25,6 +25,7 @@ class ImageConfig: distribution: Distribution release: str debug_shell: bool + tools: Optional[Path] class Image: @@ -64,6 +65,7 @@ def mkosi( return run( [ "python3", "-m", "mkosi", + *(["--tools-tree", os.fspath(self.config.tools)] if self.config.tools else []), "--debug", *options, verb, diff --git a/tests/conftest.py b/tests/conftest.py index 86e5a5ba0..86ae99a20 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1-or-later from collections.abc import Iterator +from pathlib import Path from typing import Any, cast import pytest @@ -48,6 +49,7 @@ def config(request: Any) -> ImageConfig: distribution=distribution, release=release, debug_shell=request.config.getoption("--debug-shell"), + tools=p if (p := Path("mkosi.tools")).exists() else None, )