]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix --profile
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 11 Jul 2024 06:19:21 +0000 (08:19 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 11 Jul 2024 07:27:41 +0000 (09:27 +0200)
The attribute might be set on either the cli or the config namespace
so don't assume it's set on the config namespace.

Fixes #2860

mkosi/config.py
tests/test_config.py

index e556428df27b61f04926c3a002d4f2e545f625ff..fea162500d524ef21076b0c18e9cae6377a2a0a5 100644 (file)
@@ -3666,8 +3666,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu
                     setattr(ParseContext.config, s.dest, s.parse(v, getattr(ParseContext.config, s.dest, None)))
 
         if profiles:
-            finalize_value(SETTINGS_LOOKUP_BY_DEST["profile"])
-            profile = getattr(ParseContext.config, "profile")
+            profile = finalize_value(SETTINGS_LOOKUP_BY_DEST["profile"])
             ParseContext.immutable.add("Profile")
 
             if profile:
index b82d2ab905998ca2c5f05b536fedb186523d755c..6a5b6d591033175dfab70d534544a511b2370018 100644 (file)
@@ -356,6 +356,16 @@ def test_profiles(tmp_path: Path) -> None:
     assert config.distribution == Distribution.debian
     assert config.qemu_kvm == ConfigFeature.enabled
 
+    (d / "mkosi.conf").unlink()
+
+    with chdir(d):
+        _, [config] = parse_config(["--profile", "profile"])
+
+    assert config.profile == "profile"
+    # mkosi.conf.d/ should override the profile
+    assert config.distribution == Distribution.debian
+    assert config.qemu_kvm == ConfigFeature.enabled
+
 
 def test_override_default(tmp_path: Path) -> None:
     d = tmp_path