From c86e4726d30ec4d7086f7fb002e960a2dc570490 Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Wed, 21 Apr 2010 18:22:34 +0000 Subject: http://scons.tigris.org/issues/show_bug.cgi?id=2345 Apply the 'itertools' and 'itertools_imports' fixers. --- src/engine/SCons/Node/FS.py | 6 ++---- src/engine/SCons/Node/__init__.py | 8 +++---- src/engine/SCons/compat/_scons_sets.py | 39 ++++++++-------------------------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index c8b900f..b961092 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -36,10 +36,8 @@ from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -from itertools import izip import fnmatch import os -import os.path import re import shutil import stat @@ -2230,7 +2228,7 @@ class FileBuildInfo(SCons.Node.BuildInfoBase): except AttributeError: continue nodes = [] - for s, ni in izip(strings, nodeinfos): + for s, ni in zip(strings, nodeinfos): if not isinstance(s, SCons.Node.Node): s = ni.str_to_node(s) nodes.append(s) @@ -2239,7 +2237,7 @@ class FileBuildInfo(SCons.Node.BuildInfoBase): result = [] bkids = self.bsources + self.bdepends + self.bimplicit bkidsigs = self.bsourcesigs + self.bdependsigs + self.bimplicitsigs - for bkid, bkidsig in izip(bkids, bkidsigs): + for bkid, bkidsig in zip(bkids, bkidsigs): result.append(str(bkid) + ': ' + ' '.join(bkidsig.format(names=names))) result.append('%s [%s]' % (self.bactsig, self.bact)) diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index d635933..9a425b6 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -47,7 +47,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import collections import copy -from itertools import chain, izip +from itertools import chain from SCons.Debug import logInstanceCreation import SCons.Executor @@ -1051,7 +1051,7 @@ class Node: if t: Trace(': old %s new %s' % (len(then), len(children))) result = True - for child, prev_ni in izip(children, then): + for child, prev_ni in zip(children, then): if child.changed_since_last_build(self, prev_ni): if t: Trace(': %s changed' % child) result = True @@ -1197,8 +1197,8 @@ class Node: new_bkids = new.bsources + new.bdepends + new.bimplicit new_bkidsigs = new.bsourcesigs + new.bdependsigs + new.bimplicitsigs - osig = dict(izip(old_bkids, old_bkidsigs)) - nsig = dict(izip(new_bkids, new_bkidsigs)) + osig = dict(zip(old_bkids, old_bkidsigs)) + nsig = dict(zip(new_bkids, new_bkidsigs)) # The sources and dependencies we'll want to report are all stored # as relative paths to this target's directory, but we want to diff --git a/src/engine/SCons/compat/_scons_sets.py b/src/engine/SCons/compat/_scons_sets.py index 211ff16..54450b3 100644 --- a/src/engine/SCons/compat/_scons_sets.py +++ b/src/engine/SCons/compat/_scons_sets.py @@ -54,29 +54,8 @@ what's tested is actually `z in y'. # - Raymond Hettinger added a number of speedups and other # improvements. -from __future__ import generators -try: - from itertools import ifilter, ifilterfalse -except ImportError: - # Code to make the module run under Py2.2 - def ifilter(predicate, iterable): - if predicate is None: - def predicate(x): - return x - for x in iterable: - if predicate(x): - yield x - def ifilterfalse(predicate, iterable): - if predicate is None: - def predicate(x): - return x - for x in iterable: - if not predicate(x): - yield x - try: - True, False - except NameError: - True, False = (0==0, 0!=0) +# protect this import from the fixers... +exec('from itertools import ifilterfalse as filterfalse') __all__ = ['BaseSet', 'Set', 'ImmutableSet'] @@ -232,7 +211,7 @@ class BaseSet(object): little, big = self, other else: little, big = other, self - common = ifilter(big._data.has_key, little) + common = iter(filter(big._data.has_key, little)) return self.__class__(common) def __xor__(self, other): @@ -257,9 +236,9 @@ class BaseSet(object): otherdata = other._data except AttributeError: otherdata = Set(other)._data - for elt in ifilterfalse(otherdata.has_key, selfdata): + for elt in filterfalse(otherdata.has_key, selfdata): data[elt] = value - for elt in ifilterfalse(selfdata.has_key, otherdata): + for elt in filterfalse(selfdata.has_key, otherdata): data[elt] = value return result @@ -284,7 +263,7 @@ class BaseSet(object): except AttributeError: otherdata = Set(other)._data value = True - for elt in ifilterfalse(otherdata.has_key, self): + for elt in filterfalse(otherdata.has_key, self): data[elt] = value return result @@ -310,7 +289,7 @@ class BaseSet(object): self._binary_sanity_check(other) if len(self) > len(other): # Fast check for obvious cases return False - for elt in ifilterfalse(other._data.has_key, self): + for elt in filterfalse(other._data.has_key, self): return False return True @@ -319,7 +298,7 @@ class BaseSet(object): self._binary_sanity_check(other) if len(self) < len(other): # Fast check for obvious cases return False - for elt in ifilterfalse(self._data.has_key, other): + for elt in filterfalse(self._data.has_key, other): return False return True @@ -502,7 +481,7 @@ class Set(BaseSet): other = Set(other) if self is other: self.clear() - for elt in ifilter(data.has_key, other): + for elt in filter(data.has_key, other): del data[elt] # Python dict-like mass mutations: update, clear -- cgit v0.12