]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Get rid of final uses of joinpath()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 6 Aug 2023 07:54:55 +0000 (09:54 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 6 Aug 2023 09:59:10 +0000 (11:59 +0200)
We prefer using parentheses instead of joinpath() these days. This
commit gets rid of the remaining places where we're still using
joinpath().

mkosi/__init__.py
mkosi/config.py
mkosi/distributions/debian.py
mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/manifest.py

index 1ef2ca1da309163440051d2496f093add8fbd38f..c752efda450822e10869429e6f969f4663932622 100644 (file)
@@ -70,7 +70,7 @@ def mount_image(state: MkosiState) -> Iterator[None]:
 
         if state.config.base_trees and state.config.overlay:
             bases = []
-            state.workspace.joinpath("bases").mkdir(exist_ok=True)
+            (state.workspace / "bases").mkdir(exist_ok=True)
 
             for path in state.config.base_trees:
                 d = Path(stack.enter_context(tempfile.TemporaryDirectory(dir=state.workspace / "bases", prefix=path.name)))
@@ -613,11 +613,11 @@ def make_directory(state: MkosiState) -> None:
 
 
 def gen_kernel_images(state: MkosiState) -> Iterator[tuple[str, Path]]:
-    if not state.root.joinpath("usr/lib/modules").exists():
+    if not (state.root / "usr/lib/modules").exists():
         return
 
     for kver in sorted(
-        (k for k in state.root.joinpath("usr/lib/modules").iterdir() if k.is_dir()),
+        (k for k in (state.root / "usr/lib/modules").iterdir() if k.is_dir()),
         key=lambda k: GenericVersion(k.name),
         reverse=True
     ):
@@ -854,8 +854,8 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None:
 
             # See https://systemd.io/AUTOMATIC_BOOT_ASSESSMENT/#boot-counting
             boot_count = ""
-            if state.root.joinpath("etc/kernel/tries").exists():
-                boot_count = f'+{state.root.joinpath("etc/kernel/tries").read_text().strip()}'
+            if (state.root / "etc/kernel/tries").exists():
+                boot_count = f'+{(state.root / "etc/kernel/tries").read_text().strip()}'
 
             if state.config.image_version:
                 boot_binary = state.root / f"efi/EFI/Linux/{image_id}_{state.config.image_version}-{kver}{boot_count}.efi"
@@ -865,10 +865,10 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None:
             else:
                 boot_binary = state.root / f"efi/EFI/Linux/{image_id}-{kver}{boot_count}.efi"
 
-            if state.root.joinpath("etc/kernel/cmdline").exists():
-                cmdline = [state.root.joinpath("etc/kernel/cmdline").read_text().strip()]
-            elif state.root.joinpath("usr/lib/kernel/cmdline").exists():
-                cmdline = [state.root.joinpath("usr/lib/kernel/cmdline").read_text().strip()]
+            if (state.root / "etc/kernel/cmdline").exists():
+                cmdline = [(state.root / "etc/kernel/cmdline").read_text().strip()]
+            elif (state.root / "usr/lib/kernel/cmdline").exists():
+                cmdline = [(state.root / "usr/lib/kernel/cmdline").read_text().strip()]
             else:
                 cmdline = []
 
@@ -879,7 +879,7 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None:
 
             # Older versions of systemd-stub expect the cmdline section to be null terminated. We can't embed
             # nul terminators in argv so let's communicate the cmdline via a file instead.
-            state.workspace.joinpath("cmdline").write_text(f"{' '.join(cmdline).strip()}\x00")
+            (state.workspace / "cmdline").write_text(f"{' '.join(cmdline).strip()}\x00")
 
             stub = state.root / f"usr/lib/systemd/boot/efi/linux{state.config.architecture.to_efi()}.efi.stub"
             if not stub.exists():
@@ -945,12 +945,12 @@ def install_unified_kernel(state: MkosiState, roothash: Optional[str]) -> None:
 
             run(cmd)
 
-            if not state.staging.joinpath(state.config.output_split_uki).exists():
+            if not (state.staging / state.config.output_split_uki).exists():
                 shutil.copy(boot_binary, state.staging / state.config.output_split_uki)
 
             print_output_size(boot_binary)
 
-    if state.config.bootable == ConfigFeature.enabled and not state.staging.joinpath(state.config.output_split_uki).exists():
+    if state.config.bootable == ConfigFeature.enabled and not (state.staging / state.config.output_split_uki).exists():
         die("A bootable image was requested but no kernel was found")
 
 
@@ -1015,7 +1015,7 @@ def calculate_sha256sum(state: MkosiState) -> None:
             for p in state.staging.iterdir():
                 hash_file(f, p)
 
-        state.workspace.joinpath(state.config.output_checksum).rename(state.staging / state.config.output_checksum)
+        (state.workspace / state.config.output_checksum).rename(state.staging / state.config.output_checksum)
 
 
 def calculate_signature(state: MkosiState) -> None:
@@ -1043,9 +1043,9 @@ def calculate_signature(state: MkosiState) -> None:
                 # if possible and fallback to the default path. Without this the
                 # keyring for the root user will instead be used which will fail
                 # for a non-root build.
-                'GNUPGHOME': os.environ.get(
-                    'GNUPGHOME',
-                    os.fspath((Path(os.environ['HOME']).joinpath('.gnupg'))),
+                "GNUPGHOME": os.environ.get(
+                    "GNUPGHOME",
+                    os.fspath(((Path(os.environ["HOME"]) / ".gnupg"))),
                 )
             },
         )
@@ -1187,7 +1187,7 @@ def check_outputs(config: MkosiConfig) -> None:
         config.output_signature if config.sign else None,
         config.output_nspawn_settings if config.nspawn_settings is not None else None,
     ):
-        if f and config.output_dir.joinpath(f).exists():
+        if f and (config.output_dir / f).exists():
             die(f"Output path {f} exists already. (Consider invocation with --force.)")
 
 
@@ -1239,14 +1239,14 @@ def configure_ssh(state: MkosiState) -> None:
 
 
 def configure_initrd(state: MkosiState) -> None:
-    if not state.root.joinpath("init").exists() and state.root.joinpath("usr/lib/systemd/systemd").exists():
-        state.root.joinpath("init").symlink_to("/usr/lib/systemd/systemd")
+    if not (state.root / "init").exists() and (state.root / "usr/lib/systemd/systemd").exists():
+        (state.root / "init").symlink_to("/usr/lib/systemd/systemd")
 
     if not state.config.make_initrd:
         return
 
-    if not state.root.joinpath("etc/initrd-release").exists():
-        state.root.joinpath("etc/initrd-release").symlink_to("/etc/os-release")
+    if not (state.root / "etc/initrd-release").exists():
+        (state.root / "etc/initrd-release").symlink_to("/etc/os-release")
 
 
 def process_kernel_modules(state: MkosiState, kver: str) -> None:
@@ -1404,7 +1404,7 @@ def save_cache(state: MkosiState) -> None:
 
         # We only use the cache-overlay directory for caching if we have a base tree, otherwise we just
         # cache the root directory.
-        if state.workspace.joinpath("cache-overlay").exists():
+        if (state.workspace / "cache-overlay").exists():
             move_tree(state.config, state.workspace / "cache-overlay", final)
         else:
             move_tree(state.config, state.root, final)
@@ -1434,7 +1434,7 @@ def reuse_cache(state: MkosiState) -> bool:
     with complete_step("Copying cached trees"):
         copy_tree(state.config, final, state.root)
         if need_build_packages(state.config):
-            state.workspace.joinpath("build-overlay").symlink_to(build)
+            (state.workspace / "build-overlay").symlink_to(build)
 
     return True
 
@@ -1457,7 +1457,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False)
 
     if not state.config.architecture.is_native():
         cmdline += ["--architecture", str(state.config.architecture)]
-    if not state.staging.joinpath(state.config.output_with_format).exists():
+    if not (state.staging / state.config.output_with_format).exists():
         cmdline += ["--empty=create"]
     if state.config.passphrase:
         cmdline += ["--key-file", state.config.passphrase]
@@ -1477,7 +1477,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False)
         definitions = state.workspace / "repart-definitions"
         if not definitions.exists():
             definitions.mkdir()
-            bootdir = state.root.joinpath("efi/EFI/BOOT")
+            bootdir = state.root / "efi/EFI/BOOT"
 
             # If Bootable=auto and we have at least one UKI and a bootloader, let's generate an ESP partition.
             add = (state.config.bootable == ConfigFeature.enabled or
@@ -1487,7 +1487,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False)
                    any(gen_kernel_images(state))))
 
             if add:
-                definitions.joinpath("00-esp.conf").write_text(
+                (definitions / "00-esp.conf").write_text(
                     dedent(
                         """\
                         [Partition]
@@ -1500,7 +1500,7 @@ def make_image(state: MkosiState, skip: Sequence[str] = [], split: bool = False)
                     )
                 )
 
-            definitions.joinpath("10-root.conf").write_text(
+            (definitions / "10-root.conf").write_text(
                 dedent(
                     f"""\
                     [Partition]
@@ -1633,7 +1633,7 @@ def build_image(args: MkosiArgs, config: MkosiConfig) -> None:
 
         finalize_staging(state)
 
-        output_base = state.config.output_dir.joinpath(state.config.output)
+        output_base = state.config.output_dir / state.config.output
         if not output_base.exists() or output_base.is_symlink():
             output_base.unlink(missing_ok=True)
             output_base.symlink_to(state.config.output_with_compression)
@@ -1866,7 +1866,7 @@ def expand_specifier(s: str) -> str:
 
 
 def needs_build(args: MkosiArgs, config: MkosiConfig) -> bool:
-    return args.verb.needs_build() and (args.force > 0 or not config.output_dir.joinpath(config.output_with_compression).exists())
+    return args.verb.needs_build() and (args.force > 0 or not (config.output_dir / config.output_with_compression).exists())
 
 
 @contextlib.contextmanager
@@ -1879,7 +1879,7 @@ def prepend_to_environ_path(config: MkosiConfig) -> Iterator[None]:
 
         for path in config.extra_search_paths:
             if not path.is_dir():
-                Path(d).joinpath(path.name).symlink_to(path.absolute())
+                (Path(d) / path.name).symlink_to(path.absolute())
 
         news = [os.fspath(path) for path in [Path(d), *config.extra_search_paths] if path.is_dir()]
         olds = os.getenv("PATH", "").split(":")
index 5c1b440100f3707d2adb61d83e7d9d54774c2b70..063752e2efb77d18ee0c0d77462009dd80f9798d 100644 (file)
@@ -1565,8 +1565,8 @@ class MkosiConfigParser:
         if extras:
             # Dropin configuration has priority over any default paths.
 
-            if path.parent.joinpath("mkosi.conf.d").exists():
-                for p in sorted(path.parent.joinpath("mkosi.conf.d").iterdir()):
+            if (path.parent / "mkosi.conf.d").exists():
+                for p in sorted((path.parent / "mkosi.conf.d").iterdir()):
                     if p.is_dir() or p.suffix == ".conf":
                         with chdir(p if p.is_dir() else Path.cwd()):
                             self.parse_config(p if p.is_file() else Path("."), namespace)
index b28000ad967d2bcf238d72dd2837b34ccdae740a..823d14d4eade2052f4b8c462b6fc3432061632f5 100644 (file)
@@ -176,7 +176,7 @@ class DebianInstaller(DistributionInstaller):
 
 
 def install_apt_sources(state: MkosiState, repos: Sequence[str]) -> None:
-    if not state.root.joinpath("usr/bin/apt").exists():
+    if not (state.root / "usr/bin/apt").exists():
         return
 
     sources = state.root / "etc/apt/sources.list"
index da36365a0406088052ce820d6924c1f3df8d36c0..f756017c4fd3963b1bc7efdbba195f70cf9cb0bd 100644 (file)
@@ -10,12 +10,12 @@ from mkosi.util import flatten, sort_packages, umask
 
 
 def setup_apt(state: MkosiState, repos: Sequence[str]) -> None:
-    state.pkgmngr.joinpath("etc/apt").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("etc/apt/apt.conf.d").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("etc/apt/preferences.d").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("etc/apt/sources.list.d").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("var/log/apt").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("var/lib/apt").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/apt").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/apt/apt.conf.d").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/apt/preferences.d").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/apt/sources.list.d").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "var/log/apt").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "var/lib/apt").mkdir(exist_ok=True, parents=True)
 
     # TODO: Drop once apt 2.5.4 is widely available.
     with umask(~0o755):
index 1527ce3ea32ea51eb72a4927ced97210e92e2d8f..aa980e5a7bc40d2551aec86fc88055805a211ead 100644 (file)
@@ -28,9 +28,9 @@ def dnf_executable(state: MkosiState) -> str:
 
 
 def setup_dnf(state: MkosiState, repos: Sequence[Repo], filelists: bool = True) -> None:
-    state.pkgmngr.joinpath("etc/dnf/vars").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("etc/yum.repos.d").mkdir(exist_ok=True, parents=True)
-    state.pkgmngr.joinpath("var/lib/dnf").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/dnf/vars").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "etc/yum.repos.d").mkdir(exist_ok=True, parents=True)
+    (state.pkgmngr / "var/lib/dnf").mkdir(exist_ok=True, parents=True)
 
     config = state.pkgmngr / "etc/dnf/dnf.conf"
 
index 952cf3785395fde917cb96e3b65ab620c0465ed6..ee9e2c2516d32cc5d693f57bac3e369ff82f22ee 100644 (file)
@@ -31,7 +31,7 @@ def setup_pacman(state: MkosiState) -> None:
 
     # Create base layout for pacman and pacman-key
     with umask(~0o755):
-        state.root.joinpath("var/lib/pacman").mkdir(exist_ok=True, parents=True)
+        (state.root / "var/lib/pacman").mkdir(exist_ok=True, parents=True)
 
     config = state.pkgmngr / "etc/pacman.conf"
     if config.exists():
@@ -73,7 +73,7 @@ def setup_pacman(state: MkosiState) -> None:
                 )
             )
 
-        if any(state.pkgmngr.joinpath("etc/pacman.d/").glob("*.conf")):
+        if any((state.pkgmngr / "etc/pacman.d/").glob("*.conf")):
             f.write(
                 textwrap.dedent(
                     f"""\
index d005bf3718ea16b9f9a5d5b7e9510f4a531f4009..81b2290edfd405543c5120d7fb9ed474fcb4b687 100644 (file)
@@ -231,7 +231,7 @@ class Manifest:
             source_package.add(package)
 
     def record_pkg_packages(self, root: Path) -> None:
-        packages = sorted(root.joinpath("var/lib/pacman/local").glob("*/desc"))
+        packages = sorted((root / "var/lib/pacman/local").glob("*/desc"))
 
         for desc in packages:
             name, version, source, arch = parse_pkg_desc(desc)