From ae0891eece6e36b9e261de807979fd4d35dcc4e2 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 10:28:35 -0800 Subject: remove remaining from __future__ imports --- src/engine/SCons/Defaults.py | 2 -- src/engine/SCons/TaskmasterTests.py | 2 -- src/engine/SCons/Tool/cyglink.py | 2 -- src/engine/SCons/Tool/f08.py | 2 -- src/engine/SCons/cppTests.py | 3 --- 5 files changed, 11 deletions(-) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index a69d8b0..2bac41e 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -31,8 +31,6 @@ from distutils.msvccompiler. # 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 - __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" diff --git a/src/engine/SCons/TaskmasterTests.py b/src/engine/SCons/TaskmasterTests.py index 1a47230..58a31aa 100644 --- a/src/engine/SCons/TaskmasterTests.py +++ b/src/engine/SCons/TaskmasterTests.py @@ -20,8 +20,6 @@ # 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 - __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.compat diff --git a/src/engine/SCons/Tool/cyglink.py b/src/engine/SCons/Tool/cyglink.py index f19614c..fbb6d24 100644 --- a/src/engine/SCons/Tool/cyglink.py +++ b/src/engine/SCons/Tool/cyglink.py @@ -8,8 +8,6 @@ selection method. """ -from __future__ import absolute_import - import re import os diff --git a/src/engine/SCons/Tool/f08.py b/src/engine/SCons/Tool/f08.py index 7fa5872..64bac8e 100644 --- a/src/engine/SCons/Tool/f08.py +++ b/src/engine/SCons/Tool/f08.py @@ -8,8 +8,6 @@ selection method. """ -from __future__ import absolute_import - # # __COPYRIGHT__ # diff --git a/src/engine/SCons/cppTests.py b/src/engine/SCons/cppTests.py index eff7715..eb9189d 100644 --- a/src/engine/SCons/cppTests.py +++ b/src/engine/SCons/cppTests.py @@ -20,9 +20,6 @@ # 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 absolute_import - __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import atexit -- cgit v0.12 From 0a6189cb492728a839d753d1a96e96d8a6cabcf9 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 12:32:29 -0800 Subject: Clean up collections to switch to collections.abc where possible --- src/engine/SCons/ActionTests.py | 2 -- src/engine/SCons/Builder.py | 8 ++++---- src/engine/SCons/BuilderTests.py | 4 ++-- src/engine/SCons/DefaultsTests.py | 2 -- src/engine/SCons/Tool/MSCommon/vc.py | 19 ------------------- src/engine/SCons/Tool/__init__.py | 7 +------ src/engine/SCons/Util.py | 7 ++----- 7 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 3303750..c61a4c7 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -37,10 +37,8 @@ class GlobalActFunc(object): pass -import collections import io import os -import re import sys import types import unittest diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 13949e5..3f0be63 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -100,7 +100,7 @@ There are the following methods for internal use within this module: __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import collections +from collections import UserDict, UserList import SCons.Action import SCons.Debug @@ -197,7 +197,7 @@ class DictEmitter(SCons.Util.Selector): target, source = emitter(target, source, env) return (target, source) -class ListEmitter(collections.UserList): +class ListEmitter(UserList): """A callable list of emitters that calls each in sequence, returning the result. """ @@ -215,7 +215,7 @@ misleading_keywords = { 'sources' : 'source', } -class OverrideWarner(collections.UserDict): +class OverrideWarner(UserDict): """A class for warning about keyword arguments that we use as overrides in a Builder call. @@ -224,7 +224,7 @@ class OverrideWarner(collections.UserDict): warnings once, no matter how many Builders are invoked. """ def __init__(self, dict): - collections.UserDict.__init__(self, dict) + UserDict.__init__(self, dict) if SCons.Debug.track_instances: logInstanceCreation(self, 'Builder.OverrideWarner') self.already_warned = None def warn(self): diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index acdc277..2f72832 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -31,7 +31,7 @@ import SCons.compat def Func(): pass -import collections +from collections import UserList import io import os.path import re @@ -254,7 +254,7 @@ class BuilderTestCase(unittest.TestCase): assert not hasattr(n2, 'env') l = [1] - ul = collections.UserList([2]) + ul = UserList([2]) try: l.extend(ul) except TypeError: diff --git a/src/engine/SCons/DefaultsTests.py b/src/engine/SCons/DefaultsTests.py index 2cbad70..34941bc 100644 --- a/src/engine/SCons/DefaultsTests.py +++ b/src/engine/SCons/DefaultsTests.py @@ -29,8 +29,6 @@ import os import sys import unittest -from collections import UserDict - import TestCmd import SCons.Errors diff --git a/src/engine/SCons/Tool/MSCommon/vc.py b/src/engine/SCons/Tool/MSCommon/vc.py index ed713d0..82fb6b9 100644 --- a/src/engine/SCons/Tool/MSCommon/vc.py +++ b/src/engine/SCons/Tool/MSCommon/vc.py @@ -46,9 +46,6 @@ import platform import sys from string import digits as string_digits from subprocess import PIPE -#TODO: Python 2 cleanup -if sys.version_info[0] == 2: - import collections import SCons.Warnings from SCons.Tool import find_program_path @@ -697,22 +694,6 @@ def script_env(script, args=None): script_env_cache[cache_key] = cache_data # once we updated cache, give a chance to write out if user wanted common.write_script_env_cache(script_env_cache) - else: - #TODO: Python 2 cleanup - # If we "hit" data from the json file, we have a Py2 problem: - # keys & values will be unicode. don't detect, just convert. - if sys.version_info[0] == 2: - def convert(data): - if isinstance(data, basestring): - return str(data) - elif isinstance(data, collections.Mapping): - return dict(map(convert, data.iteritems())) - elif isinstance(data, collections.Iterable): - return type(data)(map(convert, data)) - else: - return data - - cache_data = convert(cache_data) return cache_data diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 76a0913..7331a64 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -41,6 +41,7 @@ import sys import re import os import shutil +from collections.abc import Callable import SCons.Builder import SCons.Errors @@ -51,12 +52,6 @@ import SCons.Scanner.D import SCons.Scanner.LaTeX import SCons.Scanner.Prog import SCons.Scanner.SWIG -try: - # Python 3 - from collections.abc import Callable -except ImportError: - # Python 2.7 - from collections import Callable DefaultToolpath = [] diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 130cc5e..d1baab2 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -34,15 +34,12 @@ import types import codecs import pprint import hashlib +from collections import UserDict, UserList, UserString, OrderedDict +from collections.abc import Iterable, MappingView PY3 = sys.version_info[0] == 3 PYPY = hasattr(sys, 'pypy_translation_info') - -from collections import UserDict, UserList, UserString -from collections.abc import Iterable, MappingView -from collections import OrderedDict - # Don't "from types import ..." these because we need to get at the # types module later to look for UnicodeType. -- cgit v0.12 From 83690c61e673b91b3e35cffdbc0a010296509e05 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 12:45:45 -0800 Subject: Fix some py3.8 warnings in doc SConscript --- doc/SConscript | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/SConscript b/doc/SConscript index ff29a70..e43a27b 100644 --- a/doc/SConscript +++ b/doc/SConscript @@ -90,7 +90,8 @@ def writeVersionXml(verfile, date, ver, rev): os.makedirs(dir) except OSError: pass # okay if the directory already exists - open(verfile, "w").write(""" @@ -105,7 +106,7 @@ man_page_list = ['scons.1','scons-time.1','sconsign.1'] # Template for the MAN page texts when we can't properly # create them because the skip_doc flag is set (required # modules/tools aren't installed in the current system) -man_replace_tpl = """.TH "%(uctitle)s" "1" "%(today)s" "SCons %(version)s" "SCons %(version)s" +man_replace_tpl = r""".TH "%(uctitle)s" "1" "%(today)s" "SCons %(version)s" "SCons %(version)s" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .nh -- cgit v0.12 From 7f77bd5474b7c154d029431ed1bb38c813f6c9fb Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 15:34:03 -0800 Subject: Fix sider issue. Simplify code by removing py27 v py35+ --- src/engine/SCons/Util.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index d1baab2..fa6bc06 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -35,7 +35,7 @@ import codecs import pprint import hashlib from collections import UserDict, UserList, UserString, OrderedDict -from collections.abc import Iterable, MappingView +from collections.abc import MappingView PY3 = sys.version_info[0] == 3 PYPY = hasattr(sys, 'pypy_translation_info') @@ -356,27 +356,18 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): DictTypes = (dict, UserDict) ListTypes = (list, UserList) -try: - # Handle getting dictionary views. - SequenceTypes = (list, tuple, UserList, MappingView) -except NameError: - SequenceTypes = (list, tuple, UserList) +# Handle getting dictionary views. +SequenceTypes = (list, tuple, UserList, MappingView) # Note that profiling data shows a speed-up when comparing # explicitly with str and unicode instead of simply comparing # with basestring. (at least on Python 2.5.1) -try: - StringTypes = (str, unicode, UserString) -except NameError: - StringTypes = (str, UserString) +StringTypes = (str, UserString) # Empirically, it is faster to check explicitly for str and # unicode than for basestring. -try: - BaseStringTypes = (str, unicode) -except NameError: - BaseStringTypes = str +BaseStringTypes = str def is_Dict(obj, isinstance=isinstance, DictTypes=DictTypes): return isinstance(obj, DictTypes) -- cgit v0.12 From 2298a1eeb3299f852af45e31c1829b9b3a35f4f1 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 15:55:10 -0800 Subject: remove PY3 variable from SCons.Util No longer needed --- src/engine/SCons/Util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index fa6bc06..0f2a27a 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -37,7 +37,6 @@ import hashlib from collections import UserDict, UserList, UserString, OrderedDict from collections.abc import MappingView -PY3 = sys.version_info[0] == 3 PYPY = hasattr(sys, 'pypy_translation_info') # Don't "from types import ..." these because we need to get at the -- cgit v0.12 From a70cd70c45384f4482b90b950e2ad49e6e50a7b7 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:22:02 -0800 Subject: replace dictionary initializations with simpler logic --- src/engine/SCons/Node/FS.py | 12 +++--------- src/engine/SCons/Node/FSTests.py | 5 +---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 423ba76..a268020 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1547,9 +1547,7 @@ class Dir(Base): self.repositories = [] self.srcdir = None - self.entries = {} - self.entries['.'] = self - self.entries['..'] = self.dir + self.entries = {'.': self, '..': self.dir} self.cwd = self self.searched = 0 self._sconsign = None @@ -2304,10 +2302,8 @@ class RootDir(Dir): self._morph() self.duplicate = 0 - self._lookupDict = {} + self._lookupDict = {'': self, '/': self} - self._lookupDict[''] = self - self._lookupDict['/'] = self self.root = self # The // entry is necessary because os.path.normpath() # preserves double slashes at the beginning of a path on Posix @@ -2327,9 +2323,7 @@ class RootDir(Dir): self.repositories = [] self.srcdir = None - self.entries = {} - self.entries['.'] = self - self.entries['..'] = self.dir + self.entries = {'.': self, '..': self.dir} self.cwd = self self.searched = 0 self._sconsign = None diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 41d9381..26c71b0 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -463,10 +463,7 @@ class VariantDirTestCase(unittest.TestCase): def __init__(self, duplicate, link, symlink, copy): self.duplicate = duplicate - self.have = {} - self.have['hard'] = link - self.have['soft'] = symlink - self.have['copy'] = copy + self.have = {'hard': link, 'soft': symlink, 'copy': copy} self.links_to_be_called = [] for link in self.duplicate.split('-'): -- cgit v0.12 From b22e98ed4f611eabc05aec9aa1c991f0f918967a Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:26:53 -0800 Subject: more code cleanup found by pycharm --- .../SCons/Tool/docbook/docbook-xsl-1.76.1/extensions/docbook.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Tool/docbook/docbook-xsl-1.76.1/extensions/docbook.py b/src/engine/SCons/Tool/docbook/docbook-xsl-1.76.1/extensions/docbook.py index 7e6a81a..3d53bf7 100644 --- a/src/engine/SCons/Tool/docbook/docbook-xsl-1.76.1/extensions/docbook.py +++ b/src/engine/SCons/Tool/docbook/docbook-xsl-1.76.1/extensions/docbook.py @@ -67,9 +67,9 @@ def adjustColumnWidths(ctx, nodeset): relPart = 0.0 absPart = 0.0 - starPos = string.find(width, "*") + starPos = width.find("*") if starPos >= 0: - relPart, absPart = string.split(width, "*", 2) + relPart, absPart = width.split("*", 2) relPart = float(relPart) relTotal = relTotal + float(relPart) else: @@ -111,7 +111,7 @@ def adjustColumnWidths(ctx, nodeset): widths = correctRoundingError(widths) else: pixelWidth = nominalWidth - if string.find(tableWidth, "%") < 0: + if '%' not in tableWidth: pixelWidth = convertLength(tableWidth) if pixelWidth <= absTotal: @@ -125,7 +125,7 @@ def adjustColumnWidths(ctx, nodeset): relParts[count] = rel + absParts[count] absTotal = absTotal + rel + absParts[count] - if string.find(tableWidth, "%") < 0: + if '%' not in tableWidth: for count in range(len(relParts)): if foStylesheet: pixels = relParts[count] -- cgit v0.12 From 155c43a058bcd6fa1bccd0ed89fb778eaa598958 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:27:33 -0800 Subject: more code cleanup found by pycharm --- bin/import-test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/import-test.py b/bin/import-test.py index 65b6e79..6a71a37 100644 --- a/bin/import-test.py +++ b/bin/import-test.py @@ -82,7 +82,7 @@ def print_files(dir): for dirpath, dirnames, filenames in os.walk(directory): dir = lookup(dirpath) - for f in fnames: + for f in filenames: dir.entries[f] = None subdir_list = [] -- cgit v0.12 From 5b2f62cb7d8e7b91ab0dcf6fcda830df93d54221 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:29:30 -0800 Subject: Fix reference to obsolete urllib.urlretrieve, now urllib.request.urlretrieve --- bin/install_scons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install_scons.py b/bin/install_scons.py index ac79fd3..ed919f8 100644 --- a/bin/install_scons.py +++ b/bin/install_scons.py @@ -25,7 +25,7 @@ import os import shutil import sys import tarfile -from urllib import urlretrieve +from urllib.request import urlretrieve from Command import CommandRunner, Usage -- cgit v0.12 From 5bc5aac03463900b731b352940459ca5270c7ac5 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:34:32 -0800 Subject: remove unicode reference in ActionTests.py --- src/engine/SCons/ActionTests.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index c61a4c7..4784abf 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -337,14 +337,6 @@ class ActionTestCase(unittest.TestCase): # a singleton list returns the contained action test_positional_args(cmd_action, ["string"]) - try: - unicode - except NameError: - pass - else: - a2 = eval("SCons.Action.Action(u'string')") - assert isinstance(a2, SCons.Action.CommandAction), a2 - def line_action(a): assert isinstance(a, SCons.Action.CommandAction), a assert a.cmd_list == ["explicit", "command", "line"], a.cmd_list -- cgit v0.12 From d741d87697bdd305335df0e2b76c1e61d70de663 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:37:38 -0800 Subject: remove unicode from dblite.py --- src/engine/SCons/dblite.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/engine/SCons/dblite.py b/src/engine/SCons/dblite.py index 8351017..5ac77a5 100644 --- a/src/engine/SCons/dblite.py +++ b/src/engine/SCons/dblite.py @@ -18,26 +18,14 @@ def corruption_warning(filename): print("Warning: Discarding corrupt database:", filename) -try: - unicode -except NameError: - def is_string(s): - return isinstance(s, str) -else: - def is_string(s): - return type(s) in (str, unicode) +def is_string(s): + return isinstance(s, str) def is_bytes(s): return isinstance(s, bytes) -try: - unicode('a') -except NameError: - def unicode(s): - return s - dblite_suffix = '.dblite' # TODO: Does commenting this out break switching from py2/3? @@ -217,23 +205,17 @@ def _exercise(): assert len(db) == 0 db["foo"] = "bar" assert db["foo"] == "bar" - db[unicode("ufoo")] = unicode("ubar") - assert db[unicode("ufoo")] == unicode("ubar") db.sync() db = open("tmp", "c") assert len(db) == 2, len(db) assert db["foo"] == "bar" db["bar"] = "foo" assert db["bar"] == "foo" - db[unicode("ubar")] = unicode("ufoo") - assert db[unicode("ubar")] == unicode("ufoo") db.sync() db = open("tmp", "r") assert len(db) == 4, len(db) assert db["foo"] == "bar" assert db["bar"] == "foo" - assert db[unicode("ufoo")] == unicode("ubar") - assert db[unicode("ubar")] == unicode("ufoo") try: db.sync() except IOError as e: -- cgit v0.12 From d750da6bcc95931b0f492c318c6937b6016b73a4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:39:11 -0800 Subject: removing unicode from UtilTests.py --- src/engine/SCons/UtilTests.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index ee07e61..4968a77 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -313,7 +313,7 @@ class UtilTestCase(unittest.TestCase): """ Test the to_Bytes method""" self.assertEqual(to_bytes('Hello'), bytearray('Hello', 'utf-8'), - "Check that to_bytes creates byte array when presented with unicode string.") + "Check that to_bytes creates byte array when presented with non byte string.") def test_to_String(self): """Test the to_String() method.""" @@ -761,9 +761,6 @@ bling def test_intern(self): s1 = silent_intern("spam") - # TODO: Python 3.x does not have a unicode() global function - if sys.version[0] == '2': - s2 = silent_intern(unicode("unicode spam")) s3 = silent_intern(42) s4 = silent_intern("spam") assert id(s1) == id(s4) -- cgit v0.12 From 31406d8059594246bff3f5cca945f82301cc8c32 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:45:06 -0800 Subject: More unicode removal and cleanup --- src/engine/SCons/Util.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 0f2a27a..22df6fa 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -39,9 +39,6 @@ from collections.abc import MappingView PYPY = hasattr(sys, 'pypy_translation_info') -# Don't "from types import ..." these because we need to get at the -# types module later to look for UnicodeType. - # Below not used? # InstanceType = types.InstanceType @@ -358,14 +355,13 @@ ListTypes = (list, UserList) # Handle getting dictionary views. SequenceTypes = (list, tuple, UserList, MappingView) - +# TODO: PY3 check this benchmarking is still correct. # Note that profiling data shows a speed-up when comparing -# explicitly with str and unicode instead of simply comparing +# explicitly with str instead of simply comparing # with basestring. (at least on Python 2.5.1) StringTypes = (str, UserString) -# Empirically, it is faster to check explicitly for str and -# unicode than for basestring. +# Empirically, it is faster to check explicitly for str than for basestring. BaseStringTypes = str def is_Dict(obj, isinstance=isinstance, DictTypes=DictTypes): @@ -434,24 +430,25 @@ def flatten_sequence(sequence, isinstance=isinstance, StringTypes=StringTypes, do_flatten(item, result) return result -# Generic convert-to-string functions that abstract away whether or -# not the Python we're executing has Unicode support. The wrapper +# Generic convert-to-string functions. The wrapper # to_String_for_signature() will use a for_signature() method if the # specified object has one. # + + def to_String(s, isinstance=isinstance, str=str, UserString=UserString, BaseStringTypes=BaseStringTypes): - if isinstance(s,BaseStringTypes): + if isinstance(s, BaseStringTypes): # Early out when already a string! return s elif isinstance(s, UserString): - # s.data can only be either a unicode or a regular - # string. Please see the UserString initializer. + # s.data can only be a regular string. Please see the UserString initializer. return s.data else: return str(s) + def to_String_for_subst(s, isinstance=isinstance, str=str, to_String=to_String, BaseStringTypes=BaseStringTypes, SequenceTypes=SequenceTypes, @@ -463,12 +460,12 @@ def to_String_for_subst(s, elif isinstance(s, SequenceTypes): return ' '.join([to_String_for_subst(e) for e in s]) elif isinstance(s, UserString): - # s.data can only be either a unicode or a regular - # string. Please see the UserString initializer. + # s.data can only a regular string. Please see the UserString initializer. return s.data else: return str(s) + def to_String_for_signature(obj, to_String_for_subst=to_String_for_subst, AttributeError=AttributeError): try: @@ -478,6 +475,7 @@ def to_String_for_signature(obj, to_String_for_subst=to_String_for_subst, # pprint will output dictionary in key sorted order # with py3.5 the order was randomized. In general depending on dictionary order # which was undefined until py3.6 (where it's by insertion order) was not wise. + # TODO: Change code when floor is raised to PY36 return pprint.pformat(obj, width=1000000) else: return to_String_for_subst(obj) @@ -1495,7 +1493,7 @@ def MD5collect(signatures): def silent_intern(x): """ Perform sys.intern() on the passed argument and return the result. - If the input is ineligible (e.g. a unicode string) the original argument is + If the input is ineligible the original argument is returned and no exception is thrown. """ try: -- cgit v0.12 From d447cda50da33619e221e49b8f62f8723483e312 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:47:03 -0800 Subject: more unicode cleanup --- src/engine/SCons/BuilderTests.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 2f72832..d509219 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -306,22 +306,6 @@ class BuilderTestCase(unittest.TestCase): #be = target.get_build_env() #assert be['VAR'] == 'foo', be['VAR'] - try: unicode - except NameError: - uni = str - else: - uni = unicode - - target = builder(env, target = uni('n12 n13'), - source = [uni('n14 n15')])[0] - assert target.name == uni('n12 n13') - assert target.sources[0].name == uni('n14 n15') - - target = builder(env, target = [uni('n16 n17')], - source = uni('n18 n19'))[0] - assert target.name == uni('n16 n17') - assert target.sources[0].name == uni('n18 n19') - n20 = MyNode_without_target_from_source('n20') flag = 0 try: -- cgit v0.12 From 30394eb96f38142120beb4548918be4d5193f71e Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:52:47 -0800 Subject: more unicode cleanup --- src/engine/SCons/Platform/win32.py | 3 --- src/engine/SCons/SConfTests.py | 10 +--------- src/engine/SCons/Scanner/ProgTests.py | 17 +---------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index bb1b46d..3258dfd 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -307,9 +307,6 @@ def get_system_root(): except: pass - # Ensure system root is a string and not unicode - # (This only matters for py27 were unicode in env passed to POpen fails) - val = str(val) _system_root = val return val diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index 40cd69d..63ec8f1 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -307,10 +307,6 @@ int main(void) { return None def actionFAIL(target, source, env): return 1 - def actionUnicode(target, source, env): - with open(str(target[0]), "wb") as f: - f.write('2\302\242\n') - return None self._resetSConfState() @@ -319,14 +315,10 @@ int main(void) { log_file=self.test.workpath('config.log')) try: (ret, output) = sconf.TryAction(action=actionOK) - assert ret and output.encode('utf-8') == bytearray("RUN OK"+os.linesep,'utf-8'), (ret, output) + assert ret and output.encode('utf-8') == bytearray("RUN OK"+os.linesep, 'utf-8'), (ret, output) (ret, output) = sconf.TryAction(action=actionFAIL) assert not ret and output == "", (ret, output) - if not TestCmd.IS_PY3: - # GH Issue #3141 - unicode text and py2.7 crashes. - (ret, output) = sconf.TryAction(action=actionUnicode) - assert ret and output == u'2\xa2\n', (ret, output) finally: sconf.Finish() diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index 45fdcb2..8981fd4 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -43,6 +43,7 @@ libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib', for h in libs: test.write(h, "\n") + # define some helpers: class DummyEnvironment(object): @@ -254,22 +255,6 @@ def suite(): suite.addTest(ProgramScannerTestCase8()) suite.addTest(ProgramScannerTestCase9()) suite.addTest(ProgramScannerTestCase10()) - try: unicode - except NameError: pass - else: - code = """if 1: - class ProgramScannerTestCase4(unittest.TestCase): - def runTest(self): - env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"), - test.workpath("d1")], - LIBS=u'l2 l3'.split()) - s = SCons.Scanner.Prog.ProgramScanner() - path = s.path(env) - deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps) - suite.addTest(ProgramScannerTestCase4()) - \n""" - exec(code) return suite if __name__ == "__main__": -- cgit v0.12 From 46fc8314b5956313f4f7a3f3cbaf970f6f8616f5 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Mon, 17 Feb 2020 16:57:44 -0800 Subject: more unicode cleanup --- src/engine/SCons/Action.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index c6fc575..b22de60 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -628,17 +628,9 @@ class _ActionAction(ActionBase): """ In python 3, and in some of our tests, sys.stdout is a String io object, and it takes unicode strings only - In other cases it's a regular Python 2.x file object - which takes strings (bytes), and if you pass those a - unicode object they try to decode with 'ascii' codec - which fails if the cmd line has any hi-bit-set chars. - This code assumes s is a regular string, but should - work if it's unicode too. + This code assumes s is a regular string. """ - try: - sys.stdout.write(s + u"\n") - except UnicodeDecodeError: - sys.stdout.write(s + "\n") + sys.stdout.write(s + "\n") def __call__(self, target, source, env, exitstatfunc=_null, -- cgit v0.12