summaryrefslogtreecommitdiff
path: root/src/engine/SCons/compat/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/compat/__init__.py')
-rw-r--r--src/engine/SCons/compat/__init__.py161
1 files changed, 32 insertions, 129 deletions
diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py
index 62f28f2..000b81f 100644
--- a/src/engine/SCons/compat/__init__.py
+++ b/src/engine/SCons/compat/__init__.py
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001 - 2015 The SCons Foundation
+# Copyright (c) 2001 - 2016 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -35,9 +35,6 @@ the builtins namespace or the global module list so that the rest
of our code can use the objects and names imported here regardless of
Python version.
-Simply enough, things that go in the builtins name space come from
-our _scons_builtins module.
-
The rest of the things here will be in individual compatibility modules
that are either: 1) suitably modified copies of the future modules that
we want to use; or 2) backwards compatible re-implementations of the
@@ -60,7 +57,7 @@ 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 rel_2.4.1:3453:73fefd3ea0b0 2015/11/09 03:25:05 bdbaddog"
+__revision__ = "src/engine/SCons/compat/__init__.py rel_2.5.0:3543:937e55cd78f7 2016/04/09 11:29:54 bdbaddog"
import os
import sys
@@ -85,93 +82,8 @@ def rename_module(new, old):
except ImportError:
return False
-
-rename_module('builtins', '__builtin__')
-import _scons_builtins
-
-
-try:
- import hashlib
-except ImportError:
- # Pre-2.5 Python has no hashlib module.
- try:
- import_as('_scons_hashlib', 'hashlib')
- except ImportError:
- # If we failed importing our compatibility module, it probably
- # means this version of Python has no md5 module. Don't do
- # anything and let the higher layer discover this fact, so it
- # can fall back to using timestamp.
- pass
-
-try:
- set
-except NameError:
- # Pre-2.4 Python has no native set type
- import_as('_scons_sets', 'sets')
- import builtins, sets
- builtins.set = sets.Set
-
-
-try:
- import collections
-except ImportError:
- # Pre-2.4 Python has no collections module.
- import_as('_scons_collections', 'collections')
-else:
- try:
- collections.UserDict
- except AttributeError:
- exec('from UserDict import UserDict as _UserDict')
- collections.UserDict = _UserDict
- del _UserDict
- try:
- collections.UserList
- except AttributeError:
- exec('from UserList import UserList as _UserList')
- collections.UserList = _UserList
- del _UserList
- try:
- collections.UserString
- except AttributeError:
- exec('from UserString import UserString as _UserString')
- collections.UserString = _UserString
- del _UserString
-
-
-try:
- import io
-except ImportError:
- # Pre-2.6 Python has no io module.
- import_as('_scons_io', 'io')
-
-
-try:
- os.devnull
-except AttributeError:
- # Pre-2.4 Python has no os.devnull attribute
- _names = sys.builtin_module_names
- if 'posix' in _names:
- os.devnull = '/dev/null'
- elif 'nt' in _names:
- os.devnull = 'nul'
- os.path.devnull = os.devnull
-try:
- os.path.lexists
-except AttributeError:
- # Pre-2.4 Python has no os.path.lexists function
- def lexists(path):
- return os.path.exists(path) or os.path.islink(path)
- os.path.lexists = lexists
-
-
-# When we're using the '-3' option during regression tests, importing
-# cPickle gives a warning no matter how it's done, so always use the
-# real profile module, whether it's fast or not.
-if os.environ.get('SCONS_HORRIBLE_REGRESSION_TEST_HACK') is None:
- # Not a regression test with '-3', so try to use faster version.
- # In 3.x, 'pickle' automatically loads the fast version if available.
- rename_module('pickle', 'cPickle')
-
+# In 3.x, 'pickle' automatically loads the fast version if available.
+rename_module('pickle', 'cPickle')
# In 3.x, 'profile' automatically loads the fast version if available.
rename_module('profile', 'cProfile')
@@ -185,49 +97,40 @@ rename_module('queue', 'Queue')
rename_module('winreg', '_winreg')
+# Python 3 moved builtin intern() to sys package
+# To make porting easier, make intern always live
+# in sys package (for python 2.7.x)
+try:
+ sys.intern
+except AttributeError:
+ # We must be using python 2.7.x so monkey patch
+ # 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
+import collections
try:
- import subprocess
-except ImportError:
- # Pre-2.4 Python has no subprocess module.
- import_as('_scons_subprocess', 'subprocess')
+ collections.UserDict
+except AttributeError:
+ exec('from UserDict import UserDict as _UserDict')
+ collections.UserDict = _UserDict
+ del _UserDict
try:
- sys.intern
+ collections.UserList
except AttributeError:
- # Pre-2.6 Python has no sys.intern() function.
- import builtins
- try:
- sys.intern = builtins.intern
- except AttributeError:
- # Pre-2.x Python has no builtin intern() function.
- def intern(x):
- return x
- sys.intern = intern
- del intern
+ exec('from UserList import UserList as _UserList')
+ collections.UserList = _UserList
+ del _UserList
+
try:
- sys.maxsize
+ collections.UserString
except AttributeError:
- # Pre-2.6 Python has no sys.maxsize attribute
- # Wrapping sys in () is silly, but protects it from 2to3 renames fixer
- sys.maxsize = (sys).maxint
-
-
-if os.environ.get('SCONS_HORRIBLE_REGRESSION_TEST_HACK') is not None:
- # We can't apply the 'callable' fixer until the floor is 2.6, but the
- # '-3' option to Python 2.6 and 2.7 generates almost ten thousand
- # warnings. This hack allows us to run regression tests with the '-3'
- # option by replacing the callable() built-in function with a hack
- # that performs the same function but doesn't generate the warning.
- # Note that this hack is ONLY intended to be used for regression
- # testing, and should NEVER be used for real runs.
- from types import ClassType
- def callable(obj):
- if hasattr(obj, '__call__'): return True
- if isinstance(obj, (ClassType, type)): return True
- return False
- import builtins
- builtins.callable = callable
- del callable
+ exec('from UserString import UserString as _UserString')
+ collections.UserString = _UserString
+ del _UserString
# Local Variables: