From 738149c9bfb9965d013d01ef99f9bb1c2819e7e8 Mon Sep 17 00:00:00 2001 From: Luca Falavigna Date: Tue, 15 Jun 2010 14:28:22 +0000 Subject: Imported Upstream version 2.0.0 --- src/engine/SCons/Scanner/C.py | 6 ++-- src/engine/SCons/Scanner/CTests.py | 23 ++++++------- src/engine/SCons/Scanner/D.py | 5 ++- src/engine/SCons/Scanner/Dir.py | 16 ++++----- src/engine/SCons/Scanner/DirTests.py | 16 ++++----- src/engine/SCons/Scanner/Fortran.py | 14 +++----- src/engine/SCons/Scanner/FortranTests.py | 20 ++++++------ src/engine/SCons/Scanner/IDL.py | 2 +- src/engine/SCons/Scanner/IDLTests.py | 20 ++++++------ src/engine/SCons/Scanner/LaTeX.py | 56 ++++++++++++-------------------- src/engine/SCons/Scanner/LaTeXTests.py | 22 ++++++------- src/engine/SCons/Scanner/Prog.py | 8 ++--- src/engine/SCons/Scanner/ProgTests.py | 49 ++++++++++++++-------------- src/engine/SCons/Scanner/RC.py | 2 +- src/engine/SCons/Scanner/RCTests.py | 21 +++++------- src/engine/SCons/Scanner/ScannerTests.py | 46 ++++++++++++-------------- src/engine/SCons/Scanner/__init__.py | 36 +++++++++----------- 17 files changed, 161 insertions(+), 201 deletions(-) (limited to 'src/engine/SCons/Scanner') diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index a8f4be9..598d3b1 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -27,7 +27,7 @@ This module implements the depenency scanner for C/C++ code. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/C.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/C.py 5023 2010/06/14 22:05:46 scons" import SCons.Node.FS import SCons.Scanner @@ -44,7 +44,7 @@ class SConsCPPScanner(SCons.cpp.PreProcessor): missing. """ def __init__(self, *args, **kw): - apply(SCons.cpp.PreProcessor.__init__, (self,)+args, kw) + SCons.cpp.PreProcessor.__init__(self, *args, **kw) self.missing = [] def initialize_result(self, fname): self.result = SCons.Util.UniqueList([fname]) @@ -81,7 +81,7 @@ def dictify_CPPDEFINES(env): return {cppdefines : None} return cppdefines -class SConsCPPScannerWrapper: +class SConsCPPScannerWrapper(object): """ The SCons wrapper around a cpp.py scanner. diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index 86f5d57..f09333b 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -21,14 +21,15 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/CTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/CTests.py 5023 2010/06/14 22:05:46 scons" +import SCons.compat + +import collections import os -import os.path import sys import TestCmd import unittest -import UserDict import SCons.Node.FS import SCons.Warnings @@ -170,9 +171,9 @@ test.write("f5b.h", "\n") # define some helpers: -class DummyEnvironment(UserDict.UserDict): +class DummyEnvironment(collections.UserDict): def __init__(self, **kw): - UserDict.UserDict.__init__(self) + collections.UserDict.__init__(self) self.data.update(kw) self.fs = SCons.Node.FS.FS(test.workpath('')) @@ -190,9 +191,9 @@ class DummyEnvironment(UserDict.UserDict): return [[strSubst]] def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_calculator(self): return None @@ -213,8 +214,8 @@ else: def deps_match(self, deps, headers): global my_normpath - scanned = map(my_normpath, map(str, deps)) - expect = map(my_normpath, headers) + scanned = list(map(my_normpath, list(map(str, deps)))) + expect = list(map(my_normpath, headers)) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) # define some tests: @@ -310,7 +311,7 @@ class CScannerTestCase8(unittest.TestCase): env.fs.chdir(env.Dir('')) path = s.path(env, dir) deps2 = s(env.File('#fa.cpp'), env, path) - headers1 = map(test.workpath, ['include/fa.h', 'include/fb.h']) + headers1 = list(map(test.workpath, ['include/fa.h', 'include/fb.h'])) headers2 = ['include/fa.h', 'include/fb.h'] deps_match(self, deps1, headers1) deps_match(self, deps2, headers2) @@ -319,7 +320,7 @@ class CScannerTestCase9(unittest.TestCase): def runTest(self): """Generate a warning when we can't find a #included file""" SCons.Warnings.enableWarningClass(SCons.Warnings.DependencyWarning) - class TestOut: + class TestOut(object): def __call__(self, x): self.out = x diff --git a/src/engine/SCons/Scanner/D.py b/src/engine/SCons/Scanner/D.py index f657eeb..04bb5a7 100644 --- a/src/engine/SCons/Scanner/D.py +++ b/src/engine/SCons/Scanner/D.py @@ -30,10 +30,9 @@ Coded by Andy Friesen # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/D.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/D.py 5023 2010/06/14 22:05:46 scons" import re -import string import SCons.Scanner @@ -54,7 +53,7 @@ class D(SCons.Scanner.Classic): def find_include(self, include, source_dir, path): # translate dots (package separators) to slashes - inc = string.replace(include, '.', '/') + inc = include.replace('.', '/') i = SCons.Node.FS.find_file(inc + '.d', (source_dir,) + path) if i is None: diff --git a/src/engine/SCons/Scanner/Dir.py b/src/engine/SCons/Scanner/Dir.py index bb25324..172aa62 100644 --- a/src/engine/SCons/Scanner/Dir.py +++ b/src/engine/SCons/Scanner/Dir.py @@ -19,30 +19,29 @@ # 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. -# -__revision__ = "src/engine/SCons/Scanner/Dir.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/Dir.py 5023 2010/06/14 22:05:46 scons" import SCons.Node.FS import SCons.Scanner def only_dirs(nodes): is_Dir = lambda n: isinstance(n.disambiguate(), SCons.Node.FS.Dir) - return filter(is_Dir, nodes) + return list(filter(is_Dir, nodes)) def DirScanner(**kw): """Return a prototype Scanner instance for scanning directories for on-disk files""" kw['node_factory'] = SCons.Node.FS.Entry kw['recursive'] = only_dirs - return apply(SCons.Scanner.Base, (scan_on_disk, "DirScanner"), kw) + return SCons.Scanner.Base(scan_on_disk, "DirScanner", **kw) def DirEntryScanner(**kw): """Return a prototype Scanner instance for "scanning" directory Nodes for their in-memory entries""" kw['node_factory'] = SCons.Node.FS.Entry kw['recursive'] = None - return apply(SCons.Scanner.Base, (scan_in_memory, "DirEntryScanner"), kw) + return SCons.Scanner.Base(scan_in_memory, "DirEntryScanner", **kw) skip_entry = {} @@ -67,7 +66,7 @@ for skip in skip_entry_list: skip_entry[skip] = 1 skip_entry[SCons.Node.FS._my_normcase(skip)] = 1 -do_not_scan = lambda k: not skip_entry.has_key(k) +do_not_scan = lambda k: k not in skip_entry def scan_on_disk(node, env, path=()): """ @@ -100,9 +99,8 @@ def scan_in_memory(node, env, path=()): # mixed Node types (Dirs and Files, for example) has a Dir as # the first entry. return [] - entry_list = filter(do_not_scan, entries.keys()) - entry_list.sort() - return map(lambda n, e=entries: e[n], entry_list) + entry_list = sorted(filter(do_not_scan, list(entries.keys()))) + return [entries[n] for n in entry_list] # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Scanner/DirTests.py b/src/engine/SCons/Scanner/DirTests.py index c18a829..debf213 100644 --- a/src/engine/SCons/Scanner/DirTests.py +++ b/src/engine/SCons/Scanner/DirTests.py @@ -21,12 +21,10 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/DirTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/DirTests.py 5023 2010/06/14 22:05:46 scons" import os.path -import string import sys -import types import unittest import TestCmd @@ -43,7 +41,7 @@ import SCons.Scanner.Dir # def Entry(self, name): # return self.fs.Entry(name) -class DummyEnvironment: +class DummyEnvironment(object): def __init__(self, root): self.fs = SCons.Node.FS.FS(root) def Dir(self, name): @@ -91,7 +89,7 @@ class DirScannerTestCase(DirScannerTestBase): os.path.join('dir', 'sub'), ] deps = s(env.Dir('dir'), env, ()) - sss = map(str, deps) + sss = list(map(str, deps)) assert sss == expect, sss expect = [ @@ -99,7 +97,7 @@ class DirScannerTestCase(DirScannerTestBase): os.path.join('dir', 'sub', 'f4'), ] deps = s(env.Dir('dir/sub'), env, ()) - sss = map(str, deps) + sss = list(map(str, deps)) assert sss == expect, sss class DirEntryScannerTestCase(DirScannerTestBase): @@ -109,16 +107,16 @@ class DirEntryScannerTestCase(DirScannerTestBase): s = SCons.Scanner.Dir.DirEntryScanner() deps = s(env.Dir('dir'), env, ()) - sss = map(str, deps) + sss = list(map(str, deps)) assert sss == [], sss deps = s(env.Dir('dir/sub'), env, ()) - sss = map(str, deps) + sss = list(map(str, deps)) assert sss == [], sss # Make sure we don't blow up if handed a non-Dir node. deps = s(env.File('dir/f1'), env, ()) - sss = map(str, deps) + sss = list(map(str, deps)) assert sss == [], sss def suite(): diff --git a/src/engine/SCons/Scanner/Fortran.py b/src/engine/SCons/Scanner/Fortran.py index 1587368..8d023e7 100644 --- a/src/engine/SCons/Scanner/Fortran.py +++ b/src/engine/SCons/Scanner/Fortran.py @@ -25,12 +25,10 @@ This module implements the dependency scanner for Fortran code. # 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. -# -__revision__ = "src/engine/SCons/Scanner/Fortran.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/Fortran.py 5023 2010/06/14 22:05:46 scons" import re -import string import SCons.Node import SCons.Node.FS @@ -75,7 +73,7 @@ class F90Scanner(SCons.Scanner.Classic): kw['skeys'] = suffixes kw['name'] = name - apply(SCons.Scanner.Current.__init__, (self,) + args, kw) + SCons.Scanner.Current.__init__(self, *args, **kw) def scan(self, node, env, path=()): @@ -94,12 +92,12 @@ class F90Scanner(SCons.Scanner.Classic): d = {} for m in defmodules: d[m] = 1 - modules = filter(lambda m, d=d: not d.has_key(m), modules) + modules = [m for m in modules if m not in d] #modules = self.undefinedModules(modules, defmodules) # Convert module name to a .mod filename suffix = env.subst('$FORTRANMODSUFFIX') - modules = map(lambda x, s=suffix: string.lower(x) + s, modules) + modules = [x.lower() + suffix for x in modules] # Remove unique items from the list mods_and_includes = SCons.Util.unique(includes+modules) node.includes = mods_and_includes @@ -123,9 +121,7 @@ class F90Scanner(SCons.Scanner.Classic): sortkey = self.sort_key(dep) nodes.append((sortkey, n)) - nodes.sort() - nodes = map(lambda pair: pair[1], nodes) - return nodes + return [pair[1] for pair in sorted(nodes)] def FortranScan(path_variable="FORTRANPATH"): """Return a prototype Scanner instance for scanning source files diff --git a/src/engine/SCons/Scanner/FortranTests.py b/src/engine/SCons/Scanner/FortranTests.py index 3ebb9a2..66eb057 100644 --- a/src/engine/SCons/Scanner/FortranTests.py +++ b/src/engine/SCons/Scanner/FortranTests.py @@ -21,7 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/FortranTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/FortranTests.py 5023 2010/06/14 22:05:46 scons" import os import os.path @@ -207,7 +207,7 @@ test.write(['modules', 'use.mod'], "\n") # define some helpers: -class DummyEnvironment: +class DummyEnvironment(object): def __init__(self, listCppPath): self.path = listCppPath self.fs = SCons.Node.FS.FS(test.workpath('')) @@ -218,10 +218,10 @@ class DummyEnvironment: elif len(args) == 1 and args[0] == 'FORTRANPATH': return self.path else: - raise KeyError, "Dummy environment only has FORTRANPATH attribute." + raise KeyError("Dummy environment only has FORTRANPATH attribute.") def has_key(self, key): - return self.Dictionary().has_key(key) + return key in self.Dictionary() def __getitem__(self,key): return self.Dictionary()[key] @@ -238,9 +238,9 @@ class DummyEnvironment: return arg def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_calculator(self): return None @@ -255,8 +255,8 @@ class DummyEnvironment: return self.fs.File(filename) def deps_match(self, deps, headers): - scanned = map(os.path.normpath, map(str, deps)) - expect = map(os.path.normpath, headers) + scanned = list(map(os.path.normpath, list(map(str, deps)))) + expect = list(map(os.path.normpath, headers)) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) # define some tests: @@ -382,7 +382,7 @@ class FortranScannerTestCase10(unittest.TestCase): env.fs.chdir(env.Dir('')) path = s.path(env, dir) deps2 = s(env.File('#fff4.f'), env, path) - headers1 = map(test.workpath, ['include/f4.f']) + headers1 = list(map(test.workpath, ['include/f4.f'])) headers2 = ['include/f4.f'] deps_match(self, deps1, headers1) deps_match(self, deps2, headers2) @@ -390,7 +390,7 @@ class FortranScannerTestCase10(unittest.TestCase): class FortranScannerTestCase11(unittest.TestCase): def runTest(self): SCons.Warnings.enableWarningClass(SCons.Warnings.DependencyWarning) - class TestOut: + class TestOut(object): def __call__(self, x): self.out = x diff --git a/src/engine/SCons/Scanner/IDL.py b/src/engine/SCons/Scanner/IDL.py index f2169f8..507b9e1 100644 --- a/src/engine/SCons/Scanner/IDL.py +++ b/src/engine/SCons/Scanner/IDL.py @@ -28,7 +28,7 @@ Definition Language) files. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/IDL.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/IDL.py 5023 2010/06/14 22:05:46 scons" import SCons.Node.FS import SCons.Scanner diff --git a/src/engine/SCons/Scanner/IDLTests.py b/src/engine/SCons/Scanner/IDLTests.py index 1dca8c8..d434971 100644 --- a/src/engine/SCons/Scanner/IDLTests.py +++ b/src/engine/SCons/Scanner/IDLTests.py @@ -21,7 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/IDLTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/IDLTests.py 5023 2010/06/14 22:05:46 scons" import TestCmd import SCons.Scanner.IDL @@ -186,7 +186,7 @@ test.write([ 'repository', 'src', 'ddd.idl'], "\n") # define some helpers: -class DummyEnvironment: +class DummyEnvironment(object): def __init__(self, listCppPath): self.path = listCppPath self.fs = SCons.Node.FS.FS(test.workpath('')) @@ -197,18 +197,18 @@ class DummyEnvironment: elif len(args) == 1 and args[0] == 'CPPPATH': return self.path else: - raise KeyError, "Dummy environment only has CPPPATH attribute." + raise KeyError("Dummy environment only has CPPPATH attribute.") def subst(self, arg, target=None, source=None, conv=None): return arg def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def has_key(self, key): - return self.Dictionary().has_key(key) + return key in self.Dictionary() def __getitem__(self,key): return self.Dictionary()[key] @@ -238,8 +238,8 @@ if os.path.normcase('foo') == os.path.normcase('FOO'): my_normpath = os.path.normcase def deps_match(self, deps, headers): - scanned = map(my_normpath, map(str, deps)) - expect = map(my_normpath, headers) + scanned = list(map(my_normpath, list(map(str, deps)))) + expect = list(map(my_normpath, headers)) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) # define some tests: @@ -329,7 +329,7 @@ class IDLScannerTestCase7(unittest.TestCase): env.fs.chdir(env.Dir('')) path = s.path(env, dir) deps2 = s(env.File('#t4.idl'), env, path) - headers1 = map(test.workpath, ['include/fa.idl', 'include/fb.idl']) + headers1 = list(map(test.workpath, ['include/fa.idl', 'include/fb.idl'])) headers2 = ['include/fa.idl', 'include/fb.idl'] deps_match(self, deps1, headers1) deps_match(self, deps2, headers2) @@ -337,7 +337,7 @@ class IDLScannerTestCase7(unittest.TestCase): class IDLScannerTestCase8(unittest.TestCase): def runTest(self): SCons.Warnings.enableWarningClass(SCons.Warnings.DependencyWarning) - class TestOut: + class TestOut(object): def __call__(self, x): self.out = x diff --git a/src/engine/SCons/Scanner/LaTeX.py b/src/engine/SCons/Scanner/LaTeX.py index 01755f4..77be34c 100644 --- a/src/engine/SCons/Scanner/LaTeX.py +++ b/src/engine/SCons/Scanner/LaTeX.py @@ -27,10 +27,9 @@ This module implements the dependency scanner for LaTeX code. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/LaTeX.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/LaTeX.py 5023 2010/06/14 22:05:46 scons" import os.path -import string import re import SCons.Scanner @@ -41,7 +40,7 @@ TexGraphics = ['.eps', '.ps'] LatexGraphics = ['.pdf', '.png', '.jpg', '.gif', '.tif'] # Used as a return value of modify_env_var if the variable is not set. -class _Null: +class _Null(object): pass _null = _Null @@ -58,13 +57,10 @@ def modify_env_var(env, var, abspath): env.PrependENVPath(var, abspath) try: if SCons.Util.is_List(env[var]): - #TODO(1.5) - #env.PrependENVPath(var, [os.path.abspath(str(p)) for p in env[var]]) - env.PrependENVPath(var, map(lambda p: os.path.abspath(str(p)), env[var])) + env.PrependENVPath(var, [os.path.abspath(str(p)) for p in env[var]]) else: # Split at os.pathsep to convert into absolute path - #TODO(1.5) env.PrependENVPath(var, [os.path.abspath(p) for p in str(env[var]).split(os.pathsep)]) - env.PrependENVPath(var, map(lambda p: os.path.abspath(p), string.split(str(env[var]), os.pathsep))) + env.PrependENVPath(var, [os.path.abspath(p) for p in str(env[var]).split(os.pathsep)]) except KeyError: pass @@ -73,15 +69,13 @@ def modify_env_var(env, var, abspath): # does not work, refuses to append ":" (os.pathsep). if SCons.Util.is_List(env['ENV'][var]): - # TODO(1.5) - #env['ENV'][var] = os.pathsep.join(env['ENV'][var]) - env['ENV'][var] = string.join(env['ENV'][var], os.pathsep) + env['ENV'][var] = os.pathsep.join(env['ENV'][var]) # Append the trailing os.pathsep character here to catch the case with no env[var] env['ENV'][var] = env['ENV'][var] + os.pathsep return save -class FindENVPathDirs: +class FindENVPathDirs(object): """A class to bind a specific *PATH variable name to a function that will return all of the *path directories.""" def __init__(self, variable): @@ -165,7 +159,7 @@ class LaTeX(SCons.Scanner.Base): 'bibliographystyle': 'BSTINPUTS', 'usepackage': 'TEXINPUTS', 'lstinputlisting': 'TEXINPUTS'} - env_variables = SCons.Util.unique(keyword_paths.values()) + env_variables = SCons.Util.unique(list(keyword_paths.values())) def __init__(self, name, suffixes, graphics_extensions, *args, **kw): @@ -184,7 +178,7 @@ class LaTeX(SCons.Scanner.Base): return [] return self.scan_recurse(node, path) - class FindMultiPathDirs: + class FindMultiPathDirs(object): """The stock FindPathDirs function has the wrong granularity: it is called once per target, while we need the path that depends on what kind of included files is being searched. This wrapper @@ -212,7 +206,7 @@ class LaTeX(SCons.Scanner.Base): # To prevent "dict is not hashable error" return tuple(di.items()) - class LaTeXScanCheck: + class LaTeXScanCheck(object): """Skip all but LaTeX source files, i.e., do not scan *.eps, *.pdf, *.jpg, etc. """ @@ -231,7 +225,7 @@ class LaTeX(SCons.Scanner.Base): kw['scan_check'] = LaTeXScanCheck(suffixes) kw['name'] = name - apply(SCons.Scanner.Base.__init__, (self,) + args, kw) + SCons.Scanner.Base.__init__(self, *args, **kw) def _latex_names(self, include): filename = include[1] @@ -252,11 +246,12 @@ class LaTeX(SCons.Scanner.Base): if include[0] == 'includegraphics': base, ext = os.path.splitext( filename ) if ext == "": - #TODO(1.5) return [filename + e for e in self.graphics_extensions] - #return map(lambda e, f=filename: f+e, self.graphics_extensions + TexGraphics) - # use the line above to find dependency for PDF builder when only .eps figure is present - # Since it will be found if the user tell scons how to make the pdf figure leave it out for now. - return map(lambda e, f=filename: f+e, self.graphics_extensions) + #return [filename+e for e in self.graphics_extensions + TexGraphics] + # use the line above to find dependencies for the PDF builder + # when only an .eps figure is present. Since it will be found + # if the user tells scons how to make the pdf figure, leave + # it out for now. + return [filename+e for e in self.graphics_extensions] return [filename] def sort_key(self, include): @@ -303,7 +298,7 @@ class LaTeX(SCons.Scanner.Base): split_includes = [] for include in includes: inc_type = noopt_cre.sub('', include[0]) - inc_list = string.split(include[1],',') + inc_list = include[1].split(',') for j in range(len(inc_list)): split_includes.append( (inc_type, inc_list[j]) ) # @@ -336,19 +331,11 @@ class LaTeX(SCons.Scanner.Base): while queue: include = queue.pop() - # TODO(1.5): more compact: - #try: - # if seen[include[1]] == 1: - # continue - #except KeyError: - # seen[include[1]] = 1 try: - already_seen = seen[include[1]] + if seen[include[1]] == 1: + continue except KeyError: seen[include[1]] = 1 - already_seen = False - if already_seen: - continue # # Handle multiple filenames in include[1] @@ -366,10 +353,7 @@ class LaTeX(SCons.Scanner.Base): # recurse down queue.extend( self.scan(n) ) - # - nodes.sort() - nodes = map(lambda pair: pair[1], nodes) - return nodes + return [pair[1] for pair in sorted(nodes)] # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py index d503a86..38c837f 100644 --- a/src/engine/SCons/Scanner/LaTeXTests.py +++ b/src/engine/SCons/Scanner/LaTeXTests.py @@ -21,14 +21,14 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/LaTeXTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/LaTeXTests.py 5023 2010/06/14 22:05:46 scons" -import os.path -import string +import SCons.compat + +import collections +import os import sys -import types import unittest -import UserDict import TestCmd import SCons.Node.FS @@ -66,9 +66,9 @@ test.write('incNO.tex', "\n") # define some helpers: # copied from CTest.py -class DummyEnvironment(UserDict.UserDict): +class DummyEnvironment(collections.UserDict): def __init__(self, **kw): - UserDict.UserDict.__init__(self) + collections.UserDict.__init__(self) self.data.update(kw) self.fs = SCons.Node.FS.FS(test.workpath('')) @@ -86,9 +86,9 @@ class DummyEnvironment(UserDict.UserDict): return [[strSubst]] def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_calculator(self): return None @@ -109,8 +109,8 @@ else: def deps_match(self, deps, headers): global my_normpath - scanned = map(my_normpath, map(str, deps)) - expect = map(my_normpath, headers) + scanned = list(map(my_normpath, list(map(str, deps)))) + expect = list(map(my_normpath, headers)) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 395d39f..97f25b3 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -21,9 +21,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/Prog.py 4720 2010/03/24 03:14:11 jars" - -import string +__revision__ = "src/engine/SCons/Scanner/Prog.py 5023 2010/06/14 22:05:46 scons" import SCons.Node import SCons.Node.FS @@ -37,7 +35,7 @@ def ProgramScanner(**kw): """Return a prototype Scanner instance for scanning executable files for static-lib dependencies""" kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH') - ps = apply(SCons.Scanner.Base, [scan, "ProgramScanner"], kw) + ps = SCons.Scanner.Base(scan, "ProgramScanner", **kw) return ps def scan(node, env, libpath = ()): @@ -53,7 +51,7 @@ def scan(node, env, libpath = ()): # There are no LIBS in this environment, so just return a null list: return [] if SCons.Util.is_String(libs): - libs = string.split(libs) + libs = libs.split() else: libs = SCons.Util.flatten(libs) diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index d3162cb..6e124e6 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -21,12 +21,10 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/ProgTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/ProgTests.py 5023 2010/06/14 22:05:46 scons" import os.path -import string import sys -import types import unittest import TestCmd @@ -45,7 +43,7 @@ for h in libs: # define some helpers: -class DummyEnvironment: +class DummyEnvironment(object): def __init__(self, **kw): self._dict = {'LIBSUFFIXES' : '.lib'} self._dict.update(kw) @@ -57,10 +55,10 @@ class DummyEnvironment: elif len(args) == 1: return self._dict[args[0]] else: - return map(lambda x, s=self: s._dict[x], args) + return [self._dict[x] for x in args] def has_key(self, key): - return self.Dictionary().has_key(key) + return key in self.Dictionary() def __getitem__(self,key): return self.Dictionary()[key] @@ -80,9 +78,9 @@ class DummyEnvironment: return s def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_factory(self, factory): return factory or self.fs.File @@ -93,7 +91,7 @@ class DummyEnvironment: def File(self, filename): return self.fs.File(test.workpath(filename)) -class DummyNode: +class DummyNode(object): def __init__(self, name): self.name = name def rexists(self): @@ -102,10 +100,9 @@ class DummyNode: return self.name def deps_match(deps, libs): - deps=map(str, deps) - deps.sort() + deps=sorted(map(str, deps)) libs.sort() - return map(os.path.normpath, deps) == map(os.path.normpath, libs) + return list(map(os.path.normpath, deps)) == list(map(os.path.normpath, libs)) # define some tests: @@ -116,14 +113,14 @@ class ProgramScannerTestCase1(unittest.TestCase): s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['l1.lib']), map(str, deps) + assert deps_match(deps, ['l1.lib']), list(map(str, deps)) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS='l1') s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['l1.lib']), map(str, deps) + assert deps_match(deps, ['l1.lib']), list(map(str, deps)) f1 = env.fs.File(test.workpath('f1')) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], @@ -144,23 +141,23 @@ class ProgramScannerTestCase1(unittest.TestCase): class ProgramScannerTestCase2(unittest.TestCase): def runTest(self): - env = DummyEnvironment(LIBPATH=map(test.workpath, - ["", "d1", "d1/d2" ]), + env = DummyEnvironment(LIBPATH=list(map(test.workpath, + ["", "d1", "d1/d2" ])), LIBS=[ 'l1', 'l2', 'l3' ]) s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), map(str, deps) + assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), list(map(str, deps)) class ProgramScannerTestCase3(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"), test.workpath("d1")], - LIBS=string.split('l2 l3')) + LIBS='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) + assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), list(map(str, deps)) class ProgramScannerTestCase5(unittest.TestCase): def runTest(self): @@ -171,11 +168,11 @@ class ProgramScannerTestCase5(unittest.TestCase): else: return arg env = SubstEnvironment(LIBPATH=[ "$blah" ], - LIBS=string.split('l2 l3')) + LIBS='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' ]), map(str, deps) + assert deps_match(deps, [ 'd1/l2.lib' ]), list(map(str, deps)) class ProgramScannerTestCase6(unittest.TestCase): def runTest(self): @@ -186,7 +183,7 @@ class ProgramScannerTestCase6(unittest.TestCase): s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps) + assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps)) class ProgramScannerTestCase7(unittest.TestCase): def runTest(self): @@ -199,7 +196,7 @@ class ProgramScannerTestCase7(unittest.TestCase): s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) - assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps) + assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps)) class ProgramScannerTestCase8(unittest.TestCase): def runTest(self): @@ -233,13 +230,15 @@ def suite(): suite.addTest(ProgramScannerTestCase6()) suite.addTest(ProgramScannerTestCase7()) suite.addTest(ProgramScannerTestCase8()) - if hasattr(types, 'UnicodeType'): + 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=string.split(u'l2 l3')) + LIBS=u'l2 l3'.split()) s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) diff --git a/src/engine/SCons/Scanner/RC.py b/src/engine/SCons/Scanner/RC.py index 23de58b..de7744b 100644 --- a/src/engine/SCons/Scanner/RC.py +++ b/src/engine/SCons/Scanner/RC.py @@ -28,7 +28,7 @@ Definition Language) files. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/RC.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/RC.py 5023 2010/06/14 22:05:46 scons" import SCons.Node.FS import SCons.Scanner diff --git a/src/engine/SCons/Scanner/RCTests.py b/src/engine/SCons/Scanner/RCTests.py index 62ca2d1..7da7e03 100644 --- a/src/engine/SCons/Scanner/RCTests.py +++ b/src/engine/SCons/Scanner/RCTests.py @@ -21,17 +21,16 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/RCTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/RCTests.py 5023 2010/06/14 22:05:46 scons" import TestCmd import SCons.Scanner.RC import unittest import sys +import collections import os -import os.path import SCons.Node.FS import SCons.Warnings -import UserDict test = TestCmd.TestCmd(workdir = '') @@ -71,9 +70,9 @@ for h in headers: # define some helpers: -class DummyEnvironment(UserDict.UserDict): +class DummyEnvironment(collections.UserDict): def __init__(self,**kw): - UserDict.UserDict.__init__(self) + collections.UserDict.__init__(self) self.data.update(kw) self.fs = SCons.Node.FS.FS(test.workpath('')) @@ -86,12 +85,12 @@ class DummyEnvironment(UserDict.UserDict): return strSubst def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def has_key(self, key): - return self.Dictionary().has_key(key) + return key in self.Dictionary() def get_calculator(self): return None @@ -112,10 +111,8 @@ if os.path.normcase('foo') == os.path.normcase('FOO'): my_normpath = os.path.normcase def deps_match(self, deps, headers): - scanned = map(my_normpath, map(str, deps)) - expect = map(my_normpath, headers) - scanned.sort() - expect.sort() + scanned = sorted(map(my_normpath, list(map(str, deps)))) + expect = sorted(map(my_normpath, headers)) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) # define some tests: diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 2a65b36..c70b8a6 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -19,23 +19,24 @@ # 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. -# -__revision__ = "src/engine/SCons/Scanner/ScannerTests.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/ScannerTests.py 5023 2010/06/14 22:05:46 scons" + +import SCons.compat +import collections import sys import unittest -import UserDict import SCons.Scanner -class DummyFS: +class DummyFS(object): def File(self, name): return DummyNode(name) -class DummyEnvironment(UserDict.UserDict): +class DummyEnvironment(collections.UserDict): def __init__(self, dict=None, **kw): - UserDict.UserDict.__init__(self, dict) + collections.UserDict.__init__(self, dict) self.data.update(kw) self.fs = DummyFS() def subst(self, strSubst, target=None, source=None, conv=None): @@ -47,13 +48,13 @@ class DummyEnvironment(UserDict.UserDict): return [self.data[strSubst[1:]]] return [[strSubst]] def subst_path(self, path, target=None, source=None, conv=None): - if type(path) != type([]): + if not isinstance(path, list): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_factory(self, factory): return factory or self.fs.File -class DummyNode: +class DummyNode(object): def __init__(self, name, search_result=()): self.name = name self.search_result = tuple(search_result) @@ -105,7 +106,7 @@ class ScannerTestCase(unittest.TestCase): class BaseTestCase(unittest.TestCase): - class skey_node: + class skey_node(object): def __init__(self, key): self.key = key def scanner_key(self): @@ -127,13 +128,13 @@ class BaseTestCase(unittest.TestCase): self.deps = deps path = scanner.path(env) scanned = scanner(filename, env, path) - scanned_strs = map(lambda x: str(x), scanned) + scanned_strs = [str(x) for x in scanned] self.failUnless(self.filename == filename, "the filename was passed incorrectly") self.failUnless(self.env == env, "the environment was passed incorrectly") self.failUnless(scanned_strs == deps, "the dependencies were returned incorrectly") for d in scanned: - self.failUnless(type(d) != type(""), "got a string in the dependencies") + self.failUnless(not isinstance(d, str), "got a string in the dependencies") if len(args) > 0: self.failUnless(self.arg == args[0], "the argument was passed incorrectly") @@ -241,7 +242,7 @@ class BaseTestCase(unittest.TestCase): dict = {} dict[s] = 777 i = hash(id(s)) - h = hash(dict.keys()[0]) + h = hash(list(dict.keys())[0]) self.failUnless(h == i, "hash Scanner base class expected %s, got %s" % (i, h)) @@ -280,7 +281,7 @@ class BaseTestCase(unittest.TestCase): "recursive = 1 didn't return all nodes: %s" % n) def odd_only(nodes): - return filter(lambda n: n % 2, nodes) + return [n for n in nodes if n % 2] s = SCons.Scanner.Base(function = self.func, recursive = odd_only) n = s.recurse_nodes(nodes) self.failUnless(n == [1, 3], @@ -337,7 +338,7 @@ class BaseTestCase(unittest.TestCase): assert s == 'xyzzy', s class SelectorTestCase(unittest.TestCase): - class skey_node: + class skey_node(object): def __init__(self, key): self.key = key def scanner_key(self): @@ -396,7 +397,7 @@ class SelectorTestCase(unittest.TestCase): class CurrentTestCase(unittest.TestCase): def test_class(self): """Test the Scanner.Current class""" - class MyNode: + class MyNode(object): def __init__(self): self.called_has_builder = None self.called_is_up_to_date = None @@ -470,7 +471,7 @@ class ClassicTestCase(unittest.TestCase): def test_scan(self): """Test the Scanner.Classic scan() method""" - class MyNode: + class MyNode(object): def __init__(self, name): self.name = name self._rfile = self @@ -568,14 +569,7 @@ class ClassicCPPTestCase(unittest.TestCase): assert n == 'path/bbb', n assert i == 'bbb', i - # TODO(1.5): remove when 2.2 is minimal; replace ccc - # variable in find_include() call below with in-line u'ccc'. - try: - ccc = eval("u'ccc'") - except SyntaxError: - ccc = 'ccc' - - n, i = s.find_include(('<', ccc), 'foo', ('path',)) + n, i = s.find_include(('<', u'ccc'), 'foo', ('path',)) assert n == 'path/ccc', n assert i == 'ccc', i @@ -595,7 +589,7 @@ def suite(): ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) return suite if __name__ == "__main__": diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 987df51..2a6f299 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -27,16 +27,15 @@ The Scanner package for the SCons software construction utility. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "src/engine/SCons/Scanner/__init__.py 4720 2010/03/24 03:14:11 jars" +__revision__ = "src/engine/SCons/Scanner/__init__.py 5023 2010/06/14 22:05:46 scons" import re -import string import SCons.Node.FS import SCons.Util -class _Null: +class _Null(object): pass # This is used instead of None as a default argument value so None can be @@ -56,13 +55,13 @@ def Scanner(function, *args, **kw): patterned on SCons code. """ if SCons.Util.is_Dict(function): - return apply(Selector, (function,) + args, kw) + return Selector(function, *args, **kw) else: - return apply(Base, (function,) + args, kw) + return Base(function, *args, **kw) -class FindPathDirs: +class FindPathDirs(object): """A class to bind a specific *PATH variable name to a function that will return all of the *path directories.""" def __init__(self, variable): @@ -80,7 +79,7 @@ class FindPathDirs: -class Base: +class Base(object): """ The base class for dependency scanners. This implements straightforward, single-pass scanning of a single file. @@ -171,7 +170,7 @@ class Base: if skeys is _null: if SCons.Util.is_Dict(function): - skeys = function.keys() + skeys = list(function.keys()) else: skeys = [] self.skeys = skeys @@ -218,7 +217,7 @@ class Base: nodes = [] for l in list: if self.node_class and not isinstance(l, self.node_class): - l = apply(node_factory, (l,), kw) + l = node_factory(l, **kw) nodes.append(l) return nodes @@ -280,9 +279,9 @@ class Selector(Base): for custom modules that may be out there.) """ def __init__(self, dict, *args, **kw): - apply(Base.__init__, (self, None,)+args, kw) + Base.__init__(self, None, *args, **kw) self.dict = dict - self.skeys = dict.keys() + self.skeys = list(dict.keys()) def __call__(self, node, env, path = ()): return self.select(node)(node, env, path) @@ -309,7 +308,7 @@ class Current(Base): def current_check(node, env): return not node.has_builder() or node.is_up_to_date() kw['scan_check'] = current_check - apply(Base.__init__, (self,) + args, kw) + Base.__init__(self, *args, **kw) class Classic(Current): """ @@ -339,7 +338,7 @@ class Classic(Current): kw['skeys'] = suffixes kw['name'] = name - apply(Current.__init__, (self,) + args, kw) + Current.__init__(self, *args, **kw) def find_include(self, include, source_dir, path): n = SCons.Node.FS.find_file(include, (source_dir,) + tuple(path)) @@ -360,7 +359,7 @@ class Classic(Current): includes = self.find_include_names (node) # Intern the names of the include files. Saves some memory # if the same header is included many times. - node.includes = map(SCons.Util.silent_intern, includes) + node.includes = list(map(SCons.Util.silent_intern, includes)) # This is a hand-coded DSU (decorate-sort-undecorate, or # Schwartzian transform) pattern. The sort key is the raw name @@ -379,12 +378,9 @@ class Classic(Current): SCons.Warnings.warn(SCons.Warnings.DependencyWarning, "No dependency generated for file: %s (included from: %s) -- file not found" % (i, node)) else: - sortkey = self.sort_key(include) - nodes.append((sortkey, n)) + nodes.append((self.sort_key(include), n)) - nodes.sort() - nodes = map(lambda pair: pair[1], nodes) - return nodes + return [pair[1] for pair in sorted(nodes)] class ClassicCPP(Classic): """ @@ -408,7 +404,7 @@ class ClassicCPP(Classic): return n, i def sort_key(self, include): - return SCons.Node.FS._my_normcase(string.join(include)) + return SCons.Node.FS._my_normcase(' '.join(include)) # Local Variables: # tab-width:4 -- cgit v1.2.3