From b35f4ba978bed068f7af6866bc57c3ac51a9a13e Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 4 Oct 2023 13:30:19 +0200 Subject: [PATCH] Parse setting paths before parsing main config file Currently, paths either configure default values or append to a list (When path_default is False, it's always a list based setting). When paths are configuring default values, it makes more sense for default values set in the mkosi.conf file to override path based default values. When appending to a list, (e.g. ExtraTrees=), it makes more sense for the trees configured in the mkosi.conf to come after the tree from the path (mkosi.extra). Both these goals are achieved by parsing the path based values before parsing the main mkosi.conf file. --- mkosi/config.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/mkosi/config.py b/mkosi/config.py index 6150a0db1..b91de042f 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -2187,6 +2187,7 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig return triggered is not False def parse_config(path: Path, namespace: argparse.Namespace, defaults: argparse.Namespace) -> bool: + s: Optional[MkosiConfigSetting] # Make mypy happy extras = path.is_dir() if path.is_dir(): @@ -2195,6 +2196,22 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig if not match_config(path, namespace, defaults): return False + if extras: + for s in SETTINGS: + ns = defaults if s.path_default else namespace + for f in s.paths: + p = parse_path( + f, + secret=s.path_secret, + required=False, + resolve=False, + expanduser=False, + expandvars=False, + ) + if p.exists(): + setattr(ns, s.dest, + s.parse(p.read_text() if s.path_read_text else f, getattr(ns, s.dest, None))) + if path.exists(): logging.debug(f"Including configuration file {Path.cwd() / path}") @@ -2215,27 +2232,11 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig with parse_new_includes(namespace, defaults): setattr(ns, s.dest, s.parse(v, getattr(ns, s.dest, None))) - if extras: - for s in SETTINGS: - ns = defaults if s.path_default else namespace - for f in s.paths: - p = parse_path( - f, - secret=s.path_secret, - required=False, - resolve=False, - expanduser=False, - expandvars=False, - ) - if p.exists(): - setattr(ns, s.dest, - s.parse(p.read_text() if s.path_read_text else f, getattr(ns, s.dest, None))) - - if (path.parent / "mkosi.conf.d").exists(): - for p in sorted((path.parent / "mkosi.conf.d").iterdir()): - if p.is_dir() or p.suffix == ".conf": - with chdir(p if p.is_dir() else Path.cwd()): - parse_config(p if p.is_file() else Path("."), namespace, defaults) + if extras and (path.parent / "mkosi.conf.d").exists(): + for p in sorted((path.parent / "mkosi.conf.d").iterdir()): + if p.is_dir() or p.suffix == ".conf": + with chdir(p if p.is_dir() else Path.cwd()): + parse_config(p if p.is_file() else Path("."), namespace, defaults) return True -- 2.47.3