From nobody Mon Feb 9 09:08:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692986287; cv=none; d=zohomail.com; s=zohoarc; b=fvUxk12OqLxgUpmMSqZBk0zio3UaQoJxQ/4HbXWFv2z8IEz7+XaG09M8gy6eQnuyXH4s/WCpMfMavIyKpws/p6zQn4+S4wsTJvpo+PuP8yN4/lgHcLaO7rUC9q5eqWITLHWA6AEkb2RuxvftDbHh988DR6uKF0JLg7P67d61OiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692986287; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E8osTw0eaDWNQGUrJQjpH7Beqw4hBLrIht+qG6Y+ozY=; b=Py7iEBwXYFYiPWJ9SVHgCCNI1u+zQO30X4f/aX4uYXj60EMopXMKKEeQIALrYf1NKBsUMLgXqcNdBAH7dQf+6uQxlyjcPCm9uprbhbYe7+3Vst2ezc/xJ10kn/OoNsOvIeqvDvzLOQ7ChYyw4zxhkmRGlgIb6vk8xO/6TpOv4pM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1692986287819768.7324364309397; Fri, 25 Aug 2023 10:58:07 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-278-p6RmXH_OPVm50eONE6RYxg-1; Fri, 25 Aug 2023 13:56:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 721E38D40B2; Fri, 25 Aug 2023 17:56:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E00A140E950; Fri, 25 Aug 2023 17:56:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4F3CA1946A4E; Fri, 25 Aug 2023 17:56:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1C6E01946A6C for ; Fri, 25 Aug 2023 17:56:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 019B44021B9; Fri, 25 Aug 2023 17:56:04 +0000 (UTC) Received: from orca.. (unknown [10.45.225.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EA984A9004; Fri, 25 Aug 2023 17:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692986286; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=E8osTw0eaDWNQGUrJQjpH7Beqw4hBLrIht+qG6Y+ozY=; b=d3a/dq1SsyyYYzgXHXCF1BfTKqPzvHLHUg8nr38W0rlLVx6u3HN1Vo0pGK1Up+0yt+UmGP XkaF0jpInmmnXFm7yFyMTi7PGDVP/e3rYQ7Vt65e9nnOIRv4J+H0SD5eGdTp/hAX6OC106 aTJma0uCmw2/11hFE1Sab517Ev8Zr18= X-MC-Unique: p6RmXH_OPVm50eONE6RYxg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH 26/33] ci: helper: Add a required_deps higher order helper/decorator Date: Fri, 25 Aug 2023 19:55:34 +0200 Message-ID: <6b38f030f49681f6fcde1668b6f39b9a06655cc0.1692986130.git.eskultet@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Erik Skultety Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692986288754100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Since we'll depend on GitPython for repo cloning, we need to make sure to emit a user friendly error if the module is not installed. This patch introduces a helper which future patches will use as a decorator. Inspiration for this helper has been taken out of lcitool where we use an identical helper for this purpose. Signed-off-by: Erik Skultety Reviewed-by: Daniel P. Berrang=C3=A9 --- ci/helper | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ci/helper b/ci/helper index 60fdaed5f4..780f4161f5 100755 --- a/ci/helper +++ b/ci/helper @@ -14,6 +14,28 @@ import textwrap import util =20 =20 +def required_deps(*deps): + module2pkg =3D { + "git": "GitPython" + } + + def inner_decorator(func): + def wrapped(*args, **kwargs): + cmd =3D func.__name__[len('_action_'):] + for dep in deps: + try: + import importlib + importlib.import_module(dep) + except ImportError: + pkg =3D module2pkg[dep] + msg =3D f"'{pkg}' not found (required by the '{cmd}' c= ommand)" + print(msg, file=3Dsys.stderr) + sys.exit(1) + func(*args, **kwargs) + return wrapped + return inner_decorator + + class Parser: def __init__(self): # Options that are common to all actions that use containers --=20 2.41.0