From add39d1a57ff06ac7927c7fe7b57eaa3c8978c82 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Sun, 12 Apr 2020 17:15:19 +0200 Subject: [PATCH] pmb.config.init: fix perf regression when selecting "none" UI (MR 1913) The ui-extras questions will attempt to find a postmarketos-ui- package in pmaports. If the package does not exist as "root" APKBUILD it currently attempts to parse all APKBUILDs in case it is somewhere defined as a subpackage. This is really slow (up to 2-3 seconds), which feels weird during "pmbootstrap init". For the UI packages we specifically look for the root UI package, not the subpackage, so let's skip searching for subpackages in this case. This makes selecting the "none" UI nice and fast again. --- pmb/config/init.py | 3 ++- pmb/helpers/pmaports.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pmb/config/init.py b/pmb/config/init.py index 17ed9904..3591a753 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -90,7 +90,8 @@ def ask_for_ui(args): def ask_for_ui_extras(args, ui): - apkbuild = pmb.helpers.pmaports.get(args, "postmarketos-ui-" + ui, must_exist=False) + apkbuild = pmb.helpers.pmaports.get(args, "postmarketos-ui-" + ui, + subpackages=False, must_exist=False) if not apkbuild: return False diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index a6e25b99..f1486f8e 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -163,13 +163,15 @@ def find(args, package, must_exist=True): return ret -def get(args, pkgname, must_exist=True): +def get(args, pkgname, must_exist=True, subpackages=True): """ Find and parse an APKBUILD file. Run 'pmbootstrap apkbuild_parse hello-world' for a full output example. Relevant variables are defined in pmb.config.apkbuild_attributes. :param pkgname: the package name to find :param must_exist: raise an exception when it can't be found + :param subpackages: also search for subpackages with the specified names + (slow! might need to parse all APKBUILDs to find it) :returns: relevant variables from the APKBUILD as dictionary, e.g.: { "pkgname": "hello-world", "arch": ["all"], @@ -178,9 +180,17 @@ def get(args, pkgname, must_exist=True): "options": [], ... } """ - aport = find(args, pkgname, must_exist) - if aport: - return pmb.parse.apkbuild(args, aport + "/APKBUILD") + if subpackages: + aport = find(args, pkgname, must_exist) + if aport: + return pmb.parse.apkbuild(args, aport + "/APKBUILD") + else: + path = _find_apkbuilds(args).get(pkgname) + if path: + return pmb.parse.apkbuild(args, path) + if must_exist: + raise RuntimeError(f"Could not find APKBUILD for package: {pkgname}") + return None