From patchwork Wed Jan 5 15:32:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 49600 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82736385802E for ; Wed, 5 Jan 2022 15:35:39 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from smtprelay07.ispgateway.de (smtprelay07.ispgateway.de [134.119.228.101]) by sourceware.org (Postfix) with ESMTPS id 2A32A3858433 for ; Wed, 5 Jan 2022 15:33:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A32A3858433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=schwinge.name Received: from [93.210.56.207] (helo=euler.schwinge.homeip.net) by smtprelay07.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n58G0-0002kP-57; Wed, 05 Jan 2022 16:31:20 +0100 Received: (nullmailer pid 744803 invoked by uid 1000); Wed, 05 Jan 2022 15:33:14 -0000 From: Thomas Schwinge To: libabigail@sourceware.org, Dodji Seketeli Subject: [PATCH] Handle several variants of Python 'imp', 'importlib' modules Date: Wed, 5 Jan 2022 16:32:52 +0100 Message-Id: <20220105153252.744786-1-thomas@codesourcery.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <87ee5oeq3p.fsf@seketeli.org> References: <87ee5oeq3p.fsf@seketeli.org> MIME-Version: 1.0 X-Df-Sender: b3V0Z29pbmdAc2Nod2luZ2UubmFtZQ== X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard , Thomas Schwinge Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Fix-up for recent commit f0582fdbf1267f0f34bf3c3b6698b60026410146 "Replace use of deprecated Python 'imp' module with 'importlib'", and commit cc1f38ffedb8d456d43fb52c369409037c5ca4a "Replace Python 'import importlib' with 'import importlib.machinery'", because compatibility... * tests/mockfedabipkgdiff.in: Handle several variants of Python 'imp', 'importlib' modules. Signed-off-by: Thomas Schwinge Tested-by: Mark Wielaard (CentOS 7) --- tests/mockfedabipkgdiff.in | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git tests/mockfedabipkgdiff.in tests/mockfedabipkgdiff.in index 29a28ad9..1e562666 100644 --- tests/mockfedabipkgdiff.in +++ tests/mockfedabipkgdiff.in @@ -39,7 +39,6 @@ variables. import os import tempfile -import importlib.machinery import six try: @@ -69,8 +68,34 @@ def get_download_dir(): return DOWNLOAD_CACHE_DIR +def load_source(name, path): + # Different version of Python want this be done differently. + try: + import importlib.machinery + loader = importlib.machinery.SourceFileLoader(name, path) + import importlib.util + spec = importlib.util.spec_from_loader(name, loader) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + import sys.modules + sys.modules[name] = module + return module + except: + pass + try: + import importlib.machinery + loader = importlib.machinery.SourceFileLoader(name, path) + module = loader.load_module() + return module + except: + pass + import imp + module = imp.load_source(name, path) + return module + + # Import the fedabipkgdiff program file from the source directory. -fedabipkgdiff_mod = importlib.machinery.SourceFileLoader('fedabipkgdiff', FEDABIPKGDIFF).load_module() +fedabipkgdiff_mod = load_source('fedabipkgdiff', FEDABIPKGDIFF) # ----------------- Koji resource storage begins ------------------