From 29d328790294904566dbe65e0b9e28818b4b11b7 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 27 Sep 2025 22:08:51 +0200 Subject: [PATCH] config: Reduce indentation --- mkosi/config.py | 95 +++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/mkosi/config.py b/mkosi/config.py index 3035b0a56..9f8b73ded 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -5260,63 +5260,66 @@ def parse_config( None if "dependencies" in context.cli or "dependencies" in context.config else [] ) + # For the subimages in mkosi.images/, we want settings that are marked as + # "universal" to override whatever settings are specified in the subimage + # configuration files. We achieve this by making it appear like these settings + # were specified on the CLI by copying them to the CLI namespace. Any settings + # that are not marked as "universal" are deleted from the CLI namespace. + for s in SETTINGS: + if s.scope in (SettingScope.universal, SettingScope.multiversal): + context.cli[s.dest] = copy.deepcopy(config[s.dest]) + elif s.dest in context.cli: + del context.cli[s.dest] + + todo = [] if configdir is not None and (imagedir := configdir / "mkosi.images").exists(): - # For the subimages in mkosi.images/, we want settings that are marked as - # "universal" to override whatever settings are specified in the subimage - # configuration files. We achieve this by making it appear like these settings - # were specified on the CLI by copying them to the CLI namespace. Any settings - # that are not marked as "universal" are deleted from the CLI namespace. - for s in SETTINGS: - if s.scope in (SettingScope.universal, SettingScope.multiversal): - context.cli[s.dest] = copy.deepcopy(config[s.dest]) - elif s.dest in context.cli: - del context.cli[s.dest] + todo += sorted(imagedir.iterdir()) - for p in sorted(imagedir.iterdir()): - p = p.absolute() + for p in todo: + p = p.absolute() - if not p.is_dir() and not p.suffix == ".conf": - continue + if not p.is_dir() and not p.suffix == ".conf": + continue - name = p.name.removesuffix(".conf") - if not name: - die(f"{p} is not a valid image name") + name = p.name.removesuffix(".conf") + if not name: + die(f"{p} is not a valid image name") - context.config = { - "image": name, - "directory": args.directory, - "files": [], - } + context.config = { + "image": name, + "directory": args.directory, + "files": [], + } - # Settings that are marked as "inherit" are passed down to subimages but can - # be overridden, so we copy these to the config namespace so that they'll be - # overridden if the setting is explicitly configured by the subimage. - for s in SETTINGS: - if s.scope == SettingScope.inherit and s.dest in config: - context.config[s.dest] = copy.deepcopy(config[s.dest]) + # Settings that are marked as "inherit" are passed down to subimages but can + # be overridden, so we copy these to the config namespace so that they'll be + # overridden if the setting is explicitly configured by the subimage. + for s in SETTINGS: + if s.scope == SettingScope.inherit and s.dest in config: + context.config[s.dest] = copy.deepcopy(config[s.dest]) - context.config["environment"] = { - name: config["environment"][name] - for name in config.get("pass_environment", {}) - if name in config.get("environment", {}) - } + context.config["environment"] = { + name: config["environment"][name] + for name in config.get("pass_environment", {}) + if name in config.get("environment", {}) + } - # Allow subimage configuration to include everything again. - context.includes = set() - context.defaults = {} + # Allow subimage configuration to include everything again. + context.includes = set() + context.defaults = {} - with chdir(p if p.is_dir() else Path.cwd()): - if not context.parse_config_one( - p if p.is_file() else Path.cwd(), - parse_profiles=p.is_dir(), - parse_local=True, - ): - continue + with chdir(p if p.is_dir() else Path.cwd()): + if not context.parse_config_one( + p if p.is_file() else Path.cwd(), + parse_profiles=p.is_dir(), + parse_local=True, + ): + continue - images += [context.finalize()] + images += [context.finalize()] - if dependencies is not None: - dependencies += [name] + if dependencies is not None: + dependencies += [name] if dependencies is not None: config["dependencies"] = dependencies -- 2.47.3