Skip to content

Commit 9efe5af

Browse files
authored
Merge pull request #4881 from mwichmann/loader-comments-and-order
Tweak zipimporter loader sections
2 parents 2ca00ce + 5bcb244 commit 9efe5af

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
146146
is renamed to "legacy_sched_deprecated".
147147
- Java tool recognizes all released versions, and no longer needs manual
148148
updating as new releases are made. Default is now latest LTS - v25.
149+
- Clarify internal usage of zipimporter (not user-visible code)
149150
- Fixed an old problem in PDF doc generation where the path to an
150151
image file ended up with a "not found" error.
151152
- Reference manual improvements:

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ long function signature lines, and some linting-inspired cleanups.
117117
- Java tool recognizes all released versions, and no longer needs manual
118118
updating as new releases are made. Default is now latest LTS - v25.
119119

120+
- Clarify internal usage of zipimporter (not user-visible code)
121+
120122
PACKAGING
121123
---------
122124

SCons/Platform/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ def platform_module(name=platform_default()):
116116

117117
platform = sys.modules['SCons.Platform'].__path__[0]
118118
importer = zipimport.zipimporter(platform)
119-
if not hasattr(importer, 'find_spec'):
120-
# zipimport only added find_spec, exec_module in 3.10,
121-
# unlike importlib, where they've been around since 3.4.
122-
# If we don't have 'em, use the old way.
123-
mod = importer.load_module(full_name)
124-
else:
119+
# TODO: remove this check when Python 3.10 becomes base version
120+
if hasattr(importer, 'find_spec'):
121+
# Note zipimporter got these methods later than importlib
125122
spec = importer.find_spec(full_name)
126123
mod = importlib.util.module_from_spec(spec)
127124
importer.exec_module(mod)
125+
else:
126+
# Older Pythons. load_module dropped entirely from
127+
# zimpiporter in 3.15, but a new Python won't take this
128+
# branch anyway so it's okay to ignore checker gripes here.
129+
mod = importer.load_module(full_name)
128130
sys.modules[full_name] = mod
129131
except zipimport.ZipImportError:
130132
raise SCons.Errors.UserError("No platform named '%s'" % name)

SCons/Tool/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,17 @@ def _tool_module(self):
263263

264264
tooldir = sys.modules['SCons.Tool'].__path__[0]
265265
importer = zipimport.zipimporter(tooldir)
266-
if not hasattr(importer, 'find_spec'):
267-
# zipimport only added find_spec, exec_module in 3.10,
268-
# unlike importlib, where they've been around since 3.4.
269-
# If we don't have 'em, use the old way.
270-
module = importer.load_module(full_name)
271-
else:
266+
# TODO: remove this check when Python 3.10 becomes base version
267+
if hasattr(importer, 'find_spec'):
268+
# Note zipimporter got these methods later than importlib
272269
spec = importer.find_spec(full_name)
273-
module = importlib.util.module_from_spec(spec)
274-
importer.exec_module(module)
270+
mod = importlib.util.module_from_spec(spec)
271+
importer.exec_module(mod)
272+
else:
273+
# Older Pythons. load_module dropped entirely from
274+
# zimpiporter in 3.15, but a new Python won't take this
275+
# branch anyway so it's okay to ignore checker gripes here.
276+
mod = importer.load_module(full_name)
275277
sys.modules[full_name] = module
276278
setattr(SCons.Tool, self.name, module)
277279
return module

testing/framework/TestSCons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def deprecated_fatal(self, warn, msg):
580580
581581
This method expects a SConscript to be present that will causes
582582
the warning. The method writes a SConstruct that calls the
583-
SConsscript and looks to see what type of result occurs.
583+
SConscript and looks to see what type of result occurs.
584584
585585
The pattern that matches the warning is returned.
586586

0 commit comments

Comments
 (0)