From 8b939d89c0b3483ef1cc3e78eb6f58bd7f041fd6 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 20:43:29 -0800 Subject: More post py27 cleanup. Remove no-op function calls. Fix _exercise() built in test to complete --- src/engine/SCons/dblite.py | 57 +++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/engine/SCons/dblite.py b/src/engine/SCons/dblite.py index 5ac77a5..765516c 100644 --- a/src/engine/SCons/dblite.py +++ b/src/engine/SCons/dblite.py @@ -18,14 +18,6 @@ def corruption_warning(filename): print("Warning: Discarding corrupt database:", filename) -def is_string(s): - return isinstance(s, str) - - -def is_bytes(s): - return isinstance(s, bytes) - - dblite_suffix = '.dblite' # TODO: Does commenting this out break switching from py2/3? @@ -170,10 +162,13 @@ class dblite(object): def __setitem__(self, key, value): self._check_writable() - if not is_string(key): + + if not isinstance(key, str): raise TypeError("key `%s' must be a string but is %s" % (key, type(key))) - if not is_bytes(value): + + if not isinstance(value, bytes): raise TypeError("value `%s' must be a bytes but is %s" % (value, type(value))) + self._dict[key] = value self._needs_sync = 0o001 @@ -203,19 +198,21 @@ def open(file, flag=None, mode=0o666): def _exercise(): db = open("tmp", "n") assert len(db) == 0 - db["foo"] = "bar" - assert db["foo"] == "bar" + db["foo"] = b"bar" + assert db["foo"] == b"bar" db.sync() + db = open("tmp", "c") - assert len(db) == 2, len(db) - assert db["foo"] == "bar" - db["bar"] = "foo" - assert db["bar"] == "foo" + assert len(db) == 1, len(db) + assert db["foo"] == b"bar" + db["bar"] = b"foo" + assert db["bar"] == b"foo" db.sync() + db = open("tmp", "r") - assert len(db) == 4, len(db) - assert db["foo"] == "bar" - assert db["bar"] == "foo" + assert len(db) == 2, len(db) + assert db["foo"] == b"bar" + assert db["bar"] == b"foo" try: db.sync() except IOError as e: @@ -223,26 +220,31 @@ def _exercise(): else: raise RuntimeError("IOError expected.") db = open("tmp", "w") - assert len(db) == 4 - db["ping"] = "pong" + assert len(db) == 2, len(db) + db["ping"] = b"pong" db.sync() + try: db[(1, 2)] = "tuple" except TypeError as e: - assert str(e) == "key `(1, 2)' must be a string but is ", str(e) + assert str(e) == "key `(1, 2)' must be a string but is ", str(e) else: raise RuntimeError("TypeError exception expected") + try: db["list"] = [1, 2] except TypeError as e: - assert str(e) == "value `[1, 2]' must be a string but is ", str(e) + assert str(e) == "value `[1, 2]' must be a bytes but is ", str(e) else: raise RuntimeError("TypeError exception expected") + db = open("tmp", "r") - assert len(db) == 5 + assert len(db) == 3, len(db) + db = open("tmp", "n") - assert len(db) == 0 + assert len(db) == 0, len(db) dblite._open("tmp.dblite", "w") + db = open("tmp", "r") dblite._open("tmp.dblite", "w").write("x") try: @@ -251,10 +253,11 @@ def _exercise(): pass else: raise RuntimeError("pickle exception expected.") + global ignore_corrupt_dbfiles ignore_corrupt_dbfiles = 2 db = open("tmp", "r") - assert len(db) == 0 + assert len(db) == 0, len(db) os.unlink("tmp.dblite") try: db = open("tmp", "w") @@ -263,6 +266,8 @@ def _exercise(): else: raise RuntimeError("IOError expected.") + print("Completed _exercise()") + if __name__ == "__main__": _exercise() -- cgit v0.12 From 987f563b8cd16f146c2ee8b8f1617d8954aab810 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 20:56:18 -0800 Subject: more post py27 cleanup --- src/engine/SCons/Node/FS.py | 21 ++--- src/engine/SCons/Platform/win32.py | 40 --------- src/engine/SCons/SConfTests.py | 12 --- src/engine/SCons/Taskmaster.py | 15 ++-- src/engine/SCons/Tool/__init__.py | 178 +++++++++++++++---------------------- 5 files changed, 84 insertions(+), 182 deletions(-) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index a268020..1a5bd1b 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -42,6 +42,7 @@ import sys import time import codecs from itertools import chain +import importlib.util import SCons.Action import SCons.Debug @@ -1425,22 +1426,10 @@ class FS(LocalFS): This can be useful when we want to determine a toolpath based on a python module name""" dirpath = '' - if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] in (0,1,2,3,4)): - # Python2 Code - import imp - splitname = modulename.split('.') - srchpths = sys.path - for item in splitname: - file, path, desc = imp.find_module(item, srchpths) - if file is not None: - path = os.path.dirname(path) - srchpths = [path] - dirpath = path - else: - # Python3 Code - import importlib.util - modspec = importlib.util.find_spec(modulename) - dirpath = os.path.dirname(modspec.origin) + + # Python3 Code + modspec = importlib.util.find_spec(modulename) + dirpath = os.path.dirname(modspec.origin) return self._lookup(dirpath, None, Dir, True) diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index 3258dfd..afe2df9 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -62,46 +62,6 @@ except AttributeError: else: parallel_msg = None - if sys.version_info.major == 2: - import __builtin__ - - _builtin_file = __builtin__.file - _builtin_open = __builtin__.open - - def _scons_fixup_mode(mode): - """Adjust 'mode' to mark handle as non-inheritable. - - SCons is multithreaded, so allowing handles to be inherited by - children opens us up to races, where (e.g.) processes spawned by - the Taskmaster may inherit and retain references to files opened - by other threads. This may lead to sharing violations and, - ultimately, build failures. - - By including 'N' as part of fopen's 'mode' parameter, all file - handles returned from these functions are atomically marked as - non-inheritable. - """ - if not mode: - # Python's default is 'r'. - # https://docs.python.org/2/library/functions.html#open - mode = 'rN' - elif 'N' not in mode: - mode += 'N' - return mode - - class _scons_file(_builtin_file): - def __init__(self, name, mode=None, *args, **kwargs): - _builtin_file.__init__(self, name, _scons_fixup_mode(mode), - *args, **kwargs) - - def _scons_open(name, mode=None, *args, **kwargs): - return _builtin_open(name, _scons_fixup_mode(mode), - *args, **kwargs) - - __builtin__.file = _scons_file - __builtin__.open = _scons_open - - if False: # Now swap out shutil.filecopy and filecopy2 for win32 api native CopyFile diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index 63ec8f1..e2b9133 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -56,18 +56,6 @@ class SConfTestCase(unittest.TestCase): os.chdir(self.save_cwd) def _resetSConfState(self): - if sys.platform in ['cygwin', 'win32'] and sys.version_info.major == 2: - # On Windows with Python2, SCons.Platform.win32 redefines the - # built-in file() and open() functions to disable handle - # inheritance. Because we are unloading all SCons modules other - # than SCons.Compat, SCons.Platform.win32 will lose the variables - # it needs. As a result, we should reset the file() and open() - # functions to their original built-in versions. - import __builtin__ - import SCons.Platform.win32 - __builtin__.file = SCons.Platform.win32._builtin_file - __builtin__.open = SCons.Platform.win32._builtin_open - # Ok, this is tricky, and i do not know, if everything is sane. # We try to reset scons' state (including all global variables) import SCons.SConsign diff --git a/src/engine/SCons/Taskmaster.py b/src/engine/SCons/Taskmaster.py index 2bbb732..d04b585 100644 --- a/src/engine/SCons/Taskmaster.py +++ b/src/engine/SCons/Taskmaster.py @@ -553,15 +553,12 @@ class Task(object): exc_traceback = None # raise exc_type(exc_value).with_traceback(exc_traceback) - if sys.version_info[0] == 2: - exec("raise exc_type, exc_value, exc_traceback") - else: # sys.version_info[0] == 3: - if isinstance(exc_value, Exception): #hasattr(exc_value, 'with_traceback'): - # If exc_value is an exception, then just reraise - exec("raise exc_value.with_traceback(exc_traceback)") - else: - # else we'll create an exception using the value and raise that - exec("raise exc_type(exc_value).with_traceback(exc_traceback)") + if isinstance(exc_value, Exception): #hasattr(exc_value, 'with_traceback'): + # If exc_value is an exception, then just reraise + raise exc_value.with_traceback(exc_traceback) + else: + # else we'll create an exception using the value and raise that + raise exc_type(exc_value).with_traceback(exc_traceback) # raise e.__class__, e.__class__(e), sys.exc_info()[2] diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 7331a64..4cb77c0 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -38,10 +38,9 @@ tool definition. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import sys -import re import os -import shutil from collections.abc import Callable +import importlib.util import SCons.Builder import SCons.Errors @@ -137,112 +136,81 @@ class Tool(object): sys.path = self.toolpath + sys.path # sys.stderr.write("Tool:%s\nPATH:%s\n"%(self.name,sys.path)) - if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] in (0, 1, 2, 3, 4)): - # Py 2 code - try: - try: - file = None - try: - mod, file = self._load_dotted_module_py2(self.name, self.name, self.toolpath) - return mod - finally: - if file: - file.close() - except ImportError as e: - splitname = self.name.split('.') - if str(e) != "No module named %s" % splitname[0]: - raise SCons.Errors.SConsEnvironmentError(e) - try: - import zipimport - except ImportError: - pass - else: - for aPath in self.toolpath: - try: - importer = zipimport.zipimporter(aPath) - return importer.load_module(self.name) - except ImportError as e: - pass - finally: - sys.path = oldpythonpath - elif sys.version_info[1] > 4: - # From: http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path/67692#67692 - # import importlib.util - # spec = importlib.util.spec_from_file_location("module.name", "/path/to/file.py") - # foo = importlib.util.module_from_spec(spec) - # spec.loader.exec_module(foo) - # foo.MyClass() - # Py 3 code - - # import pdb; pdb.set_trace() - import importlib.util - - # sys.stderr.write("toolpath:%s\n" % self.toolpath) - # sys.stderr.write("SCONS.TOOL path:%s\n" % sys.modules['SCons.Tool'].__path__) - debug = False - spec = None - found_name = self.name - add_to_scons_tools_namespace = False - for path in self.toolpath: - sepname = self.name.replace('.', os.path.sep) - file_path = os.path.join(path, "%s.py" % sepname) - file_package = os.path.join(path, sepname) - - if debug: sys.stderr.write("Trying:%s %s\n" % (file_path, file_package)) - - if os.path.isfile(file_path): - spec = importlib.util.spec_from_file_location(self.name, file_path) - if debug: print("file_Path:%s FOUND" % file_path) - break - elif os.path.isdir(file_package): - file_package = os.path.join(file_package, '__init__.py') - spec = importlib.util.spec_from_file_location(self.name, file_package) - if debug: print("PACKAGE:%s Found" % file_package) - break - - else: - continue - - if spec is None: - if debug: sys.stderr.write("NO SPEC :%s\n" % self.name) - spec = importlib.util.find_spec("." + self.name, package='SCons.Tool') - if spec: - found_name = 'SCons.Tool.' + self.name - add_to_scons_tools_namespace = True - if debug: sys.stderr.write("Spec Found? .%s :%s\n" % (self.name, spec)) - - if spec is None: - error_string = "No module named %s" % self.name - raise SCons.Errors.SConsEnvironmentError(error_string) - - module = importlib.util.module_from_spec(spec) - if module is None: - if debug: print("MODULE IS NONE:%s" % self.name) - error_string = "No module named %s" % self.name - raise SCons.Errors.SConsEnvironmentError(error_string) - - # Don't reload a tool we already loaded. - sys_modules_value = sys.modules.get(found_name, False) - - found_module = None - if sys_modules_value and sys_modules_value.__file__ == spec.origin: - found_module = sys.modules[found_name] + # From: http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path/67692#67692 + # import importlib.util + # spec = importlib.util.spec_from_file_location("module.name", "/path/to/file.py") + # foo = importlib.util.module_from_spec(spec) + # spec.loader.exec_module(foo) + # foo.MyClass() + # Py 3 code + + + # sys.stderr.write("toolpath:%s\n" % self.toolpath) + # sys.stderr.write("SCONS.TOOL path:%s\n" % sys.modules['SCons.Tool'].__path__) + debug = False + spec = None + found_name = self.name + add_to_scons_tools_namespace = False + for path in self.toolpath: + sepname = self.name.replace('.', os.path.sep) + file_path = os.path.join(path, "%s.py" % sepname) + file_package = os.path.join(path, sepname) + + if debug: sys.stderr.write("Trying:%s %s\n" % (file_path, file_package)) + + if os.path.isfile(file_path): + spec = importlib.util.spec_from_file_location(self.name, file_path) + if debug: print("file_Path:%s FOUND" % file_path) + break + elif os.path.isdir(file_package): + file_package = os.path.join(file_package, '__init__.py') + spec = importlib.util.spec_from_file_location(self.name, file_package) + if debug: print("PACKAGE:%s Found" % file_package) + break + else: - # Not sure what to do in the case that there already - # exists sys.modules[self.name] but the source file is - # different.. ? - module = spec.loader.load_module(spec.name) - - sys.modules[found_name] = module - if add_to_scons_tools_namespace: - # If we found it in SCons.Tool, then add it to the module - setattr(SCons.Tool, self.name, module) + continue + + if spec is None: + if debug: sys.stderr.write("NO SPEC :%s\n" % self.name) + spec = importlib.util.find_spec("." + self.name, package='SCons.Tool') + if spec: + found_name = 'SCons.Tool.' + self.name + add_to_scons_tools_namespace = True + if debug: sys.stderr.write("Spec Found? .%s :%s\n" % (self.name, spec)) + + if spec is None: + error_string = "No module named %s" % self.name + raise SCons.Errors.SConsEnvironmentError(error_string) + + module = importlib.util.module_from_spec(spec) + if module is None: + if debug: print("MODULE IS NONE:%s" % self.name) + error_string = "No module named %s" % self.name + raise SCons.Errors.SConsEnvironmentError(error_string) + + # Don't reload a tool we already loaded. + sys_modules_value = sys.modules.get(found_name, False) + + found_module = None + if sys_modules_value and sys_modules_value.__file__ == spec.origin: + found_module = sys.modules[found_name] + else: + # Not sure what to do in the case that there already + # exists sys.modules[self.name] but the source file is + # different.. ? + module = spec.loader.load_module(spec.name) + + sys.modules[found_name] = module + if add_to_scons_tools_namespace: + # If we found it in SCons.Tool, then add it to the module + setattr(SCons.Tool, self.name, module) - found_module = module + found_module = module - if found_module is not None: - sys.path = oldpythonpath - return found_module + if found_module is not None: + sys.path = oldpythonpath + return found_module sys.path = oldpythonpath -- cgit v0.12 From b3589ce0a14ca9cc3ac67ee5d1a2d6ff92d4c6b0 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 18 Feb 2020 10:32:23 -0800 Subject: Remove u' u" from strings. no longer needed --- src/engine/SCons/Action.py | 2 +- src/engine/SCons/Environment.py | 2 +- src/engine/SCons/EnvironmentTests.py | 5 ----- src/engine/SCons/JobTests.py | 4 ++-- src/engine/SCons/Node/FS.py | 2 +- src/engine/SCons/Node/FSTests.py | 22 +++++----------------- src/engine/SCons/Scanner/ScannerTests.py | 2 +- src/engine/SCons/Taskmaster.py | 24 ++++++++++++------------ src/engine/SCons/UtilTests.py | 2 +- 9 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index b22de60..0b7282c 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -669,7 +669,7 @@ class _ActionAction(ActionBase): source = executor.get_all_sources() t = ' and '.join(map(str, target)) l = '\n '.join(self.presub_lines(env)) - out = u"Building %s with action:\n %s\n" % (t, l) + out = "Building %s with action:\n %s\n" % (t, l) sys.stdout.write(out) cmd = None if show and self.strfunction: diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 5e76e35..00379e1 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -584,7 +584,7 @@ class SubstitutionEnvironment(object): out,err = p.communicate() status = p.wait() if err: - sys.stderr.write(u"" + err) + sys.stderr.write("" + err) if status: raise OSError("'%s' exited %d" % (command, status)) return out diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 3db6499..a9ec674 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -262,11 +262,6 @@ class SubstitutionTestCase(unittest.TestCase): assert isinstance(nodes[0], X) assert nodes[0].name == "Util.py UtilTests.py", nodes[0].name - nodes = env.arg2nodes(u"Util.py UtilTests.py", Factory) - assert len(nodes) == 1, nodes - assert isinstance(nodes[0], X) - assert nodes[0].name == u"Util.py UtilTests.py", nodes[0].name - nodes = env.arg2nodes(["Util.py", "UtilTests.py"], Factory) assert len(nodes) == 2, nodes assert isinstance(nodes[0], X) diff --git a/src/engine/SCons/JobTests.py b/src/engine/SCons/JobTests.py index 2e3af4f..9c9bb41 100644 --- a/src/engine/SCons/JobTests.py +++ b/src/engine/SCons/JobTests.py @@ -42,8 +42,8 @@ def get_cpu_nums(): ncpus = os.sysconf( "SC_NPROCESSORS_ONLN" ) if isinstance(ncpus, int) and ncpus > 0: return ncpus - else: # OSX: - return int( os.popen2( "sysctl -n hw.ncpu")[1].read() ) + else: # OSX: + return int(os.popen2("sysctl -n hw.ncpu")[1].read() ) # Windows: if "NUMBER_OF_PROCESSORS" in os.environ: ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 1a5bd1b..bb965db 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -3727,7 +3727,7 @@ class FileFinder(object): if verbose and not callable(verbose): if not SCons.Util.is_String(verbose): verbose = "find_file" - _verbose = u' %s: ' % verbose + _verbose = ' %s: ' % verbose verbose = lambda s: sys.stdout.write(_verbose + s) filedir, filename = os.path.split(filename) diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 26c71b0..3f2cb0e 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1342,11 +1342,10 @@ class FSTestCase(_tempdirTestCase): assert f1.get_contents() == bytearray("Foo\x1aBar", 'utf-8'), f1.get_contents() # This tests to make sure we can decode UTF-8 text files. - test_string = u"Foo\x1aBar" + test_string = "Foo\x1aBar" test.write("utf8_file", test_string.encode('utf-8')) f1 = fs.File(test.workpath("utf8_file")) - assert eval('f1.get_text_contents() == u"Foo\x1aBar"'), \ - f1.get_text_contents() + f1.get_text_contents() == "Foo\x1aBar", f1.get_text_contents() # Check for string which doesn't have BOM and isn't valid # ASCII @@ -1444,7 +1443,7 @@ class FSTestCase(_tempdirTestCase): c = e.get_text_contents() try: - eval('assert c == u"", c') + eval('assert c == "", c') except SyntaxError: assert c == "" @@ -1455,10 +1454,7 @@ class FSTestCase(_tempdirTestCase): assert e.__class__ == SCons.Node.FS.Entry, e.__class__ assert c == "", c c = e.get_text_contents() - try: - eval('assert c == u"", c') - except SyntaxError: - assert c == "", c + assert c == "", c test.write("tstamp", "tstamp\n") try: @@ -3311,15 +3307,7 @@ class RepositoryTestCase(_tempdirTestCase): # Use a test string that has a file terminator in it to make # sure we read the entire file, regardless of its contents. - try: - eval('test_string = u"Con\x1aTents\n"') - except SyntaxError: - import collections - class FakeUnicodeString(collections.UserString): - def encode(self, encoding): - return str(self) - - test_string = FakeUnicodeString("Con\x1aTents\n") + test_string = "Con\x1aTents\n" # Test with ASCII. test.write(["rep3", "contents"], test_string.encode('ascii')) diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index abe4042..6206af9 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -599,7 +599,7 @@ class ClassicCPPTestCase(unittest.TestCase): assert n == 'path/bbb', n assert i == 'bbb', i - n, i = s.find_include(('<', u'ccc'), 'foo', ('path',)) + n, i = s.find_include(('<', 'ccc'), 'foo', ('path',)) assert n == 'path/ccc', n assert i == 'ccc', i diff --git a/src/engine/SCons/Taskmaster.py b/src/engine/SCons/Taskmaster.py index d04b585..6ca0e03 100644 --- a/src/engine/SCons/Taskmaster.py +++ b/src/engine/SCons/Taskmaster.py @@ -169,7 +169,7 @@ class Task(object): """ global print_prepare T = self.tm.trace - if T: T.write(self.trace_message(u'Task.prepare()', self.node)) + if T: T.write(self.trace_message('Task.prepare()', self.node)) # Now that it's the appropriate time, give the TaskMaster a # chance to raise any exceptions it encountered while preparing @@ -231,7 +231,7 @@ class Task(object): prepare(), executed() or failed(). """ T = self.tm.trace - if T: T.write(self.trace_message(u'Task.execute()', self.node)) + if T: T.write(self.trace_message('Task.execute()', self.node)) try: cached_targets = [] @@ -397,7 +397,7 @@ class Task(object): """ global print_prepare T = self.tm.trace - if T: T.write(self.trace_message(u'Task.make_ready_current()', + if T: T.write(self.trace_message('Task.make_ready_current()', self.node)) self.out_of_date = [] @@ -445,7 +445,7 @@ class Task(object): that can be put back on the candidates list. """ T = self.tm.trace - if T: T.write(self.trace_message(u'Task.postprocess()', self.node)) + if T: T.write(self.trace_message('Task.postprocess()', self.node)) # We may have built multiple targets, some of which may have # common parents waiting for this build. Count up how many @@ -462,7 +462,7 @@ class Task(object): # A node can only be in the pending_children set if it has # some waiting_parents. if t.waiting_parents: - if T: T.write(self.trace_message(u'Task.postprocess()', + if T: T.write(self.trace_message('Task.postprocess()', t, 'removing')) pending_children.discard(t) @@ -491,7 +491,7 @@ class Task(object): for p, subtract in parents.items(): p.ref_count = p.ref_count - subtract - if T: T.write(self.trace_message(u'Task.postprocess()', + if T: T.write(self.trace_message('Task.postprocess()', p, 'adjusted parent ref count')) if p.ref_count == 0: @@ -792,7 +792,7 @@ class Taskmaster(object): while True: node = self.next_candidate() if node is None: - if T: T.write(self.trace_message('No candidate anymore.') + u'\n') + if T: T.write(self.trace_message('No candidate anymore.') + '\n') return None node = node.disambiguate() @@ -815,7 +815,7 @@ class Taskmaster(object): else: S = None - if T: T.write(self.trace_message(u' Considering node %s and its children:' % self.trace_node(node))) + if T: T.write(self.trace_message(' Considering node %s and its children:' % self.trace_node(node))) if state == NODE_NO_STATE: # Mark this node as being on the execution stack: @@ -823,7 +823,7 @@ class Taskmaster(object): elif state > NODE_PENDING: # Skip this node if it has already been evaluated: if S: S.already_handled = S.already_handled + 1 - if T: T.write(self.trace_message(u' already handled (executed)')) + if T: T.write(self.trace_message(' already handled (executed)')) continue executor = node.get_executor() @@ -854,7 +854,7 @@ class Taskmaster(object): for child in chain(executor.get_all_prerequisites(), children): childstate = child.get_state() - if T: T.write(self.trace_message(u' ' + self.trace_node(child))) + if T: T.write(self.trace_message(' ' + self.trace_node(child))) if childstate == NODE_NO_STATE: children_not_visited.append(child) @@ -915,7 +915,7 @@ class Taskmaster(object): # count so we can be put back on the list for # re-evaluation when they've all finished. node.ref_count = node.ref_count + child.add_to_waiting_parents(node) - if T: T.write(self.trace_message(u' adjusted ref count: %s, child %s' % + if T: T.write(self.trace_message(' adjusted ref count: %s, child %s' % (self.trace_node(node), repr(str(child))))) if T: @@ -941,7 +941,7 @@ class Taskmaster(object): # The default when we've gotten through all of the checks above: # this node is ready to be built. if S: S.build = S.build + 1 - if T: T.write(self.trace_message(u'Evaluating %s\n' % + if T: T.write(self.trace_message('Evaluating %s\n' % self.trace_node(node))) # For debugging only: diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 4968a77..d96b63f 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -740,7 +740,7 @@ class UtilTestCase(unittest.TestCase): def test_LogicalLines(self): """Test the LogicalLines class""" - content = u""" + content = """ foo \\ bar \\ baz -- cgit v0.12 From e66f178d42d9d6f323be8884c8d1e80e3936d0a3 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 18 Feb 2020 10:36:54 -0800 Subject: more unicode cleanup post py27 --- testing/framework/TestCmd.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 6beed24..f29449f 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -358,14 +358,8 @@ def to_str(s): return str(s, 'utf-8') -try: - eval('unicode') -except NameError: - def is_String(e): - return isinstance(e, (str, UserString)) -else: - def is_String(e): - return isinstance(e, (str, unicode, UserString)) +def is_String(e): + return isinstance(e, (str, UserString)) testprefix = 'testcmd.' if os.name in ('posix', 'nt'): @@ -1094,7 +1088,7 @@ class TestCmd(object): condition = self.condition if self._preserve[condition]: for dir in self._dirlist: - print(u"Preserved directory " + dir) + print("Preserved directory " + dir) else: list = self._dirlist[:] list.reverse() @@ -1536,7 +1530,6 @@ class TestCmd(object): return stream - def finish(self, popen=None, **kw): """ Finishes and waits for the process being run under control of -- cgit v0.12 From 73a6eb497276e8ed8b8c81204d8b25a728ac84e9 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 18 Feb 2020 11:33:37 -0800 Subject: Update TestCommonTests.py to work with py35+ changes --- testing/framework/TestCommonTests.py | 48 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/testing/framework/TestCommonTests.py b/testing/framework/TestCommonTests.py index c54f33f..6377737 100644 --- a/testing/framework/TestCommonTests.py +++ b/testing/framework/TestCommonTests.py @@ -45,10 +45,9 @@ def lstrip(s): lines = [ l[spaces:] for l in lines ] return '\n'.join(lines) -if sys.version[:3] == '1.5': - expected_newline = '\\012' -else: - expected_newline = '\\n' + +expected_newline = '\\n' + def assert_display(expect, result, error=None): try: @@ -57,9 +56,9 @@ def assert_display(expect, result, error=None): pass result = [ '\n', - ('*'*80) + '\n', + 'EXPECTED'+('*'*80) + '\n', expect, - ('*'*80) + '\n', + 'GOT'+('*'*80) + '\n', result, ('*'*80) + '\n', ] @@ -353,14 +352,13 @@ class must_contain_TestCase(TestCommonTestCase): expect = lstrip("""\ File `file1' does not contain required string. Required string ================================================================ - 1 c + b'1 c' file1 contents ================================================================= - file1 does not match - + b'file1 does not match\\n' """) run_env.run(program=sys.executable, stdin=script) stdout = run_env.stdout() - assert stdout == expect, repr(stdout) + assert stdout == expect, "got:\n%s\nexpected:\n%s"%(stdout, expect) stderr = run_env.stderr() assert stderr.find("FAILED") != -1, stderr @@ -1294,7 +1292,7 @@ class must_not_contain_TestCase(TestCommonTestCase): from TestCommon import TestCommon tc = TestCommon(workdir='') tc.write('file1', "file1 contents\\n") - tc.must_not_contain('file1', "1 does not contain c") + tc.must_not_contain('file1', b"1 does not contain c") tc.pass_test() """) run_env.run(program=sys.executable, stdin=script) @@ -1327,20 +1325,20 @@ class must_not_contain_TestCase(TestCommonTestCase): from TestCommon import TestCommon tc = TestCommon(workdir='') tc.write('file1', "file1 does contain contents\\n") - tc.must_not_contain('file1', "1 does contain c") + tc.must_not_contain('file1', b"1 does contain c") tc.run() """) expect = lstrip("""\ File `file1' contains banned string. Banned string ================================================================== - 1 does contain c + b'1 does contain c' file1 contents ================================================================= - file1 does contain contents - + b'file1 does contain contents\\n' """) run_env.run(program=sys.executable, stdin=script) stdout = run_env.stdout() - assert stdout == expect, repr(stdout) + assert stdout == expect, "\ngot:\n%s\nexpected:\n%s" % (stdout, expect) + stderr = run_env.stderr() assert stderr.find("FAILED") != -1, stderr @@ -1352,20 +1350,20 @@ class must_not_contain_TestCase(TestCommonTestCase): from TestCommon import TestCommon tc = TestCommon(workdir='') tc.write('file1', "file1 does contain contents\\n") - tc.must_not_contain('file1', "file1 does") + tc.must_not_contain('file1', b"file1 does") tc.run() """) expect = lstrip("""\ File `file1' contains banned string. Banned string ================================================================== - file1 does + b'file1 does' file1 contents ================================================================= - file1 does contain contents - + b'file1 does contain contents\\n' """) run_env.run(program=sys.executable, stdin=script) stdout = run_env.stdout() - assert stdout == expect, repr(stdout) + assert stdout == expect, "\ngot:\n%s\nexpected:\n%s" % (stdout, expect) + stderr = run_env.stderr() assert stderr.find("FAILED") != -1, stderr @@ -1379,7 +1377,7 @@ class must_not_contain_TestCase(TestCommonTestCase): tc.write('file1', "file1 contents\\n", mode='w') tc.must_not_contain('file1', "1 does not contain c", mode='r') tc.write('file2', "file2 contents\\n", mode='wb') - tc.must_not_contain('file2', "2 does not contain c", mode='rb') + tc.must_not_contain('file2', b"2 does not contain c", mode='rb') tc.pass_test() """) run_env.run(program=sys.executable, stdin=script) @@ -1891,6 +1889,7 @@ class run_TestCase(TestCommonTestCase): expect_stdout = lstrip("""\ STDOUT ========================================================================= + None STDERR ========================================================================= """) @@ -1904,6 +1903,9 @@ class run_TestCase(TestCommonTestCase): .* File "[^"]+TestCommon.py", line \\d+, in start raise e + File "[^"]+TestCommon.py", line \\d+, in start + return TestCmd.start\\(self, program, interpreter, arguments, + File "", line \\d+, in raise_exception TypeError: forced TypeError """ % re.escape(repr(sys.executable))) expect_stderr = re.compile(expect_stderr, re.M) @@ -2172,7 +2174,7 @@ class run_TestCase(TestCommonTestCase): tc.run() """) - self.SIGTERM = signal.SIGTERM + self.SIGTERM = int(signal.SIGTERM) # Script returns the signal value as a negative number. expect_stdout = lstrip("""\ -- cgit v0.12 From 7528b23f63755ecb2bc60e25aeef0188179b7681 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 18 Feb 2020 11:42:57 -0800 Subject: Fix runtest.py to only run *Tests.py files under testing as well as under src (unittests) --- runtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtest.py b/runtest.py index 554b4f6..fdbbe22 100755 --- a/runtest.py +++ b/runtest.py @@ -662,7 +662,7 @@ else: # sys.stderr.write("to:%s\n"%tp) for path in glob.glob(tp): if os.path.isdir(path): - if path.startswith('src'): + if path.startswith('src') or path.startswith('testing'): for p in find_Tests_py(path): unittests.append(p) elif path.startswith('test'): -- cgit v0.12 From ce3f96839ad51b98d73db74b4335c903e3ceef44 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 18 Feb 2020 21:33:51 -0500 Subject: post py27 --- bin/calibrate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/calibrate.py b/bin/calibrate.py index be06a54..d18cfcd 100644 --- a/bin/calibrate.py +++ b/bin/calibrate.py @@ -20,8 +20,6 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -from __future__ import division, print_function - import optparse import os import re @@ -31,6 +29,7 @@ import sys variable_re = re.compile(r'^VARIABLE: (.*)$', re.M) elapsed_re = re.compile(r'^ELAPSED: (.*)$', re.M) + def main(argv=None): if argv is None: argv = sys.argv @@ -84,5 +83,6 @@ def main(argv=None): return 0 + if __name__ == "__main__": sys.exit(main()) -- cgit v0.12