From 674ebaca7eef1706549e2d3ddbe563cb2f3864c6 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Tue, 5 Mar 2019 07:30:30 -0700 Subject: [PYPY] [PY 3.8] add context mgr use in scons-time To fix some test problems for pypy, which seem more prone to problems of lost data if files are written and not explicitly closed, add context managers on file opens in scons-time. Also quiets warnings which are emitted by the much noisier Python 3.8. Changes are to the scons-time script and to the framework. After visual inspection of outputs while debugging, switched the framework's created tools in the scons-time area to use os.linesep instead of explicit '\\n' strings, tools should operate in a native way. Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + src/script/scons-time.py | 16 ++++++++++++---- testing/framework/TestSCons_time.py | 29 ++++++++++++++++------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 4d24611..205dcb2 100755 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -34,6 +34,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Add the textfile tool to the default tool list - Fix syntax on is/is not clauses: should not use with a literal - Properly retrieve exit code when catching SystemExit + - scons-time now uses context managers around file opens From Bernhard M. Wiedemann: - Do not store build host+user name if reproducible builds are wanted diff --git a/src/script/scons-time.py b/src/script/scons-time.py index d114f9a..5d0a042 100644 --- a/src/script/scons-time.py +++ b/src/script/scons-time.py @@ -814,7 +814,9 @@ class SConsTimer(object): self.title = a if self.config_file: - exec(open(self.config_file, 'r').read(), self.__dict__) + with open(self.config_file, 'r') as f: + config = f.read() + exec(config, self.__dict__) if self.chdir: os.chdir(self.chdir) @@ -933,7 +935,9 @@ class SConsTimer(object): self.title = a if self.config_file: - HACK_for_exec(open(self.config_file, 'r').read(), self.__dict__) + with open(self.config_file, 'r') as f: + config = f.read() + HACK_for_exec(config, self.__dict__) if self.chdir: os.chdir(self.chdir) @@ -1053,7 +1057,9 @@ class SConsTimer(object): object_name = args.pop(0) if self.config_file: - HACK_for_exec(open(self.config_file, 'r').read(), self.__dict__) + with open(self.config_file, 'r') as f: + config = f.read() + HACK_for_exec(config, self.__dict__) if self.chdir: os.chdir(self.chdir) @@ -1191,7 +1197,9 @@ class SConsTimer(object): sys.exit(1) if self.config_file: - exec(open(self.config_file, 'r').read(), self.__dict__) + with open(self.config_file, 'r') as f: + config = f.read() + exec(config, self.__dict__) if args: self.archive_list = args diff --git a/testing/framework/TestSCons_time.py b/testing/framework/TestSCons_time.py index 8260bef..e37d269 100644 --- a/testing/framework/TestSCons_time.py +++ b/testing/framework/TestSCons_time.py @@ -38,18 +38,18 @@ import os import sys def write_args(fp, args): - fp.write(args[0] + '\\n') + fp.write(args[0] + os.linesep) for arg in args[1:]: - fp.write(' ' + arg + '\\n') + fp.write(' ' + arg + os.linesep) write_args(sys.stdout, sys.argv) for arg in sys.argv[1:]: if arg[:10] == '--profile=': with open(arg[10:], 'w') as profile: - profile.write('--profile\\n') + profile.write('--profile' + os.linesep) write_args(profile, sys.argv) break -sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + '\\n') +sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + os.linesep) with open('SConstruct', 'r') as f: script = f.read() exec(script) @@ -63,8 +63,8 @@ import sys script_dir = 'src/script' if not os.path.exists(script_dir): os.makedirs(script_dir) -open(script_dir + '/scons.py', 'w').write( -r'''%s''') +with open(script_dir + '/scons.py', 'w') as f: + f.write(r'''%s''') """ % scons_py @@ -76,8 +76,8 @@ import sys dir = sys.argv[-1] script_dir = dir + '/src/script' os.makedirs(script_dir) -open(script_dir + '/scons.py', 'w').write( -r'''%s''') +with open(script_dir + '/scons.py', 'w') as f: + f.write(r'''%s''') """ % scons_py @@ -89,8 +89,8 @@ import sys dir = sys.argv[-1] script_dir = dir + '/src/script' os.makedirs(script_dir) -open(script_dir + '/scons.py', 'w').write( -r'''%s''') +with open(script_dir + '/scons.py', 'w') as f: + f.write(r'''%s''') """ % scons_py @@ -297,13 +297,15 @@ class TestSCons_time(TestCommon): tar = tarfile.open(archive, mode[suffix]) for name, content in files: path = os.path.join(dir, name) - open(path, 'wb').write(bytearray(content,'utf-8')) + with open(path, 'wb') as f: + f.write(bytearray(content,'utf-8')) tarinfo = tar.gettarinfo(path, path) tarinfo.uid = 111 tarinfo.gid = 111 tarinfo.uname = 'fake_user' tarinfo.gname = 'fake_group' - tar.addfile(tarinfo, open(path, 'rb')) + with open(path, 'rb') as f: + tar.addfile(tarinfo, f) tar.close() shutil.rmtree(dir) return self.workpath(archive) @@ -322,7 +324,8 @@ class TestSCons_time(TestCommon): zip = zipfile.ZipFile(archive, 'w') for name, content in files: path = os.path.join(dir, name) - open(path, 'w').write(content) + with open(path, 'w') as f: + f.write(content) zip.write(path) zip.close() shutil.rmtree(dir) -- cgit v0.12 From 0868f0e7541e39237ef91a5382945679076c1b5d Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 6 Mar 2019 13:31:57 -0700 Subject: scons-time needed to revert some changes were breaking Windows tests. Signed-off-by: Mats Wichmann --- testing/framework/TestSCons_time.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/framework/TestSCons_time.py b/testing/framework/TestSCons_time.py index e37d269..55248a4 100644 --- a/testing/framework/TestSCons_time.py +++ b/testing/framework/TestSCons_time.py @@ -38,18 +38,18 @@ import os import sys def write_args(fp, args): - fp.write(args[0] + os.linesep) + fp.write(args[0] + '\\n') for arg in args[1:]: - fp.write(' ' + arg + os.linesep) + fp.write(' ' + arg + '\\n') write_args(sys.stdout, sys.argv) for arg in sys.argv[1:]: if arg[:10] == '--profile=': with open(arg[10:], 'w') as profile: - profile.write('--profile' + os.linesep) + profile.write('--profile\\n') write_args(profile, sys.argv) break -sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + os.linesep) +sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + '\\n') with open('SConstruct', 'r') as f: script = f.read() exec(script) -- cgit v0.12