From 47dc4937019390a944fe4db3567e474fe9abd70f Mon Sep 17 00:00:00 2001 From: Clayton Craft <clayton@craftyguy.net> Date: Thu, 17 Oct 2024 23:05:48 -0700 Subject: [PATCH] pmb.parse.depends.package_provider: add type hinting and fix references (MR 2439) pmb.parse.apkindex.providers now returns a dict of string:ApkindexBlock, probably from 71772b9b6 This adds type hinting to package_provider to reflect this, and fixes code that calls it to properly deal with the possible return types. Without this, building FDE images is broken. --- pmb/install/_install.py | 8 ++++++-- pmb/parse/depends.py | 12 +++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pmb/install/_install.py b/pmb/install/_install.py index 4b8917c68..7d1573ce8 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -1291,8 +1291,12 @@ def create_device_rootfs(args: PmbArgs, step, steps): unlocker = pmb.parse.depends.package_provider( "postmarketos-fde-unlocker", install_packages, chroot ) - if unlocker["pkgname"] not in install_packages: - install_packages += [unlocker["pkgname"]] + if not unlocker: + raise RuntimeError( + "Full disk encryption enabled but unable to find any suitable FDE unlocker app" + ) + if unlocker.pkgname not in install_packages: + install_packages += [unlocker.pkgname] else: install_packages += ["postmarketos-base-nofde"] diff --git a/pmb/parse/depends.py b/pmb/parse/depends.py index 2d05269c1..861ec4c75 100644 --- a/pmb/parse/depends.py +++ b/pmb/parse/depends.py @@ -29,11 +29,12 @@ def package_from_aports(pkgname_depend): return {"pkgname": pkgname, "depends": apkbuild["depends"], "version": version} -def package_provider(pkgname, pkgnames_install, suffix: Chroot = Chroot.native()): +def package_provider( + pkgname, pkgnames_install, suffix: Chroot = Chroot.native() +) -> pmb.core.apkindex_block.ApkindexBlock | None: """ :param pkgnames_install: packages to be installed - :returns: a block from the apkindex: {"pkgname": "...", ...} - or None (no provider found) + :returns: ApkindexBlock object or None (no provider found) """ # Get all providers arch = suffix.arch @@ -105,10 +106,7 @@ def package_from_index( return package_aport # Binary package outdated - if ( - package_aport - and pmb.parse.version.compare(package_aport["version"], provider["version"]) == 1 - ): + if package_aport and pmb.parse.version.compare(package_aport["version"], provider.version) == 1: logging.verbose(pkgname_depend + ": binary package is outdated") return package_aport -- GitLab