return config_match_enum
+def package_sort_key(package: str) -> tuple[int, str]:
+ """Sorts packages: normal first, paths second, conditional third"""
+
+ if package.startswith("("):
+ return 2, package
+ elif package.startswith("/"):
+ return 1, package
+ return 0, package
+
+
def config_make_list_parser(
*,
delimiter: Optional[str] = None,
parse: Callable[[str], T] = str, # type: ignore # see mypy#3737
unescape: bool = False,
reset: bool = True,
+ key: Optional[Callable[[T], Any]] = None,
) -> ConfigParseCallback[list[T]]:
def config_parse_list(value: Optional[str], old: Optional[list[T]]) -> Optional[list[T]]:
new = old.copy() if old else []
if reset and len(values) == 1 and values[0] == "":
return None
- return new + [parse(v) for v in values if v]
+ new += [parse(v) for v in values if v]
+
+ if key:
+ new.sort(key=key)
+
+ return new
return config_parse_list
long="--package",
metavar="PACKAGE",
section="Content",
- parse=config_make_list_parser(delimiter=","),
+ parse=config_make_list_parser(delimiter=",", key=package_sort_key),
help="Add an additional package to the OS image",
),
ConfigSetting(
long="--build-package",
metavar="PACKAGE",
section="Content",
- parse=config_make_list_parser(delimiter=","),
+ parse=config_make_list_parser(delimiter=",", key=package_sort_key),
help="Additional packages needed for build scripts",
),
ConfigSetting(
long="--volatile-package",
metavar="PACKAGE",
section="Content",
- parse=config_make_list_parser(delimiter=","),
+ parse=config_make_list_parser(delimiter=",", key=package_sort_key),
help="Packages to install after executing build scripts",
),
ConfigSetting(
from mkosi.installer import PackageManager
from mkosi.installer.pacman import Pacman, PacmanRepository
from mkosi.log import complete_step, die
-from mkosi.util import sort_packages
class Installer(DistributionInstaller):
Pacman.invoke(
context,
"--sync",
- ["--needed", "--assume-installed", "initramfs", *sort_packages(packages)],
+ ["--needed", "--assume-installed", "initramfs", *packages],
apivfs=apivfs,
)
from mkosi.log import die
from mkosi.mounts import finalize_certificate_mounts
from mkosi.run import run
-from mkosi.util import sort_packages
class Installer(DistributionInstaller):
[
"--download", "in-advance",
"--recommends" if context.config.with_recommends else "--no-recommends",
- *sort_packages(packages),
+ *packages,
],
apivfs=apivfs,
) # fmt: skip
else:
- Dnf.invoke(context, "install", sort_packages(packages), apivfs=apivfs)
+ Dnf.invoke(context, "install", packages, apivfs=apivfs)
@classmethod
def remove_packages(cls, context: Context, packages: Sequence[str]) -> None:
if context.config.find_binary("zypper"):
- Zypper.invoke(context, "remove", ["--clean-deps", *sort_packages(packages)], apivfs=True)
+ Zypper.invoke(context, "remove", ["--clean-deps", *packages], apivfs=True)
else:
Dnf.invoke(context, "remove", packages, apivfs=True)
return f"{soft}:{hard}"
-def sort_packages(packages: Iterable[str]) -> list[str]:
- """Sorts packages: normal first, paths second, conditional third"""
-
- m = {"(": 2, "/": 1}
- return sorted(packages, key=lambda name: (m.get(name[0], 0), name))
-
-
def flatten(lists: Iterable[Iterable[T]]) -> list[T]:
"""Flatten a sequence of sequences into a single list."""
return list(itertools.chain.from_iterable(lists))
Architecture=arm64
Repositories=epel,epel-next
- [Content]
- Packages=abc
+ [Config]
+ Profiles=abc
[Build]
Environment=MY_KEY=MY_VALUE
assert config.distribution == Distribution.ubuntu
assert config.architecture == Architecture.arm64
- assert config.packages == ["abc"]
+ assert config.profiles == ["abc"]
assert config.output_format == OutputFormat.cpio
assert config.image_id == "base"
[Distribution]
Distribution=debian
- [Content]
- Packages=qed
+ [Config]
+ Profiles=qed
def
[Output]
)
with chdir(d):
- _, [config] = parse_config(["--package", "last"])
+ _, [config] = parse_config(["--profile", "last"])
# Setting a value explicitly in a dropin should override the default from mkosi.conf.
assert config.distribution == Distribution.debian
# Lists should be merged by appending the new values to the existing values. Any values from the CLI
# should be appended to the values from the configuration files.
- assert config.packages == ["abc", "qed", "def", "last"]
+ assert config.profiles == ["abc", "qed", "def", "last"]
assert config.output_format == OutputFormat.cpio
assert config.image_id == "00-dropin"
assert config.image_version == "0"
with chdir(d):
_, [config] = parse_config(["--include", "abc.conf", "--include", "abc.conf"])
- assert config.build_packages == ["def", "abc"]
+ assert config.build_packages == ["abc", "def"]
(d / "mkosi.images").mkdir()