From: Thomas Schwinge <thomas@codesourcery.com>
To: libabigail@sourceware.org, Dodji Seketeli <dodji@seketeli.org>
Cc: Thomas Schwinge <thomas@codesourcery.com>,
Mark Wielaard <mark@klomp.org>
Subject: [PATCH] Handle several variants of Python 'imp', 'importlib' modules
Date: Wed, 5 Jan 2022 16:32:52 +0100 [thread overview]
Message-ID: <20220105153252.744786-1-thomas@codesourcery.com> (raw)
In-Reply-To: <87ee5oeq3p.fsf@seketeli.org>
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 <thomas@codesourcery.com>
Tested-by: Mark Wielaard <mark@klomp.org> (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 ------------------
--
2.34.1
next prev parent reply other threads:[~2022-01-05 15:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-17 22:26 [PATCH] Replace use of deprecated Python 'imp' module with 'importlib' Thomas Schwinge
2021-12-21 13:31 ` Dodji Seketeli
2021-12-21 13:43 ` Mark Wielaard
2021-12-21 14:04 ` [PATCH] Replace Python 'import importlib' with 'import importlib.machinery' Thomas Schwinge
2021-12-21 15:06 ` Dodji Seketeli
2021-12-21 15:43 ` Mark Wielaard
2021-12-21 16:19 ` Thomas Schwinge
2021-12-21 19:41 ` [PATCH] Handle several variants of Python 'imp', 'importlib' modules Thomas Schwinge
2022-01-03 16:33 ` Dodji Seketeli
2022-01-05 15:32 ` Thomas Schwinge [this message]
2022-01-06 14:44 ` Dodji Seketeli
2022-01-04 14:51 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220105153252.744786-1-thomas@codesourcery.com \
--to=thomas@codesourcery.com \
--cc=dodji@seketeli.org \
--cc=libabigail@sourceware.org \
--cc=mark@klomp.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).