diff options
author | Mats Wichmann <mats@linux.com> | 2022-07-19 17:53:35 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2022-07-19 17:53:35 (GMT) |
commit | fa6c77d7ba2ca9427401d926066356b39b734663 (patch) | |
tree | f4464ec6cdc2b95be1669755aa9df7f69e25a3cd | |
parent | fbb34fb9d8397529132826f6bd094f47054a8de8 (diff) | |
download | SCons-fa6c77d7ba2ca9427401d926066356b39b734663.zip SCons-fa6c77d7ba2ca9427401d926066356b39b734663.tar.gz SCons-fa6c77d7ba2ca9427401d926066356b39b734663.tar.bz2 |
load_module work: back off zipimport changes
Apparently, the zipimport code was not intended to load modules
(platform, tool) that were stored in individual zipfiles;
instead it was added to support scons itself running inside a
zipfile in the form of a py2exe bundle. Undid the changes which
tried to find a modulename.zip file and load it, and the test
in Platform that actually verfied it works, no need to add a
new feature nobody is asking for.
Signed-off-by: Mats Wichmann <mats@linux.com>
-rwxr-xr-x | CHANGES.txt | 2 | ||||
-rwxr-xr-x | RELEASE.txt | 5 | ||||
-rw-r--r-- | SCons/Platform/PlatformTests.py | 7 | ||||
-rw-r--r-- | SCons/Platform/__init__.py | 11 | ||||
-rw-r--r-- | SCons/Platform/testzip.zip | bin | 1142 -> 0 bytes | |||
-rw-r--r-- | SCons/Tool/__init__.py | 22 |
6 files changed, 30 insertions, 17 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index aa154cc..4c694d2 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -206,6 +206,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER no longer uses the deprecated (since Py 3.10) importlib.load_module routine, shifting to the preferred exec_module. Old Python 2 compatible import fallback (using the imp module) in tool module loading is dropped. + Tool module loading no longer special-cases Jython, which is a dead + project as far as SCons (no timeline in sight for Python 3 support). From Zhichang Yu: - Added MSVC_USE_SCRIPT_ARGS variable to pass arguments to MSVC_USE_SCRIPT. diff --git a/RELEASE.txt b/RELEASE.txt index c86c1d5..6f9c4a8 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -113,6 +113,11 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY if scons can determine the ninja file doesnot need to be regenerated, which will also skip restarting the scons daemon. Note this option is could result in incorrect rebuilds if scons Glob or scons generated files are used in ninja build target's command lines. +- Tool loading used to have a special case for Jython, it no longer does. This effectively + means SCons doesn't work with Jython, which has in reality been the case ever since + SCons dropped Python 2 support - there is still no timeline for Jython switching to + Python 3 compatibility. + FIXES ----- diff --git a/SCons/Platform/PlatformTests.py b/SCons/Platform/PlatformTests.py index 195243a..ee0ab75 100644 --- a/SCons/Platform/PlatformTests.py +++ b/SCons/Platform/PlatformTests.py @@ -112,13 +112,6 @@ class PlatformTestCase(unittest.TestCase): assert env['HOST_OS'] == 'hpux', env assert env['HOST_ARCH'] != '', env - p = SCons.Platform.Platform('testzip') - assert str(p) == 'testzip', p - env = Environment() - p(env) - assert env['HOST_OS'] == 'zippy', env - assert env['TESTDUMMY'] == 1866, env - p = SCons.Platform.Platform('win32') assert str(p) == 'win32', p env = Environment() diff --git a/SCons/Platform/__init__.py b/SCons/Platform/__init__.py index d528969..3fa5a75 100644 --- a/SCons/Platform/__init__.py +++ b/SCons/Platform/__init__.py @@ -99,13 +99,14 @@ def platform_module(name=platform_default()): mod = importlib.import_module("." + name, __name__) except ModuleNotFoundError: try: - # because we don't do this import using sys.path, - # need to try zipimport explicitly. + # This support was added to enable running inside + # a py2exe bundle a long time ago - unclear if it's + # still needed. It is *not* intended to load individual + # platform modules stored in a zipfile. import zipimport - parent = sys.modules['SCons.Platform'].__path__[0] - tryname = os.path.join(parent, name + '.zip') - importer = zipimport.zipimporter(tryname) + platform = sys.modules['SCons.Platform'].__path__[0] + importer = zipimport.zipimporter(platform) 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. diff --git a/SCons/Platform/testzip.zip b/SCons/Platform/testzip.zip Binary files differdeleted file mode 100644 index 05d1b1c..0000000 --- a/SCons/Platform/testzip.zip +++ /dev/null diff --git a/SCons/Tool/__init__.py b/SCons/Tool/__init__.py index 1a39a29..019a902 100644 --- a/SCons/Tool/__init__.py +++ b/SCons/Tool/__init__.py @@ -136,6 +136,12 @@ class Tool: spec = None found_name = self.name add_to_scons_tools_namespace = False + + + # Search for the tool module, but don't import it, yet. + # + # First look in the toolpath: these take priority. + # TODO: any reason to not just use find_spec here? for path in self.toolpath: sepname = self.name.replace('.', os.path.sep) file_path = os.path.join(path, "%s.py" % sepname) @@ -156,6 +162,7 @@ class Tool: else: continue + # Now look in the builtin tools (SCons.Tool package) if spec is None: if debug: sys.stderr.write("NO SPEC :%s\n" % self.name) spec = importlib.util.find_spec("." + self.name, package='SCons.Tool') @@ -165,12 +172,14 @@ class Tool: if debug: sys.stderr.write("Spec Found? .%s :%s\n" % (self.name, spec)) if spec is None: + # we are going to bail out here, format up stuff for the msg sconstools = os.path.normpath(sys.modules['SCons.Tool'].__path__[0]) if self.toolpath: sconstools = ", ".join(self.toolpath) + ", " + sconstools error_string = "No tool module '%s' found in %s" % (self.name, sconstools) raise SCons.Errors.UserError(error_string) + # We have a module spec, so we're good to go. module = importlib.util.module_from_spec(spec) if module is None: if debug: print("MODULE IS NONE:%s" % self.name) @@ -198,20 +207,23 @@ class Tool: sys.path = oldpythonpath return found_module - # we didn't find the module, go back and try some other things - # was this name previously imported? Is there a zipfile? sys.path = oldpythonpath + # We try some other things here, but this is essentially dead code, + # because we bailed out above if we didn't find a module spec. full_name = 'SCons.Tool.' + self.name try: return sys.modules[full_name] except KeyError: try: + # This support was added to enable running inside + # a py2exe bundle a long time ago - unclear if it's + # still needed. It is *not* intended to load individual + # tool modules stored in a zipfile. import zipimport - parent = sys.modules['SCons.Tool'].__path__[0] - tryname = os.path.join(parent, self.name + '.zip') - importer = zipimport.zipimporter(tryname) + tooldir = sys.modules['SCons.Tool'].__path__[0] + importer = zipimport.zipimporter(tooldir) 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. |