From fbb34fb9d8397529132826f6bd094f47054a8de8 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sun, 17 Jul 2022 12:30:44 -0600 Subject: zip module loading: fallback for older Pythons zipimport was updated later, the find_spec and exec_module routines were only added here in 3.10, as opposed to 3.4 for importlib. So we need to fall back to the "old way" using load_module if we don't have those routines available - SCons still supposed back to Python 3.6. Signed-off-by: Mats Wichmann --- SCons/Platform/__init__.py | 12 +++++++++--- SCons/Tool/__init__.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/SCons/Platform/__init__.py b/SCons/Platform/__init__.py index e3da6ed..d528969 100644 --- a/SCons/Platform/__init__.py +++ b/SCons/Platform/__init__.py @@ -106,10 +106,16 @@ def platform_module(name=platform_default()): parent = sys.modules['SCons.Platform'].__path__[0] tryname = os.path.join(parent, name + '.zip') importer = zipimport.zipimporter(tryname) - spec = importer.find_spec(full_name) - mod = importlib.util.module_from_spec(spec) + if not hasattr(importer, 'find_spec'): + # zipimport only added find_spec, exec_module in 3.10, + # unlike importlib, where they've been around since 3.4. + # If we don't have 'em, use the old way. + mod = importer.load_module(full_name) + else: + spec = importer.find_spec(full_name) + mod = importlib.util.module_from_spec(spec) + importer.exec_module(mod) sys.modules[full_name] = mod - importer.exec_module(mod) except zipimport.ZipImportError: raise SCons.Errors.UserError("No platform named '%s'" % name) diff --git a/SCons/Tool/__init__.py b/SCons/Tool/__init__.py index 2a3ac2c..1a39a29 100644 --- a/SCons/Tool/__init__.py +++ b/SCons/Tool/__init__.py @@ -208,13 +208,20 @@ class Tool: except KeyError: try: import zipimport + parent = sys.modules['SCons.Tool'].__path__[0] tryname = os.path.join(parent, self.name + '.zip') importer = zipimport.zipimporter(tryname) - spec = importer.find_spec(full_name) - module = importlib.util.module_from_spec(spec) + if not hasattr(importer, 'find_spec'): + # zipimport only added find_spec, exec_module in 3.10, + # unlike importlib, where they've been around since 3.4. + # If we don't have 'em, use the old way. + module = importer.load_module(full_name) + else: + spec = importer.find_spec(full_name) + module = importlib.util.module_from_spec(spec) + importer.exec_module(module) sys.modules[full_name] = module - importer.exec_module(module) setattr(SCons.Tool, self.name, module) return module except zipimport.ZipImportError as e: -- cgit v0.12