From: Daan De Meyer Date: Thu, 11 Jan 2024 16:15:46 +0000 (+0100) Subject: Use default_factory for tools tree options defaults X-Git-Tag: v20.1~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcf6389cf3abcf24294c58d62888b0ab9adaee0d;p=thirdparty%2Fmkosi.git Use default_factory for tools tree options defaults --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 749f028af..a043a6b9e 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3249,22 +3249,15 @@ def prepend_to_environ_path(config: Config) -> Iterator[None]: @contextlib.contextmanager def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]: - distribution = config.tools_tree_distribution or config.distribution.default_tools_tree_distribution() - if not distribution: + if not config.tools_tree_distribution: die(f"{config.distribution} does not have a default tools tree distribution", hint="use ToolsTreeDistribution= to set one explicitly") - release = config.tools_tree_release or distribution.default_release() - mirror = ( - config.tools_tree_mirror or - (config.mirror if config.mirror and config.distribution == distribution else None) - ) - cmdline = [ "--directory", "", - "--distribution", str(distribution), - *(["--release", release] if release else []), - *(["--mirror", mirror] if mirror else []), + "--distribution", str(config.tools_tree_distribution), + *(["--release", config.tools_tree_release] if config.tools_tree_release else []), + *(["--mirror", config.tools_tree_mirror] if config.tools_tree_mirror else []), "--repository-key-check", str(config.repository_key_check), "--cache-only", str(config.cache_only), *(["--output-dir", str(config.output_dir)] if config.output_dir else []), @@ -3273,7 +3266,7 @@ def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]: "--incremental", str(config.incremental), "--acl", str(config.acl), *([f"--package={package}" for package in config.tools_tree_packages]), - "--output", f"{distribution}-tools", + "--output", f"{config.tools_tree_distribution}-tools", *(["--source-date-epoch", str(config.source_date_epoch)] if config.source_date_epoch is not None else []), *([f"--environment={k}='{v}'" for k, v in config.environment.items()]), *([f"--extra-search-path={p}" for p in config.extra_search_paths]), @@ -3290,7 +3283,7 @@ def finalize_default_tools(args: Args, config: Config) -> Iterator[Config]: *tools.build_scripts, ) - tools = dataclasses.replace(tools, image=f"{distribution}-tools") + tools = dataclasses.replace(tools, image=f"{config.tools_tree_distribution}-tools") yield tools diff --git a/mkosi/config.py b/mkosi/config.py index 46b0c7ba3..b06bc0aa8 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -2281,6 +2281,8 @@ SETTINGS = ( metavar="DISTRIBUTION", section="Host", parse=config_make_enum_parser(Distribution), + default_factory_depends=("distribution",), + default_factory=lambda ns: ns.distribution.default_tools_tree_distribution(), help="Set the distribution to use for the default tools tree", ), ConfigSetting( @@ -2288,12 +2290,16 @@ SETTINGS = ( metavar="RELEASE", section="Host", parse=config_parse_string, + default_factory_depends=("tools_tree_distribution",), + default_factory=lambda ns: d.default_release() if (d := ns.tools_tree_distribution) else None, help="Set the release to use for the default tools tree", ), ConfigSetting( dest="tools_tree_mirror", metavar="MIRROR", section="Host", + default_factory_depends=("distribution", "tools_tree_distribution"), + default_factory=lambda ns: ns.mirror if ns.mirror and ns.distribution == ns.tools_tree_distribution else None, help="Set the mirror to use for the default tools tree", ), ConfigSetting(