summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2019-03-11 17:03:29 (GMT)
committerMats Wichmann <mats@linux.com>2019-03-30 13:24:51 (GMT)
commit97c7246f5efb311b007d7aa6b585aa6b47a17230 (patch)
treef9136f64653812657d161949a205fcec7dc1bf7c /src
parenta06f5a80a882e4e2e3937b375c4096605ae251d8 (diff)
downloadSCons-97c7246f5efb311b007d7aa6b585aa6b47a17230.zip
SCons-97c7246f5efb311b007d7aa6b585aa6b47a17230.tar.gz
SCons-97c7246f5efb311b007d7aa6b585aa6b47a17230.tar.bz2
[WIP] [PY 3.8] fix more warnings
Several locations with simple usage of deprecated "imp" module changed to use "importlib". These match with work in #3159, but this is not a complete implementation of #3159. More regex patterns are changed to be raw strings. Some strings which did not seem appropriate to change to raw strings (e.g. contain embedded tabs, which Python should honor) had backslashes escaped to avoid accidental Python interpretation. Example: '\t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />\n' Python 3.8 was Warning \M was an unknown escape. More open().write(), open().read() style usage changed to use context managers so the file is closed. WIP part: even with Python 3.7, the tests which call sconsign.py fail; oddly they do not fail without the patch to compat.py. sconsign.py does an import using imp module (which is what generates the errors) so needs to be updated anyway. It does not quite fit the "simple usage" pattern - can't do a simple relative import since sconsign is normally located elsewhere in the tree than the main scons code body. With this version of the patch, 700 tests now pass with 3.8, and Warning messages reduced to 2800 (current master has 200 pass, 9000 warns) Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'src')
-rw-r--r--src/engine/SCons/Platform/__init__.py11
-rw-r--r--src/engine/SCons/Tool/__init__.py5
-rw-r--r--src/engine/SCons/Tool/cyglink.py2
-rw-r--r--src/engine/SCons/Tool/msvs.py8
-rw-r--r--src/engine/SCons/Tool/packaging/__init__.py8
-rw-r--r--src/engine/SCons/Tool/suncxx.py4
-rw-r--r--src/engine/SCons/compat/__init__.py15
-rw-r--r--src/script/scons-time.py7
8 files changed, 25 insertions, 35 deletions
diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py
index 71d292e..e06eb0f 100644
--- a/src/engine/SCons/Platform/__init__.py
+++ b/src/engine/SCons/Platform/__init__.py
@@ -47,7 +47,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import SCons.compat
-import imp
+import importlib
import os
import sys
import tempfile
@@ -101,13 +101,8 @@ def platform_module(name = platform_default()):
eval(full_name)
else:
try:
- file, path, desc = imp.find_module(name,
- sys.modules['SCons.Platform'].__path__)
- try:
- mod = imp.load_module(full_name, file, path, desc)
- finally:
- if file:
- file.close()
+ # the specific platform module is a relative import
+ mod = importlib.import_module("." + name, __name__)
except ImportError:
try:
import zipimport
diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py
index 74dba75..ae65d53 100644
--- a/src/engine/SCons/Tool/__init__.py
+++ b/src/engine/SCons/Tool/__init__.py
@@ -37,12 +37,11 @@ tool definition.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import imp
-import importlib
import sys
import re
import os
import shutil
+import importlib
import SCons.Builder
import SCons.Errors
@@ -121,6 +120,8 @@ class Tool(object):
self.options = module.options
def _load_dotted_module_py2(self, short_name, full_name, searchpaths=None):
+ import imp
+
splitname = short_name.split('.')
index = 0
srchpths = searchpaths
diff --git a/src/engine/SCons/Tool/cyglink.py b/src/engine/SCons/Tool/cyglink.py
index f69b886..c3d78de 100644
--- a/src/engine/SCons/Tool/cyglink.py
+++ b/src/engine/SCons/Tool/cyglink.py
@@ -133,7 +133,7 @@ def _versioned_lib_suffix(env, suffix, version):
if Verbose:
print("_versioned_lib_suffix: suffix= ", suffix)
print("_versioned_lib_suffix: version= ", version)
- cygversion = re.sub('\.', '-', version)
+ cygversion = re.sub(r'\.', '-', version)
if not suffix.startswith('-' + cygversion):
suffix = '-' + cygversion + suffix
if Verbose:
diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py
index f4439ba..ff81732 100644
--- a/src/engine/SCons/Tool/msvs.py
+++ b/src/engine/SCons/Tool/msvs.py
@@ -1080,7 +1080,7 @@ V10DSPPropertyGroupCondition = """\
V10DSPImportGroupCondition = """\
\t<ImportGroup Condition="'$(Configuration)|$(Platform)'=='%(variant)s|%(platform)s'" Label="PropertySheets">
-\t\t<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+\t\t<Import Project="$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
\t</ImportGroup>
"""
@@ -1159,7 +1159,7 @@ class _GenerateV10DSP(_DSPGenerator, _GenerateV10User):
name = self.name
confkeys = sorted(self.configs.keys())
- self.file.write('\t<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\n')
+ self.file.write('\t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />\n')
toolset = ''
if 'MSVC_VERSION' in self.env:
@@ -1170,7 +1170,7 @@ class _GenerateV10DSP(_DSPGenerator, _GenerateV10User):
platform = self.configs[kind].platform
self.file.write(V10DSPPropertyGroupCondition % locals())
- self.file.write('\t<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\n')
+ self.file.write('\t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" />\n')
self.file.write('\t<ImportGroup Label="ExtensionSettings">\n')
self.file.write('\t</ImportGroup>\n')
@@ -1233,7 +1233,7 @@ class _GenerateV10DSP(_DSPGenerator, _GenerateV10User):
self.filters_file.write('</Project>')
self.filters_file.close()
- self.file.write('\t<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\n'
+ self.file.write('\t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />\n'
'\t<ImportGroup Label="ExtensionTargets">\n'
'\t</ImportGroup>\n'
'</Project>\n')
diff --git a/src/engine/SCons/Tool/packaging/__init__.py b/src/engine/SCons/Tool/packaging/__init__.py
index 6261f98..174ab8c 100644
--- a/src/engine/SCons/Tool/packaging/__init__.py
+++ b/src/engine/SCons/Tool/packaging/__init__.py
@@ -35,7 +35,7 @@ from SCons.Util import is_List, make_path_relative
from SCons.Warnings import warn, Warning
import os
-import imp
+import importlib
__all__ = [
'src_targz', 'src_tarbz2', 'src_xz', 'src_zip',
@@ -122,12 +122,12 @@ def Package(env, target=None, source=None, **kw):
# load the needed packagers.
def load_packager(type):
try:
- file,path,desc=imp.find_module(type, __path__)
- return imp.load_module(type, file, path, desc)
+ # the specific packager is a relative import
+ return importlib.import_module("." + type, __name__)
except ImportError as e:
raise EnvironmentError("packager %s not available: %s"%(type,str(e)))
- packagers=list(map(load_packager, PACKAGETYPE))
+ packagers = list(map(load_packager, PACKAGETYPE))
# set up targets and the PACKAGEROOT
try:
diff --git a/src/engine/SCons/Tool/suncxx.py b/src/engine/SCons/Tool/suncxx.py
index 29226ea..d526d86 100644
--- a/src/engine/SCons/Tool/suncxx.py
+++ b/src/engine/SCons/Tool/suncxx.py
@@ -56,7 +56,7 @@ def get_package_info(package_name, pkginfo, pkgchk):
except EnvironmentError:
pass
else:
- sadm_re = re.compile('^(\S*/bin/CC)(=\S*)? %s$' % package_name, re.M)
+ sadm_re = re.compile(r'^(\S*/bin/CC)(=\S*)? %s$' % package_name, re.M)
sadm_match = sadm_re.search(sadm_contents)
if sadm_match:
pathname = os.path.dirname(sadm_match.group(1))
@@ -69,7 +69,7 @@ def get_package_info(package_name, pkginfo, pkgchk):
pass
else:
pkginfo_contents = p.communicate()[0]
- version_re = re.compile('^ *VERSION:\s*(.*)$', re.M)
+ version_re = re.compile(r'^ *VERSION:\s*(.*)$', re.M)
version_match = version_re.search(pkginfo_contents)
if version_match:
version = version_match.group(1)
diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py
index 7ab94c5..83b084a 100644
--- a/src/engine/SCons/compat/__init__.py
+++ b/src/engine/SCons/compat/__init__.py
@@ -61,27 +61,18 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
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
diff --git a/src/script/scons-time.py b/src/script/scons-time.py
index ff16ac3..6bcdf16 100644
--- a/src/script/scons-time.py
+++ b/src/script/scons-time.py
@@ -41,6 +41,7 @@ import shutil
import sys
import tempfile
import time
+import subprocess
def HACK_for_exec(cmd, *args):
"""
@@ -443,8 +444,10 @@ class SConsTimer(object):
def log_execute(self, command, log):
command = self.subst(command, self.__dict__)
- with os.popen(command) as p:
- output = p.read()
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
+ output = process.stdout.read()
+ process.stdout.close()
+ process.wait()
if self.verbose:
sys.stdout.write(output)
# TODO: Figure out