"""Check that the root was populated by looking for a os-release file."""
osrelease = state.root / "usr/lib/os-release"
if not osrelease.exists():
- die(f"{osrelease} not found.",
- hint="The root must be populated by the distribution, or from base trees, skeleton trees, and prepare scripts.")
+ die(
+ f"{osrelease} not found.",
+ hint=(
+ "The root must be populated by the distribution, or from base trees, "
+ "skeleton trees, and prepare scripts."
+ )
+ )
def configure_os_release(state: MkosiState) -> None:
ExecStart=-/sbin/agetty -o '-f -p -- \\\\u' --autologin root --noclear --keep-baud console 115200,38400,9600 $TERM
StandardInput=tty
StandardOutput=tty
- """
+ """ # noqa: E501
)
dropin = state.root / "usr/lib/systemd/system/getty@tty1.service.d/autologin.conf"
ExecStart=-/sbin/agetty -o '-f -p -- \\\\u' --autologin root --keep-baud 115200,57600,38400,9600 - $TERM
StandardInput=tty
StandardOutput=tty
- """
+ """ # noqa: E501
)
distribution = state.config.distribution
image = Path("/") / kimg.relative_to(state.root / "efi")
cmdline = " ".join(state.config.kernel_command_line)
- initrds = " ".join([os.fspath(Path("/") / initrd.relative_to(state.root / "efi")) for initrd in initrds])
+ initrds = " ".join(
+ [os.fspath(Path("/") / initrd.relative_to(state.root / "efi")) for initrd in initrds]
+ )
kmods = Path("/") / kmods.relative_to(state.root / "efi")
f.write(
def configure_initrd(state: MkosiState) -> None:
- if not (state.root / "init").exists() and not (state.root / "init").is_symlink() and (state.root / "usr/lib/systemd/systemd").exists():
+ if (
+ not (state.root / "init").exists() and
+ not (state.root / "init").is_symlink() and
+ (state.root / "usr/lib/systemd/systemd").exists()
+ ):
(state.root / "init").symlink_to("/usr/lib/systemd/systemd")
if not state.config.make_initrd:
import uuid
from collections.abc import Collection, Iterable, Iterator, Sequence
from pathlib import Path
-from typing import Any, Callable, Optional, Type, Union, cast
+from typing import Any, Callable, Optional, TypeVar, Union, cast
from mkosi.architecture import Architecture
from mkosi.distributions import Distribution, detect_distribution
detected = detect_distribution()[0]
if not detected:
- logging.info("Distribution of your host can't be detected or isn't a supported target. Defaulting to Distribution=none.")
+ logging.info(
+ "Distribution of your host can't be detected or isn't a supported target. "
+ "Defaulting to Distribution=none."
+ )
return Distribution.none
return detected
die(". and .. are not valid filenames")
if "/" in value:
- die(f"{value!r} is not a valid filename. (Output= requires a filename with no path components, relative to output directory.)")
+ die(
+ f"{value!r} is not a valid filename. "
+ "(Output= requires a filename with no path components, relative to output directory.)"
+ )
return value
)
-def create_argument_parser(action: Type[argparse.Action]) -> argparse.ArgumentParser:
+def create_argument_parser(action: type[argparse.Action]) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="mkosi",
description="Build Bespoke OS Images",
namespace: argparse.Namespace,
defaults: argparse.Namespace,
) -> Iterator[None]:
- l = len(getattr(namespace, "include", []))
+ current_num_of_includes = len(getattr(namespace, "include", []))
try:
yield
finally:
# Parse any includes that were added after yielding.
- for p in getattr(namespace, "include", [])[l:]:
+ for p in getattr(namespace, "include", [])[current_num_of_includes:]:
st = p.stat()
if (st.st_dev, st.st_ino) in parsed_includes:
import os
import shutil
import urllib.parse
-from collections.abc import Sequence
+from collections.abc import Iterable, Sequence
from pathlib import Path
-from typing import Iterable
from mkosi.architecture import Architecture
from mkosi.config import MkosiConfig
# SPDX-License-Identifier: LGPL-2.1+
-from typing import Iterable
+from collections.abc import Iterable
from mkosi.config import MkosiConfig
from mkosi.distributions import centos
if config.architecture.supports_smbios():
for k, v in config.credentials.items():
+ payload = base64.b64encode(v.encode()).decode()
cmdline += [
- "-smbios", f"type=11,value=io.systemd.credential.binary:{k}={base64.b64encode(v.encode()).decode()}"
+ "-smbios", f"type=11,value=io.systemd.credential.binary:{k}={payload}"
]
cmdline += [
"--offline=yes",
fname])
- if firmware == QemuFirmware.linux or config.output_format in (OutputFormat.cpio, OutputFormat.uki, OutputFormat.directory):
+ if (
+ firmware == QemuFirmware.linux or
+ config.output_format in (OutputFormat.cpio, OutputFormat.uki, OutputFormat.directory)
+ ):
if config.output_format == OutputFormat.uki:
kernel = fname if firmware == QemuFirmware.uefi else config.output_dir / config.output_split_kernel
elif config.qemu_kernel:
@property
def cache_dir(self) -> Path:
- return self.config.cache_dir or self.workspace / f"cache/{self.config.distribution}~{self.config.release}~{self.config.architecture}"
+ return (
+ self.config.cache_dir or
+ self.workspace / f"cache/{self.config.distribution}~{self.config.release}~{self.config.architecture}"
+ )
@property
def install_dir(self) -> Path:
with chdir(tmp_path):
_, [config] = parse_config()
assert config.bootable == ConfigFeature.auto
- assert config.split_artifacts == False
+ assert config.split_artifacts is False
# Passing the directory should include both the main config file and the dropin.
_, [config] = parse_config(["--include", os.fspath(tmp_path / "abc")] * 2)
assert config.bootable == ConfigFeature.enabled
- assert config.split_artifacts == True
+ assert config.split_artifacts is True
# The same extra config should not be parsed more than once.
assert config.build_packages == ["abc"]
# Passing the main config file should not include the dropin.
_, [config] = parse_config(["--include", os.fspath(tmp_path / "abc/mkosi.conf")])
assert config.bootable == ConfigFeature.enabled
- assert config.split_artifacts == False
+ assert config.split_artifacts is False
def test_parse_load_verb(tmp_path: Path) -> None: