Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ def config_match_build_sources(match: str, value: list[ConfigTree]) -> bool:

def config_make_list_matcher(parse: Callable[[str], T]) -> ConfigMatchCallback[list[T]]:
def config_match_list(match: str, value: list[T]) -> bool:
if not match:
return len(value) == 0

return parse(match) in value

return config_match_list
Expand Down Expand Up @@ -4255,9 +4258,6 @@ def match_config(self, path: Path) -> bool:

v = self.expand_specifiers(v, path)

if not v:
die("Match value cannot be empty")

if s := SETTINGS_LOOKUP_BY_NAME.get(k):
if not s.match:
die(f"{k} cannot be used in [{section}]")
Expand Down
34 changes: 28 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,31 @@ def test_match_multiple(tmp_path: Path) -> None:
assert config.image_id != "abcde"


@pytest.mark.parametrize("dist1,dist2", itertools.combinations_with_replacement(Distribution, 2))
def test_match_empty(tmp_path: Path) -> None:
with chdir(tmp_path):
Path("mkosi.conf").write_text(
"""\
[Match]
Profiles=

[Build]
Environment=ABC=QED
"""
)

_, [config] = parse_config([])

assert config.environment.get("ABC") == "QED"

_, [config] = parse_config(["--profile", "profile"])

assert config.environment.get("ABC") is None


@pytest.mark.parametrize(
"dist1,dist2",
itertools.combinations_with_replacement([Distribution.debian, Distribution.opensuse], 2),
)
def test_match_distribution(tmp_path: Path, dist1: Distribution, dist2: Distribution) -> None:
with chdir(tmp_path):
parent = Path("mkosi.conf")
Expand Down Expand Up @@ -750,7 +774,7 @@ def test_match_distribution(tmp_path: Path, dist1: Distribution, dist2: Distribu
assert "testpkg3" in conf.packages


@pytest.mark.parametrize("release1,release2", itertools.combinations_with_replacement([36, 37, 38], 2))
@pytest.mark.parametrize("release1,release2", itertools.combinations_with_replacement([36, 37], 2))
def test_match_release(tmp_path: Path, release1: int, release2: int) -> None:
with chdir(tmp_path):
parent = Path("mkosi.conf")
Expand Down Expand Up @@ -844,9 +868,7 @@ def test_match_repositories(tmp_path: Path) -> None:
assert config.output == "qed"


@pytest.mark.parametrize(
"image1,image2", itertools.combinations_with_replacement(["image_a", "image_b", "image_c"], 2)
)
@pytest.mark.parametrize("image1,image2", itertools.combinations_with_replacement(["image_a", "image_b"], 2))
def test_match_imageid(tmp_path: Path, image1: str, image2: str) -> None:
with chdir(tmp_path):
parent = Path("mkosi.conf")
Expand Down Expand Up @@ -918,7 +940,7 @@ def test_match_imageid(tmp_path: Path, image1: str, image2: str) -> None:
"op,version",
itertools.product(
["", "==", "<", ">", "<=", ">="],
[122, 123, 124],
[122, 123],
),
)
def test_match_imageversion(tmp_path: Path, op: str, version: str) -> None:
Expand Down