summaryrefslogtreecommitdiff
path: root/engine/SCons/compat/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'engine/SCons/compat/__init__.py')
-rw-r--r--engine/SCons/compat/__init__.py31
1 files changed, 11 insertions, 20 deletions
diff --git a/engine/SCons/compat/__init__.py b/engine/SCons/compat/__init__.py
index 4356940..439d3f6 100644
--- a/engine/SCons/compat/__init__.py
+++ b/engine/SCons/compat/__init__.py
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001 - 2017 The SCons Foundation
+# Copyright (c) 2001 - 2019 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -57,31 +57,22 @@ function defined below loads the module as the "real" name (without the
rest of our code will find our pre-loaded compatibility module.
"""
-__revision__ = "src/engine/SCons/compat/__init__.py 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
+__revision__ = "src/engine/SCons/compat/__init__.py 72ae09dc35ac2626f8ff711d8c4b30b6138e08e3 2019-08-08 14:50:06 bdeegan"
import os
import sys
-import imp # Use the "imp" module to protect imports from fixers.
+import importlib
PYPY = hasattr(sys, 'pypy_translation_info')
-def import_as(module, name):
- """
- Imports the specified module (from our local directory) as the
- specified name, returning the loaded module object.
- """
- dir = os.path.split(__file__)[0]
- return imp.load_module(name, *imp.find_module(module, [dir]))
-
-
def rename_module(new, old):
"""
- Attempts to import the old module and load it under the new name.
+ Attempt to import the old module and load it under the new name.
Used for purely cosmetic name changes in Python 3.x.
"""
try:
- sys.modules[new] = imp.load_module(old, *imp.find_module(old))
+ sys.modules[new] = importlib.import_module(old)
return True
except ImportError:
return False
@@ -98,7 +89,7 @@ import pickle
# Was pickle.HIGHEST_PROTOCOL
# Changed to 2 so py3.5+'s pickle will be compatible with py2.7.
-PICKLE_PROTOCOL = 2
+PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
# TODO: FIXME
# In 3.x, 'profile' automatically loads the fast version if available.
@@ -122,28 +113,28 @@ except AttributeError:
# intern into the sys package
sys.intern = intern
-# Preparing for 3.x. UserDict, UserList, UserString are in
-# collections for 3.x, but standalone in 2.7.x
+# UserDict, UserList, UserString are in # collections for 3.x,
+# but standalone in 2.7.x. Monkey-patch into collections for 2.7.
import collections
try:
collections.UserDict
except AttributeError:
- exec ('from UserDict import UserDict as _UserDict')
+ from UserDict import UserDict as _UserDict
collections.UserDict = _UserDict
del _UserDict
try:
collections.UserList
except AttributeError:
- exec ('from UserList import UserList as _UserList')
+ from UserList import UserList as _UserList
collections.UserList = _UserList
del _UserList
try:
collections.UserString
except AttributeError:
- exec ('from UserString import UserString as _UserString')
+ from UserString import UserString as _UserString
collections.UserString = _UserString
del _UserString