From caacda47a74c8f0ad91c7f4e6f02ae20ffb1aabe Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 1 Sep 2023 10:57:34 +0200 Subject: [PATCH] Replace `!` operator for lists with empty string assignment Let's behave more like systemd and replace the `!` operator for removing values from lists with assigning the empty string to remove all values instead. --- NEWS.md | 10 +++++----- mkosi/config.py | 15 ++++----------- mkosi/resources/mkosi.md | 6 ++---- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index e2f7bc0a6..a371a37e9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,11 +4,11 @@ - `mkosi.version` is now picked up from preset and dropin directories as well following the usual config precedence logic -- The "first assignment wins" logic was dropped from configuration - parsing. Settings parsed later will now override earlier values and - the `!` operator for lists will now remove values already in the list - instead of preventing specific values from being added. -- Add support for configuring custom default values for settings by +- Removed the "first assignment wins" logic from configuration parsing. + Settings parsed later will now override earlier values +- Removed the `!` operator for lists. Instead, assign the empty string + to the list to remove all previous values. +- Added support for configuring custom default values for settings by prefixing their name in the configuration file with `@`. ## v15.1 diff --git a/mkosi/config.py b/mkosi/config.py index 5a307c35e..4fb7ae908 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -360,7 +360,6 @@ def config_make_list_parser(delimiter: str, def config_parse_list(value: Optional[str], old: Optional[list[Any]]) -> list[Any]: new = old.copy() if old else [] - # Empty strings reset the list. if value is None: return [] @@ -373,17 +372,11 @@ def config_make_list_parser(delimiter: str, else: values = value.replace(delimiter, "\n").split("\n") - for v in values: - if not v: - continue - - if v.startswith("!"): - v = v[1:] - new = [n for n in new if not fnmatch.fnmatchcase(str(n), v)] - else: - new.append(parse(v)) + # Empty strings reset the list. + if len(values) == 1 and values[0] == "": + return [] - return new + return new + [parse(v) for v in values if v] return config_parse_list diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 58caa7587..5670c85c9 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -269,10 +269,8 @@ setting. Also note that before v16, we used to do the opposite, where the earlier assignment would be used instead of later assignments. Settings that take a list of values are merged by appending the new -values to the previously configured values. If a value of a list setting -is prefixed with `!`, all existing instances of that value in the list -are removed. Values prefixed with `!` can be globs to remove more than -one value. +values to the previously configured values. Assigning the empty string +to such a setting removes all previously assigned values. If a setting's name in the configuration file is prefixed with `@`, it configures the default value used for that setting if no explicit -- 2.47.3