Skip to content

Commit

Permalink
Update Script/Main.py so it uses importlib
Browse files Browse the repository at this point in the history
instead of deprecated imp module.

Signed-off-by: Mats Wichmann <mats@linux.com>
  • Loading branch information
mwichmann committed Aug 2, 2019
1 parent 4307e4f commit b05ec41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- JSON encoding errors for CacheDir config
- JSON decoding errors for CacheDir config

From Mats Wichmann:
- Script/Main.py now uses importlib in the PY3 case.


RELEASE 3.1.0 - Mon, 20 Jul 2019 16:59:23 -0700

Expand Down
26 changes: 19 additions & 7 deletions src/engine/SCons/Script/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
import SCons.Script
import SCons.Taskmaster
import SCons.Util
from SCons.Util import PY3
import SCons.Warnings

import SCons.Script.Interactive

# Global variables
Expand Down Expand Up @@ -714,11 +714,20 @@ def _load_site_scons_dir(topdir, site_dir_name=None):
site_init_file = os.path.join(site_dir, site_init_filename)
site_tools_dir = os.path.join(site_dir, site_tools_dirname)
if os.path.exists(site_init_file):
import imp, re
if PY3:
import importlib
else:
import imp
import re

try:
try:
fp, pathname, description = imp.find_module(site_init_modname,
[site_dir])
if PY3:
spec = importlib.util.find_spec(site_init_modname)
fp = open(spec.origin, 'r')
else:
fp, pathname, description = imp.find_module(site_init_modname, [site_dir])

# Load the file into SCons.Script namespace. This is
# opaque and clever; m is the module object for the
# SCons.Script module, and the exec ... in call executes a
Expand All @@ -732,9 +741,12 @@ def _load_site_scons_dir(topdir, site_dir_name=None):
fmt = 'cannot import site_init.py: missing SCons.Script module %s'
raise SCons.Errors.InternalError(fmt % repr(e))
try:
sfx = description[0]
modname = os.path.basename(pathname)[:-len(sfx)]
site_m = {"__file__": pathname, "__name__": modname, "__doc__": None}
if PY3:
site_m = {"__file__": spec.origin, "__name__": spec.name, "__doc__": None}
else:
sfx = description[0]
modname = os.path.basename(pathname)[:-len(sfx)]
site_m = {"__file__": pathname, "__name__": modname, "__doc__": None}
re_special = re.compile("__[^_]+__")
for k in list(m.__dict__.keys()):
if not re_special.match(k):
Expand Down

0 comments on commit b05ec41

Please sign in to comment.