From patchwork Tue Dec 21 19:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 49158 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 644CB3858039 for ; Tue, 21 Dec 2021 19:41:32 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from smtprelay05.ispgateway.de (smtprelay05.ispgateway.de [80.67.31.99]) by sourceware.org (Postfix) with ESMTPS id CDC0C3858425 for ; Tue, 21 Dec 2021 19:41:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDC0C3858425 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 [192.94.31.2] (helo=dem-tschwing-1.ger.mentorg.com) by smtprelay05.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mzl06-0000UG-TT; Tue, 21 Dec 2021 20:40:43 +0100 Received: (nullmailer pid 2386256 invoked by uid 1000); Tue, 21 Dec 2021 19:41:25 -0000 From: Thomas Schwinge To: libabigail@sourceware.org Subject: [PATCH] Handle several variants of Python 'imp', 'importlib' modules Date: Tue, 21 Dec 2021 20:41:17 +0100 Message-Id: <20211221194117.2386192-1-thomas@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <87zgouvskb.fsf@euler.schwinge.homeip.net> References: <87zgouvskb.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Df-Sender: b3V0Z29pbmdAc2Nod2luZ2UubmFtZQ== X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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. Once more, I've asked The Internet what to do about that, and this commit is the result. But beware: I'm still not much of a Python wizard. * tests/mockfedabipkgdiff.in: Handle several variants of Python 'imp', 'importlib' modules. --- tests/mockfedabipkgdiff.in | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/mockfedabipkgdiff.in b/tests/mockfedabipkgdiff.in index 29a28ad9..1e562666 100644 --- a/tests/mockfedabipkgdiff.in +++ b/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 ------------------