From 11005c46f6796d1f75ae033314d0ec4caaff796b Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Mon, 20 Jan 2025 11:37:38 +0100 Subject: [PATCH] Use $HOME in current_home_dir() regardless of whether we're in it or not If $HOME is set, let's always use it as a fallback if we're not running from a home directory. --- mkosi/util.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mkosi/util.py b/mkosi/util.py index 248d8e0cc..9b6d7e377 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -238,21 +238,20 @@ def groupby(seq: Sequence[T], key: Callable[[T], S]) -> list[tuple[S, list[T]]]: def current_home_dir() -> Optional[Path]: + home = Path(h) if (h := os.getenv("HOME")) else None + if Path.cwd() in (Path("/"), Path("/home")): - return None + return home if Path.cwd().is_relative_to("/root"): return Path("/root") - if (home := os.getenv("HOME")) and Path.cwd().is_relative_to(home): - return Path(home) - if Path.cwd().is_relative_to("/home"): # `Path.parents` only supports slices and negative indexing from Python 3.10 onwards. # TODO: Remove list() when we depend on Python 3.10 or newer. return list(Path.cwd().parents)[-3] - return None + return home def unique(seq: Sequence[T]) -> list[T]: -- 2.47.3