From 22d352500f1cd6bd0c53d788a5dc44a1fefa676e Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Thu, 25 Mar 2010 04:14:28 +0000 Subject: Move 2.0 changes collected in branches/pending back to trunk for further development. Note that this set of changes is NOT backward-compatible; the trunk no longer works with Python 1.5.2, 2.0, or 2.1. --- QMTest/SConscript | 3 +- QMTest/TestCmd.py | 68 +++---- QMTest/TestCommon.py | 57 +++--- QMTest/TestRuntest.py | 15 +- QMTest/TestSCons.py | 124 ++++++------ QMTest/TestSConsMSVS.py | 25 ++- QMTest/TestSCons_time.py | 19 +- QMTest/TestSConsign.py | 7 +- QMTest/scons_tdb.py | 33 ++-- QMTest/unittest.py | 40 ++-- SConstruct | 137 ++++++------- bench/bench.py | 11 +- bench/env.__setitem__.py | 21 +- bench/is_types.py | 8 +- bench/lvars-gvars.py | 6 +- bench/timeit.py | 10 +- bin/SConsDoc.py | 5 +- bin/import-test.py | 2 +- bin/linecount.py | 6 +- bin/memoicmp.py | 25 +-- bin/objcounts.py | 2 +- bin/scons-diff.py | 8 +- bin/scons-doc.py | 79 ++++---- bin/scons-proc.py | 31 ++- bin/scons-test.py | 5 +- bin/scons-unzip.py | 2 +- bin/sconsexamples.py | 52 +++-- bin/sfsum | 3 +- bootstrap.py | 9 +- doc/SConscript | 35 ++-- doc/man/scons.1 | 10 +- doc/user/less-simple.in | 2 +- doc/user/less-simple.xml | 2 +- doc/user/tasks.in | 5 +- doc/user/tasks.xml | 5 +- runtest.py | 77 ++++---- src/engine/SCons/Action.py | 98 +++++---- src/engine/SCons/ActionTests.py | 50 +++-- src/engine/SCons/Builder.py | 62 +++--- src/engine/SCons/BuilderTests.py | 138 ++++++------- src/engine/SCons/CacheDir.py | 3 +- src/engine/SCons/CacheDirTests.py | 2 +- src/engine/SCons/Conftest.py | 9 +- src/engine/SCons/Debug.py | 18 +- src/engine/SCons/Defaults.py | 25 ++- src/engine/SCons/DefaultsTests.py | 3 +- src/engine/SCons/Environment.py | 163 +++++++-------- src/engine/SCons/EnvironmentTests.py | 263 ++++++++++++------------- src/engine/SCons/Errors.py | 2 +- src/engine/SCons/Executor.py | 34 ++-- src/engine/SCons/ExecutorTests.py | 23 ++- src/engine/SCons/Job.py | 10 +- src/engine/SCons/JobTests.py | 3 +- src/engine/SCons/Memoize.py | 10 +- src/engine/SCons/MemoizeTests.py | 2 +- src/engine/SCons/Node/Alias.py | 7 +- src/engine/SCons/Node/AliasTests.py | 2 +- src/engine/SCons/Node/FS.py | 68 ++++--- src/engine/SCons/Node/FSTests.py | 118 ++++++----- src/engine/SCons/Node/NodeTests.py | 24 +-- src/engine/SCons/Node/Python.py | 2 +- src/engine/SCons/Node/PythonTests.py | 2 +- src/engine/SCons/Node/__init__.py | 35 ++-- src/engine/SCons/Options/BoolOption.py | 2 +- src/engine/SCons/Options/EnumOption.py | 2 +- src/engine/SCons/Options/ListOption.py | 2 +- src/engine/SCons/Options/PackageOption.py | 2 +- src/engine/SCons/Options/PathOption.py | 12 +- src/engine/SCons/Options/__init__.py | 17 +- src/engine/SCons/PathList.py | 5 +- src/engine/SCons/PathListTests.py | 2 +- src/engine/SCons/Platform/__init__.py | 21 +- src/engine/SCons/Platform/aix.py | 7 +- src/engine/SCons/Platform/os2.py | 2 +- src/engine/SCons/Platform/posix.py | 25 ++- src/engine/SCons/Platform/win32.py | 23 ++- src/engine/SCons/SConf.py | 33 ++-- src/engine/SCons/SConfTests.py | 3 +- src/engine/SCons/SConsignTests.py | 2 +- src/engine/SCons/Scanner/C.py | 2 +- src/engine/SCons/Scanner/CTests.py | 8 +- src/engine/SCons/Scanner/D.py | 3 +- src/engine/SCons/Scanner/Dir.py | 13 +- src/engine/SCons/Scanner/DirTests.py | 11 +- src/engine/SCons/Scanner/Fortran.py | 10 +- src/engine/SCons/Scanner/FortranTests.py | 10 +- src/engine/SCons/Scanner/IDLTests.py | 10 +- src/engine/SCons/Scanner/LaTeX.py | 17 +- src/engine/SCons/Scanner/LaTeXTests.py | 7 +- src/engine/SCons/Scanner/Prog.py | 6 +- src/engine/SCons/Scanner/ProgTests.py | 35 ++-- src/engine/SCons/Scanner/RCTests.py | 8 +- src/engine/SCons/Scanner/ScannerTests.py | 9 +- src/engine/SCons/Scanner/__init__.py | 19 +- src/engine/SCons/Script/Interactive.py | 16 +- src/engine/SCons/Script/Main.py | 44 ++--- src/engine/SCons/Script/MainTests.py | 2 +- src/engine/SCons/Script/SConsOptions.py | 32 +-- src/engine/SCons/Script/SConscript.py | 30 +-- src/engine/SCons/Script/__init__.py | 5 +- src/engine/SCons/Subst.py | 58 +++--- src/engine/SCons/SubstTests.py | 17 +- src/engine/SCons/Taskmaster.py | 8 +- src/engine/SCons/TaskmasterTests.py | 2 +- src/engine/SCons/Tool/FortranCommon.py | 15 +- src/engine/SCons/Tool/JavaCommon.py | 7 +- src/engine/SCons/Tool/JavaCommonTests.py | 2 +- src/engine/SCons/Tool/MSCommon/common.py | 4 +- src/engine/SCons/Tool/MSCommon/netframework.py | 8 +- src/engine/SCons/Tool/MSCommon/sdk.py | 14 +- src/engine/SCons/Tool/MSCommon/vs.py | 12 +- src/engine/SCons/Tool/PharLapCommon.py | 7 +- src/engine/SCons/Tool/ToolTests.py | 4 +- src/engine/SCons/Tool/__init__.py | 15 +- src/engine/SCons/Tool/bcc32.py | 1 - src/engine/SCons/Tool/cc.py | 18 +- src/engine/SCons/Tool/dmd.py | 3 +- src/engine/SCons/Tool/dvipdf.py | 3 +- src/engine/SCons/Tool/filesystem.py | 4 +- src/engine/SCons/Tool/fortran.py | 1 - src/engine/SCons/Tool/gs.py | 2 +- src/engine/SCons/Tool/hpc++.py | 5 +- src/engine/SCons/Tool/icl.py | 4 +- src/engine/SCons/Tool/ifl.py | 4 +- src/engine/SCons/Tool/ifort.py | 8 +- src/engine/SCons/Tool/install.py | 6 +- src/engine/SCons/Tool/intelc.py | 6 +- src/engine/SCons/Tool/ipkg.py | 5 +- src/engine/SCons/Tool/javac.py | 17 +- src/engine/SCons/Tool/javah.py | 5 +- src/engine/SCons/Tool/lex.py | 4 +- src/engine/SCons/Tool/midl.py | 6 +- src/engine/SCons/Tool/mingw.py | 1 - src/engine/SCons/Tool/mslink.py | 6 +- src/engine/SCons/Tool/msvc.py | 11 +- src/engine/SCons/Tool/msvs.py | 115 +++++------ src/engine/SCons/Tool/msvsTests.py | 41 ++-- src/engine/SCons/Tool/mwcc.py | 5 +- src/engine/SCons/Tool/packaging/__init__.py | 24 +-- src/engine/SCons/Tool/packaging/ipk.py | 10 +- src/engine/SCons/Tool/packaging/msi.py | 25 +-- src/engine/SCons/Tool/packaging/rpm.py | 42 ++-- src/engine/SCons/Tool/rmic.py | 3 +- src/engine/SCons/Tool/swig.py | 18 +- src/engine/SCons/Tool/tex.py | 7 +- src/engine/SCons/Tool/textfile.py | 2 +- src/engine/SCons/Tool/wix.py | 3 +- src/engine/SCons/Tool/yacc.py | 3 +- src/engine/SCons/Util.py | 90 ++++----- src/engine/SCons/UtilTests.py | 37 ++-- src/engine/SCons/Variables/BoolVariable.py | 4 +- src/engine/SCons/Variables/EnumVariable.py | 20 +- src/engine/SCons/Variables/ListVariable.py | 25 ++- src/engine/SCons/Variables/PackageVariable.py | 11 +- src/engine/SCons/Variables/VariablesTests.py | 18 +- src/engine/SCons/Variables/__init__.py | 22 +-- src/engine/SCons/Warnings.py | 7 +- src/engine/SCons/compat/__init__.py | 27 +++ src/engine/SCons/compat/_scons_optparse.py | 4 +- src/engine/SCons/compat/builtins.py | 2 +- src/engine/SCons/cpp.py | 31 ++- src/engine/SCons/cppTests.py | 9 +- src/engine/SCons/exitfuncs.py | 2 +- src/script/scons-time.py | 21 +- src/script/scons.py | 13 +- src/script/sconsign.py | 26 ++- src/setup.py | 12 +- src/test_aegistests.py | 10 +- src/test_files.py | 7 +- src/test_interrupts.py | 10 +- src/test_pychecker.py | 16 +- src/test_setup.py | 25 ++- src/test_strings.py | 10 +- test/AR/AR.py | 6 +- test/AR/ARCOM.py | 2 +- test/AR/ARCOMSTR.py | 2 +- test/AR/ARFLAGS.py | 6 +- test/AS/AS.py | 3 +- test/AS/ASCOM.py | 2 +- test/AS/ASCOMSTR.py | 2 +- test/AS/ASFLAGS.py | 3 +- test/AS/ASPP.py | 3 +- test/AS/ASPPCOM.py | 2 +- test/AS/ASPPCOMSTR.py | 4 +- test/AS/ASPPFLAGS.py | 3 +- test/AS/as-live.py | 8 +- test/AS/ml.py | 6 +- test/AS/nasm.py | 12 +- test/Actions/actions.py | 12 +- test/Actions/addpost-link.py | 3 +- test/Actions/function.py | 2 +- test/AddOption/help.py | 15 +- test/Alias/action.py | 11 +- test/Alias/scanner.py | 3 +- test/BitKeeper/BITKEEPERCOM.py | 3 +- test/BitKeeper/BITKEEPERCOMSTR.py | 3 +- test/BitKeeper/BitKeeper.py | 9 +- test/Builder/multi/same-overrides.py | 4 +- test/CC/CC.py | 9 +- test/CC/CCCOM.py | 2 +- test/CC/CCCOMSTR.py | 2 +- test/CC/SHCC.py | 6 +- test/CC/SHCCCOM.py | 2 +- test/CC/SHCCCOMSTR.py | 2 +- test/CC/SHCCFLAGS.py | 3 +- test/CC/SHCFLAGS.py | 3 +- test/CFILESUFFIX.py | 3 +- test/CPPPATH/absolute-path.py | 3 +- test/CVS.py | 9 +- test/CVSCOM.py | 3 +- test/CVSCOMSTR.py | 3 +- test/CXX/CXX.py | 9 +- test/CXX/CXXCOM.py | 2 +- test/CXX/CXXCOMSTR.py | 2 +- test/CXX/CXXFILESUFFIX.py | 3 +- test/CXX/CXXFLAGS.py | 3 +- test/CXX/SHCXX.py | 6 +- test/CXX/SHCXXCOM.py | 2 +- test/CXX/SHCXXCOMSTR.py | 2 +- test/CXX/SHCXXFLAGS.py | 3 +- test/CacheDir/CacheDir.py | 3 +- test/CacheDir/VariantDir.py | 3 +- test/CacheDir/debug.py | 3 +- test/CacheDir/environment.py | 3 +- test/CacheDir/option--cd.py | 3 +- test/CacheDir/option--cf.py | 3 +- test/CacheDir/option--cs.py | 3 +- test/Case.py | 3 +- test/Chmod.py | 3 +- test/Climb/explicit-parent--D.py | 3 +- test/Climb/explicit-parent--U.py | 3 +- test/Climb/explicit-parent-u.py | 3 +- test/Climb/option-u.py | 3 +- test/Configure/config-h.py | 9 +- test/Copy-Action.py | 7 +- test/DVIPDF/DVIPDF.py | 7 +- test/DVIPDF/DVIPDFCOM.py | 2 +- test/DVIPDF/DVIPDFCOMSTR.py | 2 +- test/DVIPDF/DVIPDFFLAGS.py | 7 +- test/DVIPS/DVIPS.py | 7 +- test/DVIPS/DVIPSFLAGS.py | 7 +- test/DVIPS/PSCOM.py | 2 +- test/DVIPS/PSCOMSTR.py | 2 +- test/Delete.py | 6 +- test/Deprecated/BuildDir.py | 8 +- test/Deprecated/Options/BoolOption.py | 4 +- test/Deprecated/Options/EnumOption.py | 3 +- test/Deprecated/Options/ListOption.py | 3 +- test/Deprecated/Options/Options.py | 32 ++- test/Deprecated/Options/PackageOption.py | 3 +- test/Deprecated/Options/PathOption.py | 3 +- test/Deprecated/SConscript-build_dir.py | 3 +- test/Deprecated/debug-stree.py | 6 +- test/ESCAPE.py | 3 +- test/Errors/InternalError.py | 2 +- test/Errors/UserError.py | 2 +- test/Errors/execute-a-directory.py | 3 +- test/Errors/non-executable-file.py | 3 +- test/Errors/nonexistent-executable.py | 3 +- test/Exit.py | 7 +- test/Flatten.py | 11 +- test/Fortran/F77.py | 7 +- test/Fortran/F77COMSTR.py | 2 +- test/Fortran/F77FLAGS.py | 7 +- test/Fortran/F90.py | 5 +- test/Fortran/F90COMSTR.py | 2 +- test/Fortran/F90FLAGS.py | 5 +- test/Fortran/F95.py | 7 +- test/Fortran/F95COMSTR.py | 2 +- test/Fortran/F95FLAGS.py | 7 +- test/Fortran/FORTRAN.py | 7 +- test/Fortran/FORTRANCOMSTR.py | 2 +- test/Fortran/FORTRANFLAGS.py | 7 +- test/Fortran/FORTRANMODDIR.py | 3 +- test/Fortran/SHF77.py | 7 +- test/Fortran/SHF77COMSTR.py | 2 +- test/Fortran/SHF77FLAGS.py | 7 +- test/Fortran/SHF90.py | 7 +- test/Fortran/SHF90COMSTR.py | 2 +- test/Fortran/SHF90FLAGS.py | 5 +- test/Fortran/SHF95.py | 7 +- test/Fortran/SHF95COMSTR.py | 2 +- test/Fortran/SHF95FLAGS.py | 7 +- test/Fortran/SHFORTRAN.py | 7 +- test/Fortran/SHFORTRANCOMSTR.py | 2 +- test/Fortran/SHFORTRANFLAGS.py | 7 +- test/Fortran/USE-MODULE.py | 3 +- test/Fortran/common.py | 3 +- test/GetBuildFailures/serial.py | 3 +- test/GetOption/help.py | 6 +- test/Ghostscript/GS.py | 6 +- test/Ghostscript/GSCOM.py | 2 +- test/Ghostscript/GSCOMSTR.py | 2 +- test/Ghostscript/GSFLAGS.py | 6 +- test/Glob/Repository.py | 3 +- test/IDL/MIDLCOM.py | 2 +- test/IDL/MIDLCOMSTR.py | 2 +- test/Install/Install.py | 6 +- test/Install/wrap-by-attribute.py | 3 +- test/Interactive/implicit-VariantDir.py | 3 +- test/Interactive/shell.py | 3 +- test/Java/JAR.py | 13 +- test/Java/JARCHDIR.py | 3 +- test/Java/JARCOM.py | 2 +- test/Java/JARCOMSTR.py | 2 +- test/Java/JARFLAGS.py | 3 +- test/Java/JAVABOOTCLASSPATH.py | 3 +- test/Java/JAVACCOM.py | 2 +- test/Java/JAVACCOMSTR.py | 2 +- test/Java/JAVACFLAGS.py | 3 +- test/Java/JAVAH.py | 8 +- test/Java/JAVAHCOM.py | 2 +- test/Java/JAVAHCOMSTR.py | 2 +- test/Java/Java-1.4.py | 3 +- test/Java/Java-1.5.py | 3 +- test/Java/Java-1.6.py | 3 +- test/Java/RMIC.py | 11 +- test/Java/RMICCOM.py | 2 +- test/Java/RMICCOMSTR.py | 2 +- test/LEX/LEX.py | 3 +- test/LEX/LEXCOM.py | 2 +- test/LEX/LEXCOMSTR.py | 2 +- test/LEX/LEXFLAGS.py | 5 +- test/LEX/live.py | 7 +- test/LINK/LINK.py | 6 +- test/LINK/LINKCOM.py | 2 +- test/LINK/LINKCOMSTR.py | 4 +- test/LINK/LINKFLAGS.py | 8 +- test/LINK/SHLINK.py | 6 +- test/LINK/SHLINKCOM.py | 4 +- test/LINK/SHLINKCOMSTR.py | 4 +- test/LINK/SHLINKFLAGS.py | 8 +- test/Libs/SharedLibrary.py | 11 +- test/Libs/SharedLibraryIxes.py | 12 +- test/LoadableModule.py | 5 +- test/M4/M4.py | 9 +- test/M4/M4COM.py | 2 +- test/M4/M4COMSTR.py | 2 +- test/MSVC/PCHCOM.py | 2 +- test/MSVC/PCHCOMSTR.py | 2 +- test/MSVC/RCCOM.py | 2 +- test/MSVC/RCCOMSTR.py | 2 +- test/MSVC/batch.py | 6 +- test/MSVS/vs-8.0-x64-files.py | 7 +- test/MinGW/RCCOM.py | 2 +- test/MinGW/RCCOMSTR.py | 2 +- test/Mkdir.py | 9 +- test/Move.py | 3 +- test/NodeOps.py | 11 +- test/Parallel/ref_count.py | 3 +- test/ParseConfig.py | 6 +- test/Perforce/P4COM.py | 3 +- test/Perforce/P4COMSTR.py | 3 +- test/Perforce/Perforce.py | 22 +-- test/Progress/TARGET.py | 3 +- test/Progress/file.py | 3 +- test/Progress/spinner.py | 3 +- test/QT/QTFLAGS.py | 3 +- test/QT/Tool.py | 8 +- test/QT/copied-env.py | 8 +- test/QT/generated-ui.py | 2 +- test/QT/installed.py | 9 +- test/QT/manual.py | 2 +- test/QT/source-from-ui.py | 3 +- test/QT/up-to-date.py | 3 +- test/QT/warnings.py | 3 +- test/RANLIB/RANLIB.py | 6 +- test/RANLIB/RANLIBCOM.py | 4 +- test/RANLIB/RANLIBCOMSTR.py | 4 +- test/RANLIB/RANLIBFLAGS.py | 6 +- test/RCS/RCS_COCOM.py | 3 +- test/RCS/RCS_COCOMSTR.py | 3 +- test/RCS/diskcheck.py | 5 +- test/RCS/explicit.py | 3 +- test/RCS/transparent.py | 3 +- test/Repository/LIBPATH.py | 12 +- test/Repository/M4.py | 3 +- test/Repository/RMIC.py | 6 +- test/Repository/SConscript.py | 6 +- test/Repository/SharedLibrary.py | 3 +- test/Repository/VariantDir.py | 2 +- test/Repository/option-f.py | 3 +- test/Repository/targets.py | 2 +- test/Requires/basic.py | 4 +- test/Requires/eval-order.py | 4 +- test/Rpcgen/RPCGEN.py | 5 +- test/Rpcgen/RPCGENCLIENTFLAGS.py | 5 +- test/Rpcgen/RPCGENFLAGS.py | 5 +- test/Rpcgen/RPCGENHEADERFLAGS.py | 5 +- test/Rpcgen/RPCGENSERVICEFLAGS.py | 5 +- test/Rpcgen/RPCGENXDRFLAGS.py | 5 +- test/SCCS/SCCSCOM.py | 3 +- test/SCCS/SCCSCOMSTR.py | 3 +- test/SCCS/diskcheck.py | 10 +- test/SCCS/explicit.py | 9 +- test/SCCS/implicit.py | 6 +- test/SCCS/transparent.py | 9 +- test/SConscript/SConscript.py | 2 +- test/SConscript/src_dir.py | 2 +- test/SHELL.py | 5 +- test/SPAWN.py | 5 +- test/SWIG/SWIGCOM.py | 2 +- test/SWIG/SWIGCOMSTR.py | 2 +- test/SWIG/live.py | 6 +- test/Scanner/FindPathDirs.py | 3 +- test/Scanner/Scanner.py | 4 +- test/Scanner/exception.py | 4 +- test/Scanner/generated.py | 36 ++-- test/Scanner/no-Dir-node.py | 3 +- test/SourceCode.py | 3 +- test/Subversion.py | 6 +- test/TAR/TAR.py | 6 +- test/TAR/TARCOM.py | 2 +- test/TAR/TARCOMSTR.py | 2 +- test/TAR/TARFLAGS.py | 7 +- test/TARGET-dir.py | 3 +- test/TARGETS.py | 24 +-- test/TEX/LATEX.py | 7 +- test/TEX/LATEXCOM.py | 2 +- test/TEX/LATEXCOMSTR.py | 2 +- test/TEX/LATEXFLAGS.py | 6 +- test/TEX/PDFLATEX.py | 7 +- test/TEX/PDFLATEXCOM.py | 2 +- test/TEX/PDFLATEXCOMSTR.py | 2 +- test/TEX/PDFLATEXFLAGS.py | 6 +- test/TEX/PDFTEX.py | 7 +- test/TEX/PDFTEXCOM.py | 2 +- test/TEX/PDFTEXCOMSTR.py | 2 +- test/TEX/PDFTEXFLAGS.py | 6 +- test/TEX/TEX.py | 18 +- test/TEX/TEXCOM.py | 2 +- test/TEX/TEXCOMSTR.py | 2 +- test/TEX/TEXFLAGS.py | 6 +- test/ToolSurrogate.py | 9 +- test/Touch.py | 3 +- test/Value.py | 3 +- test/Variables/BoolVariable.py | 3 +- test/Variables/EnumVariable.py | 3 +- test/Variables/ListVariable.py | 3 +- test/Variables/PackageVariable.py | 3 +- test/Variables/PathVariable.py | 3 +- test/Variables/Variables.py | 32 ++- test/VariantDir/SConscript-variant_dir.py | 3 +- test/VariantDir/VariantDir.py | 8 +- test/VariantDir/errors.py | 3 +- test/WhereIs.py | 23 ++- test/Win32/bad-drive.py | 8 +- test/Win32/default-drive.py | 3 +- test/Win32/mingw.py | 7 +- test/Win32/win32pathmadness.py | 9 +- test/YACC/YACC.py | 3 +- test/YACC/YACCCOM.py | 2 +- test/YACC/YACCCOMSTR.py | 2 +- test/YACC/YACCFLAGS.py | 5 +- test/YACC/YACCHFILESUFFIX.py | 5 +- test/YACC/YACCHXXFILESUFFIX.py | 5 +- test/YACC/YACCVCGFILESUFFIX.py | 5 +- test/YACC/live.py | 7 +- test/ZIP/ZIP.py | 11 +- test/ZIP/ZIPCOM.py | 2 +- test/ZIP/ZIPCOMSTR.py | 2 +- test/custom-concat.py | 2 +- test/explain/basic.py | 3 +- test/gnutools.py | 5 +- test/implicit/IMPLICIT_COMMAND_DEPENDENCIES.py | 3 +- test/long-lines/signature.py | 3 +- test/no-arguments.py | 2 +- test/no-target.py | 3 +- test/option--C.py | 5 +- test/option--random.py | 3 +- test/option-j.py | 9 +- test/option/debug-count.py | 6 +- test/option/debug-memory.py | 5 +- test/option/debug-presub.py | 3 +- test/option/debug-time.py | 7 +- test/option/help-options.py | 16 +- test/option/md5-chunksize.py | 4 +- test/option/profile.py | 6 +- test/option/stack-size.py | 4 +- test/option/tree-all.py | 13 +- test/packaging/convenience-functions.py | 9 +- test/preserve-source.py | 2 +- test/python-version.py | 1 - test/runtest/fallback.py | 7 +- test/runtest/noqmtest.py | 3 +- test/runtest/python.py | 3 +- test/runtest/qmtest.py | 3 +- test/runtest/xml/output.py | 1 - test/scons-time/help/all-subcommands.py | 7 +- test/sconsign/ghost-entries.py | 2 +- test/sconsign/script/SConsignFile.py | 3 +- test/sconsign/script/Signatures.py | 3 +- test/sconsign/script/no-SConsignFile.py | 3 +- test/special-filenames.py | 8 +- test/srcchange.py | 6 +- test/subdivide.py | 3 +- test/suffixes.py | 3 +- test/textfile.py | 19 +- timings/hundred/SConstruct | 4 +- 499 files changed, 2376 insertions(+), 2872 deletions(-) diff --git a/QMTest/SConscript b/QMTest/SConscript index e141a51..8e5585f 100644 --- a/QMTest/SConscript +++ b/QMTest/SConscript @@ -26,7 +26,6 @@ # import os.path -import string Import('build_dir', 'env') @@ -50,7 +49,7 @@ def copy(target, source, env): # Note: We construct the __ VERSION __ substitution string at # run-time so it doesn't get replaced when this file gets copied # into the tree for packaging. - c = string.replace(c, '__' + 'VERSION' + '__', env['VERSION']) + c = c.replace('__' + 'VERSION' + '__', env['VERSION']) open(t, 'wb').write(c) for file in files: diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 029c1d0..163a78d 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -213,6 +213,7 @@ version. # PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, # AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __author__ = "Steven Knight " __revision__ = "TestCmd.py 0.37.D001 2010/01/11 16:55:50 knight" @@ -224,7 +225,6 @@ import os.path import re import shutil import stat -import string import sys import tempfile import time @@ -282,7 +282,7 @@ _chain_to_exitfunc = None def _clean(): global _Cleanup - cleanlist = filter(None, _Cleanup) + cleanlist = [_f for _f in _Cleanup if _f] del _Cleanup[:] cleanlist.reverse() for test in cleanlist: @@ -307,16 +307,16 @@ try: except NameError: def zip(*lists): result = [] - for i in xrange(min(map(len, lists))): - result.append(tuple(map(lambda l, i=i: l[i], lists))) + for i in xrange(min(list(map(len, lists)))): + result.append(tuple([l[i] for l in lists])) return result class Collector: def __init__(self, top): self.entries = [top] def __call__(self, arg, dirname, names): - pathjoin = lambda n, d=dirname: os.path.join(d, n) - self.entries.extend(map(pathjoin, names)) + pathjoin = lambda n: os.path.join(dirname, n) + self.entries.extend(list(map(pathjoin, names))) def _caller(tblist, skip): string = "" @@ -407,9 +407,9 @@ def match_exact(lines = None, matches = None): """ """ if not is_List(lines): - lines = string.split(lines, "\n") + lines = lines.split("\n") if not is_List(matches): - matches = string.split(matches, "\n") + matches = matches.split("\n") if len(lines) != len(matches): return for i in range(len(lines)): @@ -421,9 +421,9 @@ def match_re(lines = None, res = None): """ """ if not is_List(lines): - lines = string.split(lines, "\n") + lines = lines.split("\n") if not is_List(res): - res = string.split(res, "\n") + res = res.split("\n") if len(lines) != len(res): return for i in range(len(lines)): @@ -441,9 +441,9 @@ def match_re_dotall(lines = None, res = None): """ """ if not type(lines) is type(""): - lines = string.join(lines, "\n") + lines = "\n".join(lines) if not type(res) is type(""): - res = string.join(res, "\n") + res = "\n".join(res) s = "^" + res + "$" try: expr = re.compile(s, re.DOTALL) @@ -472,15 +472,15 @@ else: for op, a1, a2, b1, b2 in sm.get_opcodes(): if op == 'delete': result.append("%sd%d" % (comma(a1, a2), b1)) - result.extend(map(lambda l: '< ' + l, a[a1:a2])) + result.extend(['< ' + l for l in a[a1:a2]]) elif op == 'insert': result.append("%da%s" % (a1, comma(b1, b2))) - result.extend(map(lambda l: '> ' + l, b[b1:b2])) + result.extend(['> ' + l for l in b[b1:b2]]) elif op == 'replace': result.append("%sc%s" % (comma(a1, a2), comma(b1, b2))) - result.extend(map(lambda l: '< ' + l, a[a1:a2])) + result.extend(['< ' + l for l in a[a1:a2]]) result.append('---') - result.extend(map(lambda l: '> ' + l, b[b1:b2])) + result.extend(['> ' + l for l in b[b1:b2]]) return result def diff_re(a, b, fromfile='', tofile='', @@ -530,13 +530,13 @@ if sys.platform == 'win32': if path is None: path = os.environ['PATH'] if is_String(path): - path = string.split(path, os.pathsep) + path = path.split(os.pathsep) if pathext is None: pathext = os.environ['PATHEXT'] if is_String(pathext): - pathext = string.split(pathext, os.pathsep) + pathext = pathext.split(os.pathsep) for ext in pathext: - if string.lower(ext) == string.lower(file[-len(ext):]): + if ext.lower() == file[-len(ext):].lower(): pathext = [''] break for dir in path: @@ -553,7 +553,7 @@ else: if path is None: path = os.environ['PATH'] if is_String(path): - path = string.split(path, os.pathsep) + path = path.split(os.pathsep) for dir in path: f = os.path.join(dir, file) if os.path.isfile(f): @@ -649,14 +649,14 @@ except ImportError: universal_newlines = 1 def __init__(self, command, **kw): if kw.get('stderr') == 'STDOUT': - apply(popen2.Popen4.__init__, (self, command, 1)) + popen2.Popen4.__init__(self, command, 1) else: - apply(popen2.Popen3.__init__, (self, command, 1)) + popen2.Popen3.__init__(self, command, 1) self.stdin = self.tochild self.stdout = self.fromchild self.stderr = self.childerr def wait(self, *args, **kw): - resultcode = apply(popen2.Popen3.wait, (self,)+args, kw) + resultcode = popen2.Popen3.wait(self, *args, **kw) if os.WIFEXITED(resultcode): return os.WEXITSTATUS(resultcode) elif os.WIFSIGNALED(resultcode): @@ -879,7 +879,7 @@ class TestCmd(object): #self.diff_function = difflib.unified_diff self._dirlist = [] self._preserve = {'pass_test': 0, 'fail_test': 0, 'no_result': 0} - if os.environ.has_key('PRESERVE') and not os.environ['PRESERVE'] is '': + if 'PRESERVE' in os.environ and not os.environ['PRESERVE'] is '': self._preserve['pass_test'] = os.environ['PRESERVE'] self._preserve['fail_test'] = os.environ['PRESERVE'] self._preserve['no_result'] = os.environ['PRESERVE'] @@ -924,9 +924,9 @@ class TestCmd(object): slash = '\\' special = '"$' - arg = string.replace(arg, slash, slash+slash) + arg = arg.replace(slash, slash+slash) for c in special: - arg = string.replace(arg, c, slash+c) + arg = arg.replace(c, slash+c) if re_space.search(arg): arg = '"' + arg + '"' @@ -944,7 +944,7 @@ class TestCmd(object): def canonicalize(self, path): if is_List(path): - path = apply(os.path.join, tuple(path)) + path = os.path.join(*tuple(path)) if not os.path.isabs(path): path = os.path.join(self.workdir, path) return path @@ -1012,7 +1012,7 @@ class TestCmd(object): cmd = list(interpreter) + cmd if arguments: if type(arguments) == type(''): - arguments = string.split(arguments) + arguments = arguments.split() cmd.extend(arguments) return cmd @@ -1033,7 +1033,7 @@ class TestCmd(object): def diff(self, a, b, name, *args, **kw): print self.banner(name) args = (a.splitlines(), b.splitlines()) + args - lines = apply(self.diff_function, args, kw) + lines = self.diff_function(*args, **kw) for l in lines: print l @@ -1149,7 +1149,7 @@ class TestCmd(object): prepended unless it is enclosed in a [list]. """ cmd = self.command_args(program, interpreter, arguments) - cmd_string = string.join(map(self.escape, cmd), ' ') + cmd_string = ' '.join(map(self.escape, cmd)) if self.verbose: sys.stderr.write(cmd_string + "\n") if universal_newlines is None: @@ -1314,7 +1314,7 @@ class TestCmd(object): if sub is None: continue if is_List(sub): - sub = apply(os.path.join, tuple(sub)) + sub = os.path.join(*tuple(sub)) new = os.path.join(self.workdir, sub) try: os.mkdir(new) @@ -1362,7 +1362,7 @@ class TestCmd(object): # letters is pretty much random on win32: drive,rest = os.path.splitdrive(path) if drive: - path = string.upper(drive) + rest + path = drive.upper() + rest # self._dirlist.append(path) @@ -1404,7 +1404,7 @@ class TestCmd(object): """Find an executable file. """ if is_List(file): - file = apply(os.path.join, tuple(file)) + file = os.path.join(*tuple(file)) if not os.path.isabs(file): file = where_is(file, path, pathext) return file @@ -1426,7 +1426,7 @@ class TestCmd(object): the temporary working directory name with the specified arguments using the os.path.join() method. """ - return apply(os.path.join, (self.workdir,) + tuple(args)) + return os.path.join(self.workdir, *tuple(args)) def readable(self, top, read=1): """Make the specified directory tree readable (read == 1) diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index 4aa7185..e9ae6a4 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -87,6 +87,7 @@ The TestCommon module also provides the following variables # PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, # AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __author__ = "Steven Knight " __revision__ = "TestCommon.py 0.37.D001 2010/01/11 16:55:50 knight" @@ -96,7 +97,6 @@ import copy import os import os.path import stat -import string import sys import types import UserList @@ -134,7 +134,7 @@ elif sys.platform == 'cygwin': lib_suffix = '.a' dll_prefix = '' dll_suffix = '.dll' -elif string.find(sys.platform, 'irix') != -1: +elif sys.platform.find('irix') != -1: exe_suffix = '' obj_suffix = '.o' shobj_suffix = '.o' @@ -143,7 +143,7 @@ elif string.find(sys.platform, 'irix') != -1: lib_suffix = '.a' dll_prefix = 'lib' dll_suffix = '.so' -elif string.find(sys.platform, 'darwin') != -1: +elif sys.platform.find('darwin') != -1: exe_suffix = '' obj_suffix = '.o' shobj_suffix = '.os' @@ -152,7 +152,7 @@ elif string.find(sys.platform, 'darwin') != -1: lib_suffix = '.a' dll_prefix = 'lib' dll_suffix = '.dylib' -elif string.find(sys.platform, 'sunos') != -1: +elif sys.platform.find('sunos') != -1: exe_suffix = '' obj_suffix = '.o' shobj_suffix = '.os' @@ -217,7 +217,7 @@ class TestCommon(TestCmd): calling the base class initialization, and then changing directory to the workdir. """ - apply(TestCmd.__init__, [self], kw) + TestCmd.__init__(self, **kw) os.chdir(self.workdir) def must_be_writable(self, *files): @@ -227,20 +227,20 @@ class TestCommon(TestCmd): them. Exits FAILED if any of the files does not exist or is not writable. """ - files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) + files = [is_List(x) and os.path.join(*x) or x for x in files] existing, missing = separate_files(files) - unwritable = filter(lambda x, iw=is_writable: not iw(x), existing) + unwritable = [x for x in existing if not is_writable(x)] if missing: - print "Missing files: `%s'" % string.join(missing, "', `") + print "Missing files: `%s'" % "', `".join(missing) if unwritable: - print "Unwritable files: `%s'" % string.join(unwritable, "', `") + print "Unwritable files: `%s'" % "', `".join(unwritable) self.fail_test(missing + unwritable) def must_contain(self, file, required, mode = 'rb'): """Ensures that the specified file contains the required text. """ file_contents = self.read(file, mode) - contains = (string.find(file_contents, required) != -1) + contains = (file_contents.find(required) != -1) if not contains: print "File `%s' does not contain required string." % file print self.banner('Required string ') @@ -261,7 +261,7 @@ class TestCommon(TestCmd): for lines in the output. """ if find is None: - find = lambda o, l: string.find(o, l) != -1 + find = lambda o, l: o.find(l) != -1 missing = [] for line in lines: if not find(output, line): @@ -289,7 +289,7 @@ class TestCommon(TestCmd): for lines in the output. """ if find is None: - find = lambda o, l: string.find(o, l) != -1 + find = lambda o, l: o.find(l) != -1 for line in lines: if find(output, line): return @@ -313,10 +313,10 @@ class TestCommon(TestCmd): pathname will be constructed by concatenating them. Exits FAILED if any of the files does not exist. """ - files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) - missing = filter(lambda x: not os.path.exists(x), files) + files = [is_List(x) and os.path.join(*x) or x for x in files] + missing = [x for x in files if not os.path.exists(x)] if missing: - print "Missing files: `%s'" % string.join(missing, "', `") + print "Missing files: `%s'" % "', `".join(missing) self.fail_test(missing) def must_match(self, file, expect, mode = 'rb'): @@ -339,7 +339,7 @@ class TestCommon(TestCmd): """Ensures that the specified file doesn't contain the banned text. """ file_contents = self.read(file, mode) - contains = (string.find(file_contents, banned) != -1) + contains = (file_contents.find(banned) != -1) if contains: print "File `%s' contains banned string." % file print self.banner('Banned string ') @@ -360,7 +360,7 @@ class TestCommon(TestCmd): for lines in the output. """ if find is None: - find = lambda o, l: string.find(o, l) != -1 + find = lambda o, l: o.find(l) != -1 unexpected = [] for line in lines: if find(output, line): @@ -385,10 +385,10 @@ class TestCommon(TestCmd): which case the pathname will be constructed by concatenating them. Exits FAILED if any of the files exists. """ - files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) - existing = filter(os.path.exists, files) + files = [is_List(x) and os.path.join(*x) or x for x in files] + existing = list(filter(os.path.exists, files)) if existing: - print "Unexpected files exist: `%s'" % string.join(existing, "', `") + print "Unexpected files exist: `%s'" % "', `".join(existing) self.fail_test(existing) @@ -399,13 +399,13 @@ class TestCommon(TestCmd): them. Exits FAILED if any of the files does not exist or is writable. """ - files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) + files = [is_List(x) and os.path.join(*x) or x for x in files] existing, missing = separate_files(files) - writable = filter(is_writable, existing) + writable = list(filter(is_writable, existing)) if missing: - print "Missing files: `%s'" % string.join(missing, "', `") + print "Missing files: `%s'" % "', `".join(missing) if writable: - print "Writable files: `%s'" % string.join(writable, "', `") + print "Writable files: `%s'" % "', `".join(writable) self.fail_test(missing + writable) def _complete(self, actual_stdout, expected_stdout, @@ -458,9 +458,8 @@ class TestCommon(TestCmd): else: arguments = options + " " + arguments try: - return apply(TestCmd.start, - (self, program, interpreter, arguments, universal_newlines), - kw) + return TestCmd.start(self, program, interpreter, arguments, universal_newlines, + **kw) except KeyboardInterrupt: raise except Exception, e: @@ -496,7 +495,7 @@ class TestCommon(TestCmd): command. A value of None means don't test exit status. """ - apply(TestCmd.finish, (self, popen,), kw) + TestCmd.finish(self, popen, **kw) match = kw.get('match', self.match) self._complete(self.stdout(), stdout, self.stderr(), stderr, status, match) @@ -538,7 +537,7 @@ class TestCommon(TestCmd): del kw['match'] except KeyError: match = self.match - apply(TestCmd.run, [self], kw) + TestCmd.run(self, **kw) self._complete(self.stdout(), stdout, self.stderr(), stderr, status, match) diff --git a/QMTest/TestRuntest.py b/QMTest/TestRuntest.py index 679a6ab..11f8ab2 100644 --- a/QMTest/TestRuntest.py +++ b/QMTest/TestRuntest.py @@ -19,7 +19,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path import re -import string import shutil import sys @@ -39,7 +38,7 @@ if re.search('\s', python): pythonstring = _python_ else: pythonstring = python -pythonstring = string.replace(pythonstring, '\\', '\\\\') +pythonstring = pythonstring.replace('\\', '\\\\') failing_test_template = """\ @@ -108,14 +107,14 @@ class TestRuntest(TestCommon): appears in a normal workspace. """ set_workpath_runtest = None - if not kw.has_key('program'): + if 'program' not in kw: kw['program'] = 'runtest.py' set_workpath_runtest = 1 - if not kw.has_key('interpreter'): + if 'interpreter' not in kw: kw['interpreter'] = [python, '-tt'] - if not kw.has_key('match'): + if 'match' not in kw: kw['match'] = match_exact - if not kw.has_key('workdir'): + if 'workdir' not in kw: kw['workdir'] = '' try: @@ -126,7 +125,7 @@ class TestRuntest(TestCommon): del kw['noqmtest'] orig_cwd = os.getcwd() - apply(TestCommon.__init__, [self], kw) + TestCommon.__init__(self, **kw) if not noqmtest: qmtest = self.where_is('qmtest') @@ -141,7 +140,7 @@ class TestRuntest(TestCommon): dirs = [os.environ.get('SCONS_RUNTEST_DIR', orig_cwd)] spe = os.environ.get('SCONS_SOURCE_PATH_EXECUTABLE', orig_cwd) - for d in string.split(spe, os.pathsep): + for d in spe.split(os.pathsep): dirs.append(os.path.join(d, 'build')) dirs.append(d) diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index 506f708..38f2c92 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -13,13 +13,13 @@ attributes defined in this subclass. """ # __COPYRIGHT__ +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import re import shutil -import string import sys import time @@ -30,7 +30,7 @@ except AttributeError: def zip(*lists): result = [] for i in xrange(len(lists[0])): - result.append(tuple(map(lambda l, i=i: l[i], lists))) + result.append(tuple([l[i] for l in lists])) return result __builtin__.zip = zip @@ -123,7 +123,7 @@ def gccFortranLibs(): stderr = p.stderr for l in stderr.readlines(): - list = string.split(l) + list = l.split() if len(list) > 3 and list[:2] == ['gcc', 'version']: if list[2][:3] in ('4.1','4.2','4.3'): libs = ['gfortranbegin'] @@ -148,7 +148,7 @@ if sys.platform == 'win32': fortran_lib = gccFortranLibs() elif sys.platform == 'cygwin': fortran_lib = gccFortranLibs() -elif string.find(sys.platform, 'irix') != -1: +elif sys.platform.find('irix') != -1: fortran_lib = ['ftn'] else: fortran_lib = gccFortranLibs() @@ -161,7 +161,7 @@ file_expr = r"""File "[^"]*", line \d+, in .+ # re.escape escapes too much. def re_escape(str): for c in ['.', '[', ']', '(', ')', '*', '+', '?']: # Not an exhaustive list. - str = string.replace(str, c, '\\' + c) + str = str.replace(c, '\\' + c) return str @@ -170,12 +170,12 @@ try: sys.version_info except AttributeError: # Pre-1.6 Python has no sys.version_info - version_string = string.split(sys.version)[0] - version_ints = map(int, string.split(version_string, '.')) + version_string = sys.version.split()[0] + version_ints = list(map(int, version_string.split('.'))) sys.version_info = tuple(version_ints + ['final', 0]) def python_version_string(): - return string.split(sys.version)[0] + return sys.version.split()[0] def python_minor_version_string(): return sys.version[:3] @@ -234,7 +234,7 @@ class TestSCons(TestCommon): pass else: os.chdir(script_dir) - if not kw.has_key('program'): + if 'program' not in kw: kw['program'] = os.environ.get('SCONS') if not kw['program']: if os.path.exists('scons'): @@ -243,11 +243,11 @@ class TestSCons(TestCommon): kw['program'] = 'scons.py' elif not os.path.isabs(kw['program']): kw['program'] = os.path.join(self.orig_cwd, kw['program']) - if not kw.has_key('interpreter') and not os.environ.get('SCONS_EXEC'): + if 'interpreter' not in kw and not os.environ.get('SCONS_EXEC'): kw['interpreter'] = [python, '-tt'] - if not kw.has_key('match'): + if 'match' not in kw: kw['match'] = match_exact - if not kw.has_key('workdir'): + if 'workdir' not in kw: kw['workdir'] = '' # Term causing test failures due to bogus readline init @@ -266,9 +266,9 @@ class TestSCons(TestCommon): else: sconsflags = [] sconsflags = sconsflags + ['--warn=no-python-version'] - os.environ['SCONSFLAGS'] = string.join(sconsflags) + os.environ['SCONSFLAGS'] = ' '.join(sconsflags) - apply(TestCommon.__init__, [self], kw) + TestCommon.__init__(self, **kw) import SCons.Node.FS if SCons.Node.FS.default_fs is None: @@ -284,7 +284,7 @@ class TestSCons(TestCommon): if not ENV is None: kw['ENV'] = ENV try: - return apply(SCons.Environment.Environment, args, kw) + return SCons.Environment.Environment(*args, **kw) except (SCons.Errors.UserError, SCons.Errors.InternalError): return None @@ -307,7 +307,7 @@ class TestSCons(TestCommon): return None result = env.WhereIs(prog) if norm and os.sep != '/': - result = string.replace(result, os.sep, '/') + result = result.replace(os.sep, '/') return result def detect_tool(self, tool, prog=None, ENV=None): @@ -376,16 +376,16 @@ class TestSCons(TestCommon): # support the --warn=no-visual-c-missing warning.) sconsflags = sconsflags + [os.environ.get('TESTSCONS_SCONSFLAGS', '--warn=no-visual-c-missing')] - os.environ['SCONSFLAGS'] = string.join(sconsflags) + os.environ['SCONSFLAGS'] = ' '.join(sconsflags) try: - result = apply(TestCommon.run, (self,)+args, kw) + result = TestCommon.run(self, *args, **kw) finally: sconsflags = save_sconsflags return result def up_to_date(self, options = None, arguments = None, read_str = "", **kw): s = "" - for arg in string.split(arguments): + for arg in arguments.split(): s = s + "scons: `%s' is up to date.\n" % arg if options: arguments = options + " " + arguments @@ -395,7 +395,7 @@ class TestSCons(TestCommon): # up-to-date output is okay. kw['stdout'] = re.escape(stdout) + '.*' kw['match'] = self.match_re_dotall - apply(self.run, [], kw) + self.run(**kw) def not_up_to_date(self, options = None, arguments = None, **kw): """Asserts that none of the targets listed in arguments is @@ -403,16 +403,16 @@ class TestSCons(TestCommon): This function is most useful in conjunction with the -n option. """ s = "" - for arg in string.split(arguments): + for arg in arguments.split(): s = s + "(?!scons: `%s' is up to date.)" % re.escape(arg) if options: arguments = options + " " + arguments s = '('+s+'[^\n]*\n)*' kw['arguments'] = arguments stdout = re.escape(self.wrap_stdout(build_str='ARGUMENTSGOHERE')) - kw['stdout'] = string.replace(stdout, 'ARGUMENTSGOHERE', s) + kw['stdout'] = stdout.replace('ARGUMENTSGOHERE', s) kw['match'] = self.match_re_dotall - apply(self.run, [], kw) + self.run(**kw) def option_not_yet_implemented(self, option, arguments=None, **kw): """ @@ -430,7 +430,7 @@ class TestSCons(TestCommon): kw['arguments'] = option + ' ' + arguments # TODO(1.5) #return self.run(**kw) - return apply(self.run, (), kw) + return self.run(**kw) def diff_substr(self, expect, actual, prelen=20, postlen=40): i = 0 @@ -461,9 +461,9 @@ class TestSCons(TestCommon): places, abstracting out the version difference. """ exec 'import traceback; x = traceback.format_stack()[-1]' - x = string.lstrip(x) - x = string.replace(x, '', file) - x = string.replace(x, 'line 1,', 'line %s,' % line) + x = x.lstrip() + x = x.replace('', file) + x = x.replace('line 1,', 'line %s,' % line) return x def normalize_pdf(self, s): @@ -486,12 +486,12 @@ class TestSCons(TestCommon): end_marker = 'endstream\nendobj' encoded = [] - b = string.find(s, begin_marker, 0) + b = s.find(begin_marker, 0) while b != -1: b = b + len(begin_marker) - e = string.find(s, end_marker, b) + e = s.find(end_marker, b) encoded.append((b, e)) - b = string.find(s, begin_marker, e + len(end_marker)) + b = s.find(begin_marker, e + len(end_marker)) x = 0 r = [] @@ -507,7 +507,7 @@ class TestSCons(TestCommon): r.append(d) x = e r.append(s[x:]) - s = string.join(r, '') + s = ''.join(r) return s @@ -553,7 +553,7 @@ class TestSCons(TestCommon): ] java_path = self.paths(patterns) + [env['ENV']['PATH']] - env['ENV']['PATH'] = string.join(java_path, os.pathsep) + env['ENV']['PATH'] = os.pathsep.join(java_path) return env['ENV'] def java_where_includes(self,version=None): @@ -634,7 +634,7 @@ class TestSCons(TestCommon): stderr=None, status=None) if version: - if string.find(self.stderr(), 'javac %s' % version) == -1: + if self.stderr().find('javac %s' % version) == -1: fmt = "Could not find javac for Java version %s, skipping test(s).\n" self.skip_test(fmt % version) else: @@ -673,7 +673,6 @@ class TestSCons(TestCommon): self.write([dir, 'bin', 'mymoc.py'], """\ import getopt import sys -import string import re # -w and -z are fake options used in test/QT/QTFLAGS.py cmd_opts, args = getopt.getopt(sys.argv[1:], 'io:wz', []) @@ -687,11 +686,11 @@ for opt, arg in cmd_opts: output.write("/* mymoc.py%s */\\n" % opt_string) for a in args: contents = open(a, 'rb').read() - a = string.replace(a, '\\\\', '\\\\\\\\') + a = a.replace('\\\\', '\\\\\\\\') subst = r'{ my_qt_symbol( "' + a + '\\\\n" ); }' if impl: contents = re.sub( r'#include.*', '', contents ) - output.write(string.replace(contents, 'Q_OBJECT', subst)) + output.write(contents.replace('Q_OBJECT', subst)) output.close() sys.exit(0) """) @@ -700,7 +699,6 @@ sys.exit(0) import os.path import re import sys -import string output_arg = 0 impl_arg = 0 impl = None @@ -773,7 +771,7 @@ else: def Qt_create_SConstruct(self, place): if type(place) is type([]): - place = apply(test.workpath, place) + place = test.workpath(*place) self.write(place, """\ if ARGUMENTS.get('noqtdir', 0): QTDIR=None else: QTDIR=r'%s' @@ -845,7 +843,7 @@ SConscript( sconscript ) lastEnd = 0 logfile = self.read(self.workpath(logfile)) if (doCheckLog and - string.find( logfile, "scons: warning: The stored build " + logfile.find( "scons: warning: The stored build " "information has an unexpected class." ) >= 0): self.fail_test() sconf_dir = sconf_dir @@ -957,7 +955,7 @@ print os.path.join(sys.prefix, 'lib', py_ver, 'config') print py_ver """) - return [python] + string.split(string.strip(self.stdout()), '\n') + return [python] + self.stdout().strip().split('\n') def start(self, *args, **kw): """ @@ -967,9 +965,9 @@ print py_ver use standard input without forcing every .start() call in the individual tests to do so explicitly. """ - if not kw.has_key('stdin'): + if 'stdin' not in kw: kw['stdin'] = True - return apply(TestCommon.start, (self,) + args, kw) + return TestCommon.start(self, *args, **kw) def wait_for(self, fname, timeout=10.0, popen=None): """ @@ -1058,12 +1056,12 @@ class TimeSCons(TestSCons): self.calibrate = os.environ.get('TIMESCONS_CALIBRATE', '0') != '0' - if not kw.has_key('verbose') and not self.calibrate: + if 'verbose' not in kw and not self.calibrate: kw['verbose'] = True # TODO(1.5) #TestSCons.__init__(self, *args, **kw) - apply(TestSCons.__init__, (self,)+args, kw) + TestSCons.__init__(self, *args, **kw) # TODO(sgk): better way to get the script dir than sys.argv[0] test_dir = os.path.dirname(sys.argv[0]) @@ -1090,7 +1088,7 @@ class TimeSCons(TestSCons): The elapsed time to execute each build is printed after it has finished. """ - if not kw.has_key('options') and self.variables: + if 'options' not in kw and self.variables: options = [] for variable, value in self.variables.items(): options.append('%s=%s' % (variable, value)) @@ -1098,16 +1096,16 @@ class TimeSCons(TestSCons): if self.calibrate: # TODO(1.5) #self.calibration(*args, **kw) - apply(self.calibration, args, kw) + self.calibration(*args, **kw) else: self.uptime() # TODO(1.5) #self.startup(*args, **kw) #self.full(*args, **kw) #self.null(*args, **kw) - apply(self.startup, args, kw) - apply(self.full, args, kw) - apply(self.null, args, kw) + self.startup(*args, **kw) + self.full(*args, **kw) + self.null(*args, **kw) def trace(self, graph, name, value, units, sort=None): fmt = "TRACE: graph=%s name=%s value=%s units=%s" @@ -1127,7 +1125,7 @@ class TimeSCons(TestSCons): for name, args in stats.items(): # TODO(1.5) #self.trace(name, trace, *args) - apply(self.trace, (name, trace), args) + self.trace(name, trace, **args) def uptime(self): try: @@ -1168,7 +1166,7 @@ class TimeSCons(TestSCons): kw['status'] = None # TODO(1.5) #self.run(*args, **kw) - apply(self.run, args, kw) + self.run(*args, **kw) sys.stdout.write(self.stdout()) stats = self.collect_stats(self.stdout()) # Delete the time-commands, since no commands are ever @@ -1182,7 +1180,7 @@ class TimeSCons(TestSCons): """ # TODO(1.5) #self.run(*args, **kw) - apply(self.run, args, kw) + self.run(*args, **kw) sys.stdout.write(self.stdout()) stats = self.collect_stats(self.stdout()) self.report_traces('full', stats) @@ -1190,9 +1188,9 @@ class TimeSCons(TestSCons): #self.trace('full-memory', 'initial', **stats['memory-initial']) #self.trace('full-memory', 'prebuild', **stats['memory-prebuild']) #self.trace('full-memory', 'final', **stats['memory-final']) - apply(self.trace, ('full-memory', 'initial'), stats['memory-initial']) - apply(self.trace, ('full-memory', 'prebuild'), stats['memory-prebuild']) - apply(self.trace, ('full-memory', 'final'), stats['memory-final']) + self.trace('full-memory', 'initial', **stats['memory-initial']) + self.trace('full-memory', 'prebuild', **stats['memory-prebuild']) + self.trace('full-memory', 'final', **stats['memory-final']) def calibration(self, *args, **kw): """ @@ -1202,7 +1200,7 @@ class TimeSCons(TestSCons): """ # TODO(1.5) #self.run(*args, **kw) - apply(self.run, args, kw) + self.run(*args, **kw) if self.variables: for variable, value in self.variables.items(): sys.stdout.write('VARIABLE: %s=%s\n' % (variable, value)) @@ -1218,7 +1216,7 @@ class TimeSCons(TestSCons): #self.up_to_date(arguments='.', **kw) kw = kw.copy() kw['arguments'] = '.' - apply(self.up_to_date, (), kw) + self.up_to_date(**kw) sys.stdout.write(self.stdout()) stats = self.collect_stats(self.stdout()) # time-commands should always be 0.0 on a null build, because @@ -1233,9 +1231,9 @@ class TimeSCons(TestSCons): #self.trace('null-memory', 'initial', **stats['memory-initial']) #self.trace('null-memory', 'prebuild', **stats['memory-prebuild']) #self.trace('null-memory', 'final', **stats['memory-final']) - apply(self.trace, ('null-memory', 'initial'), stats['memory-initial']) - apply(self.trace, ('null-memory', 'prebuild'), stats['memory-prebuild']) - apply(self.trace, ('null-memory', 'final'), stats['memory-final']) + self.trace('null-memory', 'initial', **stats['memory-initial']) + self.trace('null-memory', 'prebuild', **stats['memory-prebuild']) + self.trace('null-memory', 'final', **stats['memory-final']) def elapsed_time(self): """ @@ -1257,7 +1255,7 @@ class TimeSCons(TestSCons): try: # TODO(1.5) #result = TestSCons.run(self, *args, **kw) - result = apply(TestSCons.run, (self,)+args, kw) + result = TestSCons.run(self, *args, **kw) finally: self.endTime = time.time() return result @@ -1278,8 +1276,8 @@ class TimeSCons(TestSCons): #dirs = [ d for d in dirs if not d.startswith('TimeSCons-') ] #files = [ f for f in files if not f.startswith('TimeSCons-') ] not_timescons_entries = lambda s: not s.startswith('TimeSCons-') - dirs = filter(not_timescons_entries, dirs) - files = filter(not_timescons_entries, files) + dirs = list(filter(not_timescons_entries, dirs)) + files = list(filter(not_timescons_entries, files)) for dirname in dirs: source = os.path.join(root, dirname) destination = source.replace(source_dir, dest_dir) diff --git a/QMTest/TestSConsMSVS.py b/QMTest/TestSConsMSVS.py index 0f6fc6f..ac10cd3 100644 --- a/QMTest/TestSConsMSVS.py +++ b/QMTest/TestSConsMSVS.py @@ -18,7 +18,6 @@ in this subclass. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os -import string import sys from TestSCons import * @@ -596,7 +595,7 @@ print "self._msvs_versions =", str(SCons.Tool.MSCommon.query_versions()) replace = 'sys.path = [ %s, join(sys' % enginepath contents = self.read(fname) - contents = string.replace(contents, orig, replace) + contents = contents.replace(orig, replace) self.write(fname, contents) def msvs_substitute(self, input, msvs_ver, @@ -620,18 +619,18 @@ print "self._msvs_versions =", str(SCons.Tool.MSCommon.query_versions()) if project_guid is None: project_guid = "{E5466E26-0003-F18B-8F8A-BCD76C86388D}" - if os.environ.has_key('SCONS_LIB_DIR'): + if 'SCONS_LIB_DIR' in os.environ: exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % os.environ['SCONS_LIB_DIR'] else: exec_script_main = "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-%s'), join(sys.prefix, 'scons-%s'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()" % (self.scons_version, self.scons_version) - exec_script_main_xml = string.replace(exec_script_main, "'", "'") - - result = string.replace(input, r'', workpath) - result = string.replace(result, r'', python) - result = string.replace(result, r'', sconscript) - result = string.replace(result, r'', exec_script_main) - result = string.replace(result, r'', exec_script_main_xml) - result = string.replace(result, r'', project_guid) + exec_script_main_xml = exec_script_main.replace("'", "'") + + result = input.replace(r'', workpath) + result = result.replace(r'', python) + result = result.replace(r'', sconscript) + result = result.replace(r'', exec_script_main) + result = result.replace(r'', exec_script_main_xml) + result = result.replace(r'', project_guid) return result def get_msvs_executable(self, version): @@ -655,9 +654,9 @@ print "self._msvs_versions =", str(SCons.Tool.MSCommon.query_versions()) else: sconsflags = [] sconsflags = sconsflags + ['--warn=no-deprecated'] - os.environ['SCONSFLAGS'] = string.join(sconsflags) + os.environ['SCONSFLAGS'] = ' '.join(sconsflags) try: - result = apply(TestSCons.run, (self,)+args, kw) + result = TestSCons.run(self, *args, **kw) finally: os.environ['SCONSFLAGS'] = save_sconsflags or '' return result diff --git a/QMTest/TestSCons_time.py b/QMTest/TestSCons_time.py index f9a639e..e846ab5 100644 --- a/QMTest/TestSCons_time.py +++ b/QMTest/TestSCons_time.py @@ -17,7 +17,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import sys from TestCommon import * @@ -168,7 +167,7 @@ class TestSCons_time(TestCommon): pass else: os.chdir(script_dir) - if not kw.has_key('program'): + if 'program' not in kw: p = os.environ.get('SCONS_TIME') if not p: p = 'scons-time' @@ -176,16 +175,16 @@ class TestSCons_time(TestCommon): p = 'scons-time.py' kw['program'] = p - if not kw.has_key('interpreter'): + if 'interpreter' not in kw: kw['interpreter'] = [python, '-tt'] - if not kw.has_key('match'): + if 'match' not in kw: kw['match'] = match_exact - if not kw.has_key('workdir'): + if 'workdir' not in kw: kw['workdir'] = '' - apply(TestCommon.__init__, [self], kw) + TestCommon.__init__(self, **kw) # Now that the testing object has been set up, check if we should # skip the test due to the Python version. We need to be able to @@ -196,14 +195,14 @@ class TestSCons_time(TestCommon): try: import __future__ except ImportError: - version = string.split(sys.version)[0] + version = sys.version.split()[0] msg = 'scons-time does not work on Python version %s\n' % version self.skip_test(msg) try: eval('[x for x in [1, 2]]') except SyntaxError: - version = string.split(sys.version)[0] + version = sys.version.split()[0] msg = 'scons-time does not work on Python version %s\n' % version self.skip_test(msg) @@ -247,9 +246,9 @@ class TestSCons_time(TestCommon): tempdir = realpath(tempdir) args = (tempdir, 'scons-time-',) + args - x = apply(os.path.join, args) + x = os.path.join(*args) x = re.escape(x) - x = string.replace(x, 'time\\-', 'time\\-[^%s]*' % sep) + x = x.replace('time\\-', 'time\\-[^%s]*' % sep) return x def write_fake_aegis_py(self, name): diff --git a/QMTest/TestSConsign.py b/QMTest/TestSConsign.py index 29d8b2c..700c242 100644 --- a/QMTest/TestSConsign.py +++ b/QMTest/TestSConsign.py @@ -19,7 +19,6 @@ in this subclass. import os import os.path -import string import sys from TestSCons import * @@ -48,13 +47,13 @@ class TestSConsign(TestSCons): os.chdir(script_dir) self.script_dir = os.getcwd() - apply(TestSCons.__init__, (self,)+args, kw) + TestSCons.__init__(self, *args, **kw) self.my_kw = { 'interpreter' : python, # imported from TestSCons } - if not kw.has_key('program'): + if 'program' not in kw: kw['program'] = os.environ.get('SCONS') if not kw['program']: if os.path.exists('scons'): @@ -81,7 +80,7 @@ class TestSConsign(TestSCons): def run_sconsign(self, *args, **kw): kw.update(self.my_kw) - return apply(self.run, args, kw) + return self.run(*args, **kw) # Local Variables: # tab-width:4 diff --git a/QMTest/scons_tdb.py b/QMTest/scons_tdb.py index b725d3f..73e8430 100644 --- a/QMTest/scons_tdb.py +++ b/QMTest/scons_tdb.py @@ -22,13 +22,14 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - """ QMTest classes to support SCons' testing and Aegis-inspired workflow. Thanks to Stefan Seefeld for the initial code. """ +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" ######################################################################## # Imports @@ -96,7 +97,7 @@ def get_explicit_arguments(e): # Do not record computed fields. if field.IsComputed(): continue - if e.__dict__.has_key(name): + if name in e.__dict__: explicit_arguments[name] = e.__dict__[name] return explicit_arguments @@ -153,10 +154,10 @@ sys_attributes = [ def get_sys_values(): sys_attributes.sort() - result = map(lambda k: (k, getattr(sys, k, _null)), sys_attributes) - result = filter(lambda t: not t[1] is _null, result) - result = map(lambda t: t[0] + '=' + repr(t[1]), result) - return string.join(result, '\n ') + result = [(k, getattr(sys, k, _null)) for k in sys_attributes] + result = [t for t in result if not t[1] is _null] + result = [t[0] + '=' + repr(t[1]) for t in result] + return '\n '.join(result) module_attributes = [ '__version__', @@ -168,10 +169,10 @@ module_attributes = [ def get_module_info(module): module_attributes.sort() - result = map(lambda k: (k, getattr(module, k, _null)), module_attributes) - result = filter(lambda t: not t[1] is _null, result) - result = map(lambda t: t[0] + '=' + repr(t[1]), result) - return string.join(result, '\n ') + result = [(k, getattr(module, k, _null)) for k in module_attributes] + result = [t for t in result if not t[1] is _null] + result = [t[0] + '=' + repr(t[1]) for t in result] + return '\n '.join(result) environ_keys = [ 'PATH', @@ -214,10 +215,10 @@ environ_keys = [ def get_environment(): environ_keys.sort() - result = map(lambda k: (k, os.environ.get(k, _null)), environ_keys) - result = filter(lambda t: not t[1] is _null, result) - result = map(lambda t: t[0] + '-' + t[1], result) - return string.join(result, '\n ') + result = [(k, os.environ.get(k, _null)) for k in environ_keys] + result = [t for t in result if not t[1] is _null] + result = [t[0] + '-' + t[1] for t in result] + return '\n '.join(result) class SConsXMLResultStream(XMLResultStream): def __init__(self, *args, **kw): @@ -400,7 +401,7 @@ class AegisBatchStream(FileResultStream): file_names.sort() for file_name in file_names: exit_status = self._outcomes[file_name] - file_name = string.replace(file_name, '\\', '/') + file_name = file_name.replace('\\', '/') self.file.write(' { file_name = "%s";\n' % file_name) self.file.write(' exit_status = %s; },\n' % exit_status) self.file.write('];\n') diff --git a/QMTest/unittest.py b/QMTest/unittest.py index c74a4c7..e5a8668 100644 --- a/QMTest/unittest.py +++ b/QMTest/unittest.py @@ -28,6 +28,7 @@ PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. """ +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __author__ = "Steve Purcell (stephen_purcell@yahoo.com)" __version__ = "$ Revision: 1.23 $"[11:-2] @@ -35,15 +36,14 @@ __version__ = "$ Revision: 1.23 $"[11:-2] import time import sys import traceback -import string import os ############################################################################## # A platform-specific concession to help the code work for JPython users ############################################################################## -plat = string.lower(sys.platform) -_isJPython = string.find(plat, 'java') >= 0 or string.find(plat, 'jdk') >= 0 +plat = sys.platform.lower() +_isJPython = plat.find('java') >= 0 or plat.find('jdk') >= 0 del plat @@ -149,7 +149,7 @@ class TestCase: the specified test method's docstring. """ doc = self.__testMethod.__doc__ - return doc and string.strip(string.split(doc, "\n")[0]) or None + return doc and doc.split("\n")[0].strip() or None def id(self): return "%s.%s" % (self.__class__, self.__testMethod.__name__) @@ -205,7 +205,7 @@ class TestCase: def failIf(self, expr, msg=None): "Fail the test if the expression is true." - apply(self.assert_,(not expr,msg)) + self.assert_(not expr,msg) def assertRaises(self, excClass, callableObj, *args, **kwargs): """Assert that an exception of class excClass is thrown @@ -216,7 +216,7 @@ class TestCase: unexpected exception. """ try: - apply(callableObj, args, kwargs) + callableObj(*args, **kwargs) except excClass: return else: @@ -326,7 +326,7 @@ class FunctionTestCase(TestCase): def shortDescription(self): if self.__description is not None: return self.__description doc = self.__testFunc.__doc__ - return doc and string.strip(string.split(doc, "\n")[0]) or None + return doc and doc.split("\n")[0].strip() or None @@ -339,8 +339,7 @@ def getTestCaseNames(testCaseClass, prefix, sortUsing=cmp): and its base classes that start with the given prefix. This is used by makeSuite(). """ - testFnNames = filter(lambda n,p=prefix: n[:len(p)] == p, - dir(testCaseClass)) + testFnNames = [n for n in dir(testCaseClass) if n[:len(prefix)] == prefix] for baseclass in testCaseClass.__bases__: testFnNames = testFnNames + \ getTestCaseNames(baseclass, prefix, sortUsing=None) @@ -355,8 +354,8 @@ def makeSuite(testCaseClass, prefix='test', sortUsing=cmp): prefix. The cases are sorted by their function names using the supplied comparison function, which defaults to 'cmp'. """ - cases = map(testCaseClass, - getTestCaseNames(testCaseClass, prefix, sortUsing)) + cases = list(map(testCaseClass, + getTestCaseNames(testCaseClass, prefix, sortUsing))) return TestSuite(cases) @@ -376,18 +375,18 @@ def createTestInstance(name, module=None): -- returns result of calling makeSuite(ListTestCase, prefix="check") """ - spec = string.split(name, ':') + spec = name.split(':') if len(spec) > 2: raise ValueError, "illegal test name: %s" % name if len(spec) == 1: testName = spec[0] caseName = None else: testName, caseName = spec - parts = string.split(testName, '.') + parts = testName.split('.') if module is None: if len(parts) < 2: raise ValueError, "incomplete test name: %s" % name - constructor = __import__(string.join(parts[:-1],'.')) + constructor = __import__('.'.join(parts[:-1])) parts = parts[1:] else: constructor = module @@ -429,7 +428,7 @@ class _WritelnDecorator: return getattr(self.stream,attr) def writeln(self, *args): - if args: apply(self.write, args) + if args: self.write(*args) self.write(self.linesep) @@ -468,7 +467,7 @@ class _JUnitTextTestResult(TestResult): (len(errors), errFlavour)) i = 1 for test,error in errors: - errString = string.join(apply(traceback.format_exception,error),"") + errString = "".join(traceback.format_exception(*error)) self.stream.writeln("%i) %s" % (i, test)) self.stream.writeln(errString) i = i + 1 @@ -567,8 +566,8 @@ class _VerboseTextTestResult(TestResult): self.stream.writeln(separator1) self.stream.writeln("\t%s" % flavour) self.stream.writeln(separator2) - for line in apply(traceback.format_exception, err): - for l in string.split(line,"\n")[:-1]: + for line in traceback.format_exception(*err): + for l in line.split("\n")[:-1]: self.stream.writeln("\t%s" % l) self.stream.writeln(separator1) @@ -597,9 +596,10 @@ class VerboseTextTestRunner: self.stream.writeln() if not result.wasSuccessful(): self.stream.write("FAILED (") - failed, errored = map(len, (result.failures, result.errors)) + failed = len(result.failures) if failed: self.stream.write("failures=%d" % failed) + errored = len(result.errors) if errored: if failed: self.stream.write(", ") self.stream.write("errors=%d" % errored) @@ -635,7 +635,7 @@ Examples: argv=None, testRunner=None): if type(module) == type(''): self.module = __import__(module) - for part in string.split(module,'.')[1:]: + for part in module.split('.')[1:]: self.module = getattr(self.module, part) else: self.module = module diff --git a/SConstruct b/SConstruct index dc2036b..b90ae5a 100644 --- a/SConstruct +++ b/SConstruct @@ -3,6 +3,7 @@ # # See the README file for an overview of how SCons is built and tested. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS # When this gets changed, you must also change the copyright_years string # in QMTest/TestSCons.py so the test scripts look for the right string. @@ -40,7 +41,6 @@ import os import os.path import re import stat -import string import sys import tempfile @@ -60,7 +60,7 @@ def whereis(file): exts = [''] if platform == "win32": exts += ['.exe'] - for dir in string.split(os.environ['PATH'], os.pathsep): + for dir in os.environ['PATH'].split(os.pathsep): f = os.path.join(dir, file) for ext in exts: f_ext = f + ext @@ -106,7 +106,7 @@ if not developer: build_system = ARGUMENTS.get('BUILD_SYSTEM') if not build_system: import socket - build_system = string.split(socket.gethostname(), '.')[0] + build_system = socket.gethostname().split('.')[0] version = ARGUMENTS.get('VERSION', '') if not version: @@ -137,7 +137,7 @@ if not revision and hg: revision = b.group(1) + ':' + revision def generate_build_id(revision): result = revision - if filter(lambda l: l[0] in 'AMR!', hg_status_lines): + if [l for l in hg_status_lines if l[0] in 'AMR!']: result = result + '[MODIFIED]' return result @@ -148,7 +148,7 @@ if not revision and svn: revision = m.group(1) def generate_build_id(revision): result = 'r' + revision - if filter(lambda l: l[0] in 'ACDMR', svn_status_lines): + if [l for l in svn_status_lines if l[0] in 'ACDMR']: result = result + '[MODIFIED]' return result @@ -175,7 +175,7 @@ python_ver = sys.version[0:3] ENV = { 'PATH' : os.environ['PATH'] } for key in ['LOGNAME', 'PYTHONPATH', 'LD_LIBRARY_PATH']: - if os.environ.has_key(key): + if key in os.environ: ENV[key] = os.environ[key] build_dir = ARGUMENTS.get('BUILDDIR', 'build') @@ -365,16 +365,16 @@ def SCons_revision(target, source, env): # Note: We construct the __*__ substitution strings here # so that they don't get replaced when this file gets # copied into the tree for packaging. - contents = string.replace(contents, '__BUILD' + '__', env['BUILD']) - contents = string.replace(contents, '__BUILDSYS' + '__', env['BUILDSYS']) - contents = string.replace(contents, '__COPYRIGHT' + '__', env['COPYRIGHT']) - contents = string.replace(contents, '__DATE' + '__', env['DATE']) - contents = string.replace(contents, '__DEVELOPER' + '__', env['DEVELOPER']) - contents = string.replace(contents, '__FILE' + '__', str(source[0])) - contents = string.replace(contents, '__MONTH_YEAR'+ '__', env['MONTH_YEAR']) - contents = string.replace(contents, '__REVISION' + '__', env['REVISION']) - contents = string.replace(contents, '__VERSION' + '__', env['VERSION']) - contents = string.replace(contents, '__NULL' + '__', '') + contents = contents.replace('__BUILD' + '__', env['BUILD']) + contents = contents.replace('__BUILDSYS' + '__', env['BUILDSYS']) + contents = contents.replace('__COPYRIGHT' + '__', env['COPYRIGHT']) + contents = contents.replace('__DATE' + '__', env['DATE']) + contents = contents.replace('__DEVELOPER' + '__', env['DEVELOPER']) + contents = contents.replace('__FILE' + '__', str(source[0])) + contents = contents.replace('__MONTH_YEAR'+ '__', env['MONTH_YEAR']) + contents = contents.replace('__REVISION' + '__', env['REVISION']) + contents = contents.replace('__VERSION' + '__', env['VERSION']) + contents = contents.replace('__NULL' + '__', '') open(t, 'wb').write(contents) os.chmod(t, os.stat(s)[0]) @@ -708,7 +708,7 @@ for p in [ scons ]: pkg_version = "%s-%s" % (pkg, version) src = 'src' - if p.has_key('src_subdir'): + if 'src_subdir' in p: src = os.path.join(src, p['src_subdir']) build = os.path.join(build_dir, pkg) @@ -747,15 +747,14 @@ for p in [ scons ]: # destination files. # manifest_in = File(os.path.join(src, 'MANIFEST.in')).rstr() - src_files = map(lambda x: x[:-1], - open(manifest_in).readlines()) + src_files = [x[:-1] for x in open(manifest_in).readlines()] raw_files = src_files[:] dst_files = src_files[:] rpm_files = [] MANIFEST_in_list = [] - if p.has_key('subpkgs'): + if 'subpkgs' in p: # # This package includes some sub-packages. Read up their # MANIFEST.in files, and add them to our source and destination @@ -767,9 +766,9 @@ for p in [ scons ]: isubdir = p['subinst_dirs'][sp['pkg']] MANIFEST_in = File(os.path.join(src, ssubdir, 'MANIFEST.in')).rstr() MANIFEST_in_list.append(MANIFEST_in) - files = map(lambda x: x[:-1], open(MANIFEST_in).readlines()) + files = [x[:-1] for x in open(MANIFEST_in).readlines()] raw_files.extend(files) - src_files.extend(map(lambda x, s=ssubdir: os.path.join(s, x), files)) + src_files.extend([os.path.join(subdir, x) for x in files]) for f in files: r = os.path.join(sp['rpm_dir'], f) rpm_files.append(r) @@ -778,7 +777,7 @@ for p in [ scons ]: for f in sp.get('extra_rpm_files', []): r = os.path.join(sp['rpm_dir'], f) rpm_files.append(r) - files = map(lambda x, i=isubdir: os.path.join(i, x), files) + files = [os.path.join(isubdir, x) for x in files] dst_files.extend(files) for k, f in sp['filemap'].items(): if f: @@ -832,8 +831,8 @@ for p in [ scons ]: # # Now go through and arrange to create whatever packages we can. # - build_src_files = map(lambda x, b=build: os.path.join(b, x), src_files) - apply(Local, build_src_files, {}) + build_src_files = [os.path.join(build, x) for x in src_files] + Local(*build_src_files) distutils_formats = [] @@ -870,9 +869,8 @@ for p in [ scons ]: # but that gives heartburn to Cygwin's tar, so work around it # with separate zcat-tar-rm commands. # - unpack_tar_gz_files = map(lambda x, u=unpack_tar_gz_dir, pv=pkg_version: - os.path.join(u, pv, x), - src_files) + unpack_tar_gz_files = [os.path.join(unpack_tar_gz_dir, pkg_version, x) + for x in src_files] env.Command(unpack_tar_gz_files, dist_tar_gz, [ Delete(os.path.join(unpack_tar_gz_dir, pkg_version)), "$ZCAT $SOURCES > .temp", @@ -893,7 +891,7 @@ for p in [ scons ]: # like this because we put a preamble in it that will chdir() # to the directory in which setup.py exists. # - dfiles = map(lambda x, d=test_tar_gz_dir: os.path.join(d, x), dst_files) + dfiles = [os.path.join(test_tar_gz_dir, x) for x in dst_files] env.Command(dfiles, unpack_tar_gz_files, [ Delete(os.path.join(unpack_tar_gz_dir, pkg_version, 'build')), Delete("$TEST_TAR_GZ_DIR"), @@ -910,21 +908,9 @@ for p in [ scons ]: env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision) def Digestify(target, source, env): import md5 - def hexdigest(s): - """Return a signature as a string of hex characters. - """ - # NOTE: This routine is a method in the Python 2.0 interface - # of the native md5 module, but we want SCons to operate all - # the way back to at least Python 1.5.2, which doesn't have it. - h = string.hexdigits - r = '' - for c in s: - i = ord(c) - r = r + h[(i >> 4) & 0xF] + h[i & 0xF] - return r src = source[0].rfile() contents = open(str(src)).read() - sig = hexdigest(md5.new(contents).digest()) + sig = md5.new(contents).hexdigest() bytes = os.stat(str(src))[6] open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig, src.name, @@ -951,9 +937,8 @@ for p in [ scons ]: # Unpack the zip archive created by the distutils into # build/unpack-zip/scons-{version}. # - unpack_zip_files = map(lambda x, u=unpack_zip_dir, pv=pkg_version: - os.path.join(u, pv, x), - src_files) + unpack_zip_files = [os.path.join(unpack_zip_dir, pkg_version, x) + for x in src_files] env.Command(unpack_zip_files, dist_zip, [ Delete(os.path.join(unpack_zip_dir, pkg_version)), @@ -973,7 +958,7 @@ for p in [ scons ]: # like this because we put a preamble in it that will chdir() # to the directory in which setup.py exists. # - dfiles = map(lambda x, d=test_zip_dir: os.path.join(d, x), dst_files) + dfiles = [os.path.join(test_zip_dir, x) for x in dst_files] env.Command(dfiles, unpack_zip_files, [ Delete(os.path.join(unpack_zip_dir, pkg_version, 'build')), Delete("$TEST_ZIP_DIR"), @@ -1010,12 +995,12 @@ for p in [ scons ]: maintain multiple lists. """ c = open(str(source[0]), 'rb').read() - c = string.replace(c, '__VERSION' + '__', env['VERSION']) - c = string.replace(c, '__RPM_FILES' + '__', env['RPM_FILES']) + c = c.replace('__VERSION' + '__', env['VERSION']) + c = c.replace('__RPM_FILES' + '__', env['RPM_FILES']) open(str(target[0]), 'wb').write(c) rpm_files.sort() - rpm_files_str = string.join(rpm_files, "\n") + "\n" + rpm_files_str = "\n".join(rpm_files) + "\n" rpm_spec_env = env.Clone(RPM_FILES = rpm_files_str) rpm_spec_action = Action(spec_function, varlist=['RPM_FILES']) rpm_spec_env.Command(specfile, specfile_in, rpm_spec_action) @@ -1036,8 +1021,7 @@ for p in [ scons ]: AddPostAction(dist_noarch_rpm, Chmod(dist_noarch_rpm, 0644)) AddPostAction(dist_src_rpm, Chmod(dist_src_rpm, 0644)) - dfiles = map(lambda x, d=test_rpm_dir: os.path.join(d, 'usr', x), - dst_files) + dfiles = [os.path.join(test_rpm_dir, 'usr', x) for x in dst_files] env.Command(dfiles, dist_noarch_rpm, "$RPM2CPIO $SOURCES | (cd $TEST_RPM_DIR && cpio -id)") @@ -1060,8 +1044,7 @@ for p in [ scons ]: if s[:len(old)] == old: s = new + s[len(old):] return os.path.join('usr', s) - dfiles = map(lambda x, t=test_deb_dir: os.path.join(t, x), - map(xxx, dst_files)) + dfiles = [os.path.join(test_deb_dir, xxx(x)) for x in dst_files] env.Command(dfiles, deb, "dpkg --fsys-tarfile $SOURCES | (cd $TEST_DEB_DIR && tar -xf -)") @@ -1084,7 +1067,7 @@ for p in [ scons ]: commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_dumb -f %s" % format) commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY sdist --formats=%s" % \ - string.join(distutils_formats, ',')) + ','.join(distutils_formats)) commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_wininst") @@ -1117,11 +1100,11 @@ for p in [ scons ]: local_script = os.path.join(build_dir_local, script) commands.append(Move(local_script + '.py', local_script)) - rf = filter(lambda x: not x in scripts, raw_files) - rf = map(lambda x, slv=s_l_v: os.path.join(slv, x), rf) + rf = [x for x in raw_files if not x in scripts] + rf = [os.path.join(s_l_v, x) for x in rf] for script in scripts: rf.append("%s.py" % script) - local_targets = map(lambda x, s=build_dir_local: os.path.join(s, x), rf) + local_targets = [os.path.join(build_dir_local, x) for x in rf] env.Command(local_targets, build_src_files, commands) @@ -1140,9 +1123,7 @@ for p in [ scons ]: local_targets, "cd %s && tar czf $( ${TARGET.abspath} $) *" % build_dir_local) - unpack_targets = map(lambda x, d=test_local_tar_gz_dir: - os.path.join(d, x), - rf) + unpack_targets = [os.path.join(test_local_tar_gz_dir, x) for x in rf] commands = [Delete(test_local_tar_gz_dir), Mkdir(test_local_tar_gz_dir), "cd %s && tar xzf $( ${SOURCE.abspath} $)" % test_local_tar_gz_dir] @@ -1153,9 +1134,7 @@ for p in [ scons ]: env.Command(dist_local_zip, local_targets, zipit, CD = build_dir_local, PSV = '.') - unpack_targets = map(lambda x, d=test_local_zip_dir: - os.path.join(d, x), - rf) + unpack_targets = [os.path.join(test_local_zip_dir, x) for x in rf] commands = [Delete(test_local_zip_dir), Mkdir(test_local_zip_dir), unzipit] @@ -1208,12 +1187,12 @@ SConscript('doc/SConscript') sfiles = None if hg_status_lines: - slines = filter(lambda l: l[0] in 'ACM', hg_status_lines) - sfiles = map(lambda l: l.split()[-1], slines) + slines = [l for l in hg_status_lines if l[0] in 'ACM'] + sfiles = [l.split()[-1] for l in slines] elif svn_status_lines: - slines = filter(lambda l: l[0] in ' MA', svn_status_lines) - sentries = map(lambda l: l.split()[-1], slines) - sfiles = filter(os.path.isfile, sentries) + slines = [l for l in svn_status_lines if l[0] in ' MA'] + sentries = [l.split()[-1] for l in slines] + sfiles = list(filter(os.path.isfile, sentries)) else: "Not building in a Mercurial or Subversion tree; skipping building src package." @@ -1228,7 +1207,7 @@ if sfiles: ] for p in remove_patterns: - sfiles = filter(lambda s, p=p: not fnmatch.fnmatch(s, p), sfiles) + sfiles = [s for s in sfiles if not fnmatch.fnmatch(s, p)] if sfiles: ps = "%s-src" % project @@ -1245,7 +1224,7 @@ if sfiles: for file in sfiles: env.SCons_revision(os.path.join(b_ps, file), file) - b_ps_files = map(lambda x, d=b_ps: os.path.join(d, x), sfiles) + b_ps_files = [os.path.join(b_ps, x) for x in sfiles] cmds = [ Delete(b_psv), Copy(b_psv, b_ps), @@ -1254,7 +1233,7 @@ if sfiles: env.Command(b_psv_stamp, src_deps + b_ps_files, cmds) - apply(Local, b_ps_files, {}) + Local(*b_ps_files) if gzip: @@ -1264,9 +1243,8 @@ if sfiles: # # Unpack the archive into build/unpack/scons-{version}. # - unpack_tar_gz_files = map(lambda x, u=unpack_tar_gz_dir, psv=psv: - os.path.join(u, psv, x), - sfiles) + unpack_tar_gz_files = [os.path.join(unpack_tar_gz_dir, psv, x) + for x in sfiles] # # We'd like to replace the last three lines with the following: @@ -1295,8 +1273,7 @@ if sfiles: # like this because we put a preamble in it that will chdir() # to the directory in which setup.py exists. # - dfiles = map(lambda x, d=test_src_tar_gz_dir: os.path.join(d, x), - dst_files) + dfiles = [os.path.join(test_src_tar_gz_dir, x) for x in dst_files] scons_lib_dir = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine') ENV = env.Dictionary('ENV').copy() ENV['SCONS_LIB_DIR'] = scons_lib_dir @@ -1329,9 +1306,8 @@ if sfiles: # # Unpack the archive into build/unpack/scons-{version}. # - unpack_zip_files = map(lambda x, u=unpack_zip_dir, psv=psv: - os.path.join(u, psv, x), - sfiles) + unpack_zip_files = [os.path.join(unpack_zip_dir, psv, x) + for x in sfiles] env.Command(unpack_zip_files, src_zip, [ Delete(os.path.join(unpack_zip_dir, psv)), @@ -1351,8 +1327,7 @@ if sfiles: # like this because we put a preamble in it that will chdir() # to the directory in which setup.py exists. # - dfiles = map(lambda x, d=test_src_zip_dir: os.path.join(d, x), - dst_files) + dfiles = [os.path.join(test_src_zip_dir, x) for x in dst_files] scons_lib_dir = os.path.join(unpack_zip_dir, psv, 'src', 'engine') ENV = env.Dictionary('ENV').copy() ENV['SCONS_LIB_DIR'] = scons_lib_dir diff --git a/bench/bench.py b/bench/bench.py index ef60535..e076e43 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -23,6 +23,7 @@ # # This will allow (as much as possible) us to time just the code itself, # not Python function call overhead. +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS import getopt import sys @@ -93,10 +94,10 @@ exec(open(args[0], 'rU').read()) try: FunctionList except NameError: - function_names = filter(lambda x: x[:4] == FunctionPrefix, locals().keys()) + function_names = [x for x in locals().keys() if x[:4] == FunctionPrefix] function_names.sort() - l = map(lambda f, l=locals(): l[f], function_names) - FunctionList = filter(lambda f: type(f) == types.FunctionType, l) + l = [locals()[f] for f in function_names] + FunctionList = [f for f in l if type(f) == types.FunctionType] IterationList = [None] * Iterations @@ -104,7 +105,7 @@ def timer(func, *args, **kw): results = [] for i in range(Runs): start = Now() - apply(func, args, kw) + func(*args, **kw) finish = Now() results.append((finish - start) / Iterations) return results @@ -119,7 +120,7 @@ for func in FunctionList: print func.__name__ + d + ':' for label, args, kw in Data: - r = apply(timer, (func,)+args, kw) + r = timer(func, *args, **kw) display(label, r) # Local Variables: diff --git a/bench/env.__setitem__.py b/bench/env.__setitem__.py index d20785a..61d8c1e 100644 --- a/bench/env.__setitem__.py +++ b/bench/env.__setitem__.py @@ -6,7 +6,6 @@ import os.path import re -import string import sys import timeit @@ -174,7 +173,7 @@ class env_global_regex_is_valid(Environment): class env_special_set_has_key(Environment): """_special_set.get(): use _special_set.has_key() instead""" def __setitem__(self, key, value): - if self._special_set.has_key(key): + if key in self._special_set: self._special_set[key](self, key, value) else: if not SCons.Environment.is_valid_construction_var(key): @@ -232,7 +231,7 @@ class env_not_has_key(Environment): if special: special(self, key, value) else: - if not self._dict.has_key(key) \ + if key not in self._dict \ and not SCons.Environment.is_valid_construction_var(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key self._dict[key] = value @@ -243,7 +242,7 @@ class env_Best_attribute(Environment): if key in self._special_set_keys: self._special_set[key](self, key, value) else: - if not self._dict.has_key(key) \ + if key not in self._dict \ and not global_valid_var.match(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key self._dict[key] = value @@ -251,10 +250,10 @@ class env_Best_attribute(Environment): class env_Best_has_key(Environment): """Best __setitem__(), with has_key""" def __setitem__(self, key, value): - if self._special_set.has_key(key): + if key in self._special_set: self._special_set[key](self, key, value) else: - if not self._dict.has_key(key) \ + if key not in self._dict \ and not global_valid_var.match(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key self._dict[key] = value @@ -265,7 +264,7 @@ class env_Best_list(Environment): if key in ['BUILDERS', 'SCANNERS', 'TARGET', 'TARGETS', 'SOURCE', 'SOURCES']: self._special_set[key](self, key, value) else: - if not self._dict.has_key(key) \ + if key not in self._dict \ and not global_valid_var.match(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key self._dict[key] = value @@ -278,7 +277,7 @@ else: class env_isalnum(Environment): """Greg's Folly: isalnum instead of probe""" def __setitem__(self, key, value): - if self._special_set.has_key(key): + if key in self._special_set: self._special_set[key](self, key, value) else: if not key.isalnum() and not global_valid_var.match(key): @@ -324,7 +323,7 @@ common_import_variables = ['do_it'] + class_names common_imports = """ from __main__ import %s -""" % string.join(common_import_variables, ', ') +""" % ', '.join(common_import_variables) # The test data (lists of variable names) that we'll use for the runs. @@ -340,10 +339,10 @@ def run_it(title, init): s['num'] = iterations s['title'] = title s['init'] = init - apply(times,(),s) + times(**s) print 'Environment __setitem__ benchmark using', -print 'Python', string.split(sys.version)[0], +print 'Python', sys.version.split()[0], print 'on', sys.platform, os.name run_it('Results for re-adding an existing variable name 100 times:', diff --git a/bench/is_types.py b/bench/is_types.py index d225465..f9f7677 100644 --- a/bench/is_types.py +++ b/bench/is_types.py @@ -29,11 +29,11 @@ except ImportError: def __complex__(self): return complex(self.data) def __hash__(self): return hash(self.data) - def __cmp__(self, string): - if isinstance(string, UserString): - return cmp(self.data, string.data) + def __cmp__(self, s): + if isinstance(s, UserString): + return cmp(self.data, s.data) else: - return cmp(self.data, string) + return cmp(self.data, s) def __contains__(self, char): return char in self.data diff --git a/bench/lvars-gvars.py b/bench/lvars-gvars.py index 724b7a2..bdb09ef 100644 --- a/bench/lvars-gvars.py +++ b/bench/lvars-gvars.py @@ -19,7 +19,7 @@ def Func1(var, gvars, lvars): def Func2(var, gvars, lvars): """lvars has_key(), gvars try:-except:""" for i in IterationList: - if lvars.has_key(var): + if var in lvars: x = lvars[var] else: try: @@ -30,9 +30,9 @@ def Func2(var, gvars, lvars): def Func3(var, gvars, lvars): """lvars has_key(), gvars has_key()""" for i in IterationList: - if lvars.has_key(var): + if var in lvars: x = lvars[var] - elif gvars.has_key(var): + elif var in gvars: x = gvars[var] else: x = '' diff --git a/bench/timeit.py b/bench/timeit.py index cc087e1..ca7e470 100644 --- a/bench/timeit.py +++ b/bench/timeit.py @@ -70,8 +70,6 @@ except ImportError: # Must be an older Python version (see timeit() below) itertools = None -import string - __all__ = ["Timer"] dummy_src_name = "" @@ -100,7 +98,7 @@ def inner(_it, _timer): def reindent(src, indent): """Helper to reindent a multi-line statement.""" - return string.replace(src, "\n", "\n" + " "*indent) + return src.replace("\n", "\n" + " "*indent) class Timer: """Class for timing execution speed of small code snippets. @@ -226,7 +224,7 @@ def main(args=None): print "use -h/--help for command line help" return 2 timer = default_timer - stmt = string.join(args, "\n") or "pass" + stmt = "\n".join(args) or "pass" number = 0 # auto-determine setup = [] repeat = default_repeat @@ -252,7 +250,7 @@ def main(args=None): if o in ("-h", "--help"): print __doc__, return 0 - setup = string.join(setup, "\n") or "pass" + setup = "\n".join(setup) or "pass" # Include the current directory, so that local imports work (sys.path # contains the directory of this script, rather than the current # directory) @@ -279,7 +277,7 @@ def main(args=None): return 1 best = min(r) if verbose: - print "raw times:", string.join(map(lambda x, p=precision: "%.*g" % (p, x), r)) + print "raw times:", ' '.join(["%.*g" % (precision, x) for x in r]) print "%d loops," % number, usec = best * 1e6 / number if usec < 1000: diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py index 3f64a25..d164d11 100644 --- a/bin/SConsDoc.py +++ b/bin/SConsDoc.py @@ -2,6 +2,7 @@ # # Module for handling SCons documentation processing. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __doc__ = """ This module parses home-brew XML files that document various things @@ -218,8 +219,8 @@ class SConsDocHandler(xml.sax.handler.ContentHandler, self._start_dispatch = {} self._end_dispatch = {} keys = self.__class__.__dict__.keys() - start_tag_method_names = filter(lambda k: k[:6] == 'start_', keys) - end_tag_method_names = filter(lambda k: k[:4] == 'end_', keys) + start_tag_method_names = [k for k in keys if k[:6] == 'start_'] + end_tag_method_names = [k for k in keys if k[:4] == 'end_'] for method_name in start_tag_method_names: tag = method_name[6:] self._start_dispatch[tag] = getattr(self, method_name) diff --git a/bin/import-test.py b/bin/import-test.py index 839d2ad..fe5ea2f 100644 --- a/bin/import-test.py +++ b/bin/import-test.py @@ -78,7 +78,7 @@ def print_files(dir): if not d: l = dir.path + [n] sys.stdout.write('\ntest.write(%s, """\\\n' % l) - p = os.path.join(*([directory] + l)) + p = os.path.join(directory, *l) sys.stdout.write(open(p, 'r').read()) sys.stdout.write('""")\n') dir.call_for_each_entry(print_a_file) diff --git a/bin/linecount.py b/bin/linecount.py index 33f9f73..715d207 100644 --- a/bin/linecount.py +++ b/bin/linecount.py @@ -22,11 +22,11 @@ # non-comment lines. The last figure (non-comment) lines is the most # interesting one for most purposes. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string fmt = "%-16s %5s %7s %9s %11s %11s" @@ -85,8 +85,8 @@ sources = Collection('sources', pred=is_source) def t(arg, dirname, names): try: names.remove('.svn') except ValueError: pass - names = filter(arg, names) - arg.extend(map(lambda n, d=dirname: os.path.join(d, n), names)) + names = list(filter(arg, names)) + arg.extend([os.path.join(dirname, n) for n in names]) os.path.walk('src', t, src_Tests_py_tests) os.path.walk('src', t, src_test_tests) diff --git a/bin/memoicmp.py b/bin/memoicmp.py index f45ecb0..812af66 100644 --- a/bin/memoicmp.py +++ b/bin/memoicmp.py @@ -1,21 +1,24 @@ #!/usr/bin/env python # -# A script to compare the --debug=memoizer output found int +# A script to compare the --debug=memoizer output found in # two different files. -import sys,string +import sys def memoize_output(fname): - mout = {} - lines=filter(lambda words: - len(words) == 5 and - words[1] == 'hits' and words[3] == 'misses', - map(string.split, open(fname,'r').readlines())) - for line in lines: - mout[line[-1]] = ( int(line[0]), int(line[2]) ) - return mout + mout = {} + #lines=filter(lambda words: + # len(words) == 5 and + # words[1] == 'hits' and words[3] == 'misses', + # map(string.split, open(fname,'r').readlines())) + #for line in lines: + # mout[line[-1]] = ( int(line[0]), int(line[2]) ) + for line in open(fname,'r').readlines(): + words = line.split() + if len(words) == 5 and words[1] == 'hits' and words[3] == 'misses': + mout[words[-1]] = ( int(words[0]), int(words[2]) ) + return mout - def memoize_cmp(filea, fileb): ma = memoize_output(filea) mb = memoize_output(fileb) diff --git a/bin/objcounts.py b/bin/objcounts.py index ca814b4..c1f2dd5 100644 --- a/bin/objcounts.py +++ b/bin/objcounts.py @@ -40,7 +40,7 @@ def fetch_counts(fname): list = [l.split() for l in lines if re.match('\s+\d', l)] d = {} for l in list: - d[l[-1]] = map(int, l[:-1]) + d[l[-1]] = list(map(int, l[:-1])) return d c1 = fetch_counts(sys.argv[1]) diff --git a/bin/scons-diff.py b/bin/scons-diff.py index 7c60308..d1e48cf 100644 --- a/bin/scons-diff.py +++ b/bin/scons-diff.py @@ -97,15 +97,15 @@ def simple_diff(a, b, fromfile='', tofile='', for op, a1, a2, b1, b2 in sm.get_opcodes(): if op == 'delete': result.append("%sd%d\n" % (comma(a1, a2), b1)) - result.extend(map(lambda l: '< ' + l, a[a1:a2])) + result.extend(['< ' + l for l in a[a1:a2]]) elif op == 'insert': result.append("%da%s\n" % (a1, comma(b1, b2))) - result.extend(map(lambda l: '> ' + l, b[b1:b2])) + result.extend(['> ' + l for l in b[b1:b2]]) elif op == 'replace': result.append("%sc%s\n" % (comma(a1, a2), comma(b1, b2))) - result.extend(map(lambda l: '< ' + l, a[a1:a2])) + result.extend(['< ' + l for l in a[a1:a2]]) result.append('---\n') - result.extend(map(lambda l: '> ' + l, b[b1:b2])) + result.extend(['> ' + l for l in b[b1:b2]]) return result diff_map = { diff --git a/bin/scons-doc.py b/bin/scons-doc.py index e385b08..f140743 100644 --- a/bin/scons-doc.py +++ b/bin/scons-doc.py @@ -88,12 +88,12 @@ # Error output gets passed through to your error output so you # can see if there are any problems executing the command. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS import optparse import os import re import sgmllib -import string import sys import time @@ -185,7 +185,6 @@ Prompt = { Stdin = """\ import os import re -import string import SCons.Action import SCons.Defaults import SCons.Node.FS @@ -231,7 +230,7 @@ class Curry: else: kw = kwargs or self.kwargs - return apply(self.fun, self.pending + args, kw) + return self.fun(*self.pending + args, **kw) def Str(target, source, env, cmd=""): result = [] @@ -304,7 +303,7 @@ def JavaCCom(target, source, env): # public class FooBar # lines in the source file(s) and spits those out # to .class files named after the class. - tlist = map(str, target) + tlist = list(map(str, target)) not_copied = {} for t in tlist: not_copied[t] = 1 @@ -312,7 +311,7 @@ def JavaCCom(target, source, env): contents = open(src, "rb").read() classes = public_class_re.findall(contents) for c in classes: - for t in filter(lambda x: string.find(x, c) != -1, tlist): + for t in [x for x in tlist if x.find(c) != -1]: open(t, "wb").write(contents) del not_copied[t] for t in not_copied.keys(): @@ -326,7 +325,7 @@ def JavaHCom(target, source, env): def find_class_files(arg, dirname, names): class_files = filter(lambda n: n[-6:] == '.class', names) - paths = map(lambda n, d=dirname: os.path.join(d, n), class_files) + paths = map(lambda n: os.path.join(dirname, n), class_files) arg.extend(paths) def JarCom(target, source, env): @@ -382,9 +381,9 @@ ToolList = { toollist = ToolList[platform] filter_tools = string.split('%(tools)s') if filter_tools: - toollist = filter(lambda x, ft=filter_tools: x[0] in ft, toollist) + toollist = [x for x in toollist if x[0] in filter_tools] -toollist = map(lambda t: apply(ToolSurrogate, t), toollist) +toollist = [ToolSurrogate(*t) for t in toollist] toollist.append('install') @@ -413,8 +412,8 @@ def command_scons(args, c, test, dict): except AttributeError: pass else: - for arg in string.split(c.environment): - key, val = string.split(arg, '=') + for arg in c.environment.split(): + key, val = arg.split('=') try: save_vals[key] = os.environ[key] except KeyError: @@ -427,17 +426,17 @@ def command_scons(args, c, test, dict): # warnings that come from the new revamped VS support so # we can build doc on (Linux) systems that don't have # Visual C installed. - arguments = '--warn=no-visual-c-missing -f - ' + string.join(args), + arguments = '--warn=no-visual-c-missing -f - ' + ' '.join(args), chdir = test.workpath('WORK'), stdin = Stdin % dict) os.environ.update(save_vals) for key in delete_keys: del(os.environ[key]) out = test.stdout() - out = string.replace(out, test.workpath('ROOT'), '') - out = string.replace(out, test.workpath('WORK/SConstruct'), + out = out.replace(test.workpath('ROOT'), '') + out = out.replace(test.workpath('WORK/SConstruct'), '/home/my/project/SConstruct') - lines = string.split(out, '\n') + lines = out.split('\n') if lines: while lines[-1] == '': lines = lines[:-1] @@ -479,9 +478,9 @@ def command_edit(args, c, test, dict): def command_ls(args, c, test, dict): def ls(a): files = os.listdir(a) - files = filter(lambda x: x[0] != '.', files) + files = [x for x in files if x[0] != '.'] files.sort() - return [string.join(files, ' ')] + return [' '.join(files)] if args: l = [] for a in args: @@ -569,7 +568,7 @@ class MySGML(sgmllib.SGMLParser): # handle the begin-end tags of our SCons examples. def start_scons_example(self, attrs): - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if t: name = t[0][1] try: @@ -585,7 +584,7 @@ class MySGML(sgmllib.SGMLParser): def end_scons_example(self): e = self.e - files = filter(lambda f: f.printme, e.files) + files = [f for f in e.files if f.printme] if files: self.outfp.write('') for f in files: @@ -593,9 +592,9 @@ class MySGML(sgmllib.SGMLParser): i = len(f.data) - 1 while f.data[i] == ' ': i = i - 1 - output = string.replace(f.data[:i+1], '__ROOT__', '') - output = string.replace(output, '<', '<') - output = string.replace(output, '>', '>') + output = f.data[:i+1].replace('__ROOT__', '') + output = output.replace('<', '<') + output = output.replace('>', '>') self.outfp.write(output) if e.data and e.data[0] == '\n': e.data = e.data[1:] @@ -608,7 +607,7 @@ class MySGML(sgmllib.SGMLParser): e = self.e except AttributeError: self.error(" tag outside of ") - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if not t: self.error("no name attribute found") try: @@ -632,7 +631,7 @@ class MySGML(sgmllib.SGMLParser): e = self.e except AttributeError: self.error(" tag outside of ") - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if not t: self.error("no name attribute found") try: @@ -651,7 +650,7 @@ class MySGML(sgmllib.SGMLParser): self.afunclist = self.afunclist[:-1] def start_scons_example_file(self, attrs): - t = filter(lambda t: t[0] == 'example', attrs) + t = [t for t in attrs if t[0] == 'example'] if not t: self.error("no example attribute found") exname = t[0][1] @@ -659,11 +658,11 @@ class MySGML(sgmllib.SGMLParser): e = self.examples[exname] except KeyError: self.error("unknown example name '%s'" % exname) - fattrs = filter(lambda t: t[0] == 'name', attrs) + fattrs = [t for t in attrs if t[0] == 'name'] if not fattrs: self.error("no name attribute found") fname = fattrs[0][1] - f = filter(lambda f, fname=fname: f.name == fname, e.files) + f = [f for f in e.files if f.name == fname] if not f: self.error("example '%s' does not have a file named '%s'" % (exname, fname)) self.f = f[0] @@ -675,7 +674,7 @@ class MySGML(sgmllib.SGMLParser): delattr(self, 'f') def start_scons_output(self, attrs): - t = filter(lambda t: t[0] == 'example', attrs) + t = [t for t in attrs if t[0] == 'example'] if not t: self.error("no example attribute found") exname = t[0][1] @@ -704,7 +703,7 @@ class MySGML(sgmllib.SGMLParser): if o.preserve: t.preserve() t.subdir('ROOT', 'WORK') - t.rootpath = string.replace(t.workpath('ROOT'), '\\', '\\\\') + t.rootpath = t.workpath('ROOT').replace('\\', '\\\\') for d in e.dirs: dir = t.workpath('WORK', d.name) @@ -715,19 +714,19 @@ class MySGML(sgmllib.SGMLParser): i = 0 while f.data[i] == '\n': i = i + 1 - lines = string.split(f.data[i:], '\n') + lines = f.data[i:].split('\n') i = 0 while lines[0][i] == ' ': i = i + 1 - lines = map(lambda l, i=i: l[i:], lines) - path = string.replace(f.name, '__ROOT__', t.rootpath) + lines = [l[i:] for l in lines] + path = f.name.replace('__ROOT__', t.rootpath) if not os.path.isabs(path): path = t.workpath('WORK', path) dir, name = os.path.split(path) if dir and not os.path.exists(dir): os.makedirs(dir) - content = string.join(lines, '\n') - content = string.replace(content, '__ROOT__', t.rootpath) + content = '\n'.join(lines) + content = content.replace('__ROOT__', t.rootpath) path = t.workpath('WORK', path) t.write(path, content) if hasattr(f, 'chmod'): @@ -761,24 +760,24 @@ class MySGML(sgmllib.SGMLParser): for c in o.commandlist: self.outfp.write(p + Prompt[o.os]) - d = string.replace(c.data, '__ROOT__', '') + d = c.data.replace('__ROOT__', '') self.outfp.write('' + d + '\n') - e = string.replace(c.data, '__ROOT__', t.workpath('ROOT')) - args = string.split(e) + e = c.data.replace('__ROOT__', t.workpath('ROOT')) + args = e.split() lines = ExecuteCommand(args, c, t, {'osname':o.os, 'tools':o.tools}) content = None if c.output: content = c.output elif lines: - content = string.join(lines, '\n' + p) + content = ( '\n' + p).join(lines) if content: content = address_re.sub(r' at 0x700000>', content) content = engine_re.sub(r' File "bootstrap/src/engine/SCons/', content) content = file_re.sub(r'\1 ', content) content = nodelist_re.sub(r"\1 'NodeList' object \2", content) - content = string.replace(content, '<', '<') - content = string.replace(content, '>', '>') + content = content.replace('<', '<') + content = content.replace('>', '>') self.outfp.write(p + content + '\n') if o.data[0] == '\n': @@ -815,7 +814,7 @@ class MySGML(sgmllib.SGMLParser): def end_sconstruct(self): f = self.f self.outfp.write('') - output = string.replace(f.data, '__ROOT__', '') + output = f.data.replace('__ROOT__', '') self.outfp.write(output + '') delattr(self, 'f') self.afunclist = self.afunclist[:-1] diff --git a/bin/scons-proc.py b/bin/scons-proc.py index 15f22b7..52d326c 100644 --- a/bin/scons-proc.py +++ b/bin/scons-proc.py @@ -13,7 +13,6 @@ import getopt import os.path import re -import string import StringIO import sys import xml.sax @@ -140,7 +139,7 @@ class SCons_XML: class SCons_XML_to_XML(SCons_XML): def write(self, files): - gen, mod = string.split(files, ',') + gen, mod = files.split(',') g.write_gen(gen) g.write_mod(mod) def write_gen(self, filename): @@ -157,12 +156,12 @@ class SCons_XML_to_XML(SCons_XML): for chunk in v.summary.body: f.write(str(chunk)) if v.sets: - s = map(lambda x: '&cv-link-%s;' % x, v.sets) + s = ['&cv-link-%s;' % x for x in v.sets] f.write('\n') f.write('Sets: ' + ', '.join(s) + '.\n') f.write('\n') if v.uses: - u = map(lambda x: '&cv-link-%s;' % x, v.uses) + u = ['&cv-link-%s;' % x for x in v.uses] f.write('\n') f.write('Uses: ' + ', '.join(u) + '.\n') f.write('\n') @@ -216,15 +215,15 @@ class SCons_XML_to_man(SCons_XML): for v in self.values: chunks.extend(v.mansep()) chunks.extend(v.initial_chunks()) - chunks.extend(map(str, v.summary.body)) + chunks.extend(list(map(str, v.summary.body))) body = ''.join(chunks) - body = string.replace(body, '', '.ES') - body = string.replace(body, '', '.EE') - body = string.replace(body, '\n\n\n', '\n\n') - body = string.replace(body, '\n', '') - body = string.replace(body, '', '\n') - body = string.replace(body, '\n', '') + body = body.replace('', '.ES') + body = body.replace('', '.EE') + body = body.replace('\n\n\n', '\n\n') + body = body.replace('\n', '') + body = body.replace('', '\n') + body = body.replace('\n', '') body = string.replace(body, '\n', '.RS 10\n') # Handling needs to be rationalized and made @@ -241,9 +240,9 @@ class SCons_XML_to_man(SCons_XML): body = string.replace(body, '\n.IP\n\'\\"', '\n\n\'\\"') body = re.sub('&(scons|SConstruct|SConscript|jar|Make|lambda);', r'\\fB\1\\fP', body) body = re.sub('&(TARGET|TARGETS|SOURCE|SOURCES);', r'\\fB$\1\\fP', body) - body = string.replace(body, '&Dir;', r'\fBDir\fP') - body = string.replace(body, '⌖', r'\fItarget\fP') - body = string.replace(body, '&source;', r'\fIsource\fP') + body = body.replace('&Dir;', r'\fBDir\fP') + body = body.replace('⌖', r'\fItarget\fP') + body = body.replace('&source;', r'\fIsource\fP') body = re.sub('&b(-link)?-([^;]*);', r'\\fB\2\\fP()', body) body = re.sub('&cv(-link)?-([^;]*);', r'$\2', body) body = re.sub('&f(-link)?-env-([^;]*);', r'\\fBenv.\2\\fP()', body) @@ -258,8 +257,8 @@ class SCons_XML_to_man(SCons_XML): body = re.compile(r'^(\S+)\\f([BI])(.*)\\fP$', re.M).sub(r'.R\2 \1 \3', body) body = re.compile(r'^(\S+)\\f([BI])(.*)\\fP([^\s\\]+)$', re.M).sub(r'.R\2 \1 \3 \4', body) body = re.compile(r'^(\.R[BI].*[\S])\s+$;', re.M).sub(r'\1', body) - body = string.replace(body, '<', '<') - body = string.replace(body, '>', '>') + body = body.replace('<', '<') + body = body.replace('>', '>') body = re.sub(r'\\([^f])', r'\\\\\1', body) body = re.compile("^'\\\\\\\\", re.M).sub("'\\\\", body) body = re.compile(r'^\.([BI]R?) --', re.M).sub(r'.\1 \-\-', body) diff --git a/bin/scons-test.py b/bin/scons-test.py index aa03d72..8d1950f 100644 --- a/bin/scons-test.py +++ b/bin/scons-test.py @@ -19,7 +19,6 @@ import getopt import imp import os import os.path -import string import sys import tempfile import time @@ -90,7 +89,7 @@ def outname(n, outdir=outdir): l.append(tail) l.append(outdir) l.reverse() - return apply(os.path.join, l) + return os.path.join(*l) for name in zf.namelist(): dest = outname(name) @@ -135,7 +134,7 @@ fp.close() if not args: runtest_args = '-a' else: - runtest_args = string.join(args) + runtest_args = ' '.join(args) if format == '--xml': diff --git a/bin/scons-unzip.py b/bin/scons-unzip.py index 28c73f8..c0eb8aa 100644 --- a/bin/scons-unzip.py +++ b/bin/scons-unzip.py @@ -52,7 +52,7 @@ def outname(n, outdir=outdir): l.append(tail) l.append(outdir) l.reverse() - return apply(os.path.join, l) + return os.path.join(*l) for name in zf.namelist(): dest = outname(name) diff --git a/bin/sconsexamples.py b/bin/sconsexamples.py index 0a409bc..6f20ae9 100644 --- a/bin/sconsexamples.py +++ b/bin/sconsexamples.py @@ -67,12 +67,12 @@ # Error output gets passed through to your error output so you # can see if there are any problems executing the command. # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS import os import os.path import re import sgmllib -import string import sys sys.path.append(os.path.join(os.getcwd(), 'etc')) @@ -156,7 +156,6 @@ Prompt = { # command output. Stdin = """\ -import string import SCons.Defaults platform = '%s' @@ -174,13 +173,13 @@ class Curry: else: kw = kwargs or self.kwargs - return apply(self.fun, self.pending + args, kw) + return self.fun(*self.pending + args, **kw) def Str(target, source, env, cmd=""): result = [] for cmd in env.subst_list(cmd, target=target, source=source): - result.append(string.join(map(str, cmd))) - return string.join(result, '\\n') + result.append(" ".join(map(str, cmd))) + return '\\n'.join(result) class ToolSurrogate: def __init__(self, tool, variable, func): @@ -212,7 +211,7 @@ ToolList = { ('mslink', 'LINKCOM', Cat)] } -tools = map(lambda t: apply(ToolSurrogate, t), ToolList[platform]) +tools = map(lambda t: ToolSurrogate(*t), ToolList[platform]) SCons.Defaults.ConstructionEnvironment.update({ 'PLATFORM' : platform, @@ -270,7 +269,7 @@ class MySGML(sgmllib.SGMLParser): sys.stdout.write('&#' + ref + ';') def start_scons_example(self, attrs): - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if t: name = t[0][1] try: @@ -286,7 +285,7 @@ class MySGML(sgmllib.SGMLParser): def end_scons_example(self): e = self.e - files = filter(lambda f: f.printme, e.files) + files = [f for f in e.files if f.printme] if files: sys.stdout.write('') for f in files: @@ -294,7 +293,7 @@ class MySGML(sgmllib.SGMLParser): i = len(f.data) - 1 while f.data[i] == ' ': i = i - 1 - output = string.replace(f.data[:i+1], '__ROOT__', '') + output = f.data[:i+1].replace('__ROOT__', '') sys.stdout.write(output) if e.data and e.data[0] == '\n': e.data = e.data[1:] @@ -307,7 +306,7 @@ class MySGML(sgmllib.SGMLParser): e = self.e except AttributeError: self.error(" tag outside of ") - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if not t: self.error("no name attribute found") try: @@ -331,7 +330,7 @@ class MySGML(sgmllib.SGMLParser): e = self.e except AttributeError: self.error(" tag outside of ") - t = filter(lambda t: t[0] == 'name', attrs) + t = [t for t in attrs if t[0] == 'name'] if not t: self.error("no name attribute found") try: @@ -350,7 +349,7 @@ class MySGML(sgmllib.SGMLParser): self.afunclist = self.afunclist[:-1] def start_scons_example_file(self, attrs): - t = filter(lambda t: t[0] == 'example', attrs) + t = [t for t in attrs if t[0] == 'example'] if not t: self.error("no example attribute found") exname = t[0][1] @@ -358,11 +357,11 @@ class MySGML(sgmllib.SGMLParser): e = self.examples[exname] except KeyError: self.error("unknown example name '%s'" % exname) - fattrs = filter(lambda t: t[0] == 'name', attrs) + fattrs = [t for t in attrs if t[0] == 'name'] if not fattrs: self.error("no name attribute found") fname = fattrs[0][1] - f = filter(lambda f, fname=fname: f.name == fname, e.files) + f = [f for f in e.files if f.name == fname] if not f: self.error("example '%s' does not have a file named '%s'" % (exname, fname)) self.f = f[0] @@ -377,7 +376,7 @@ class MySGML(sgmllib.SGMLParser): delattr(self, 'f') def start_scons_output(self, attrs): - t = filter(lambda t: t[0] == 'example', attrs) + t = [t for t in attrs if t[0] == 'example'] if not t: self.error("no example attribute found") exname = t[0][1] @@ -408,20 +407,19 @@ class MySGML(sgmllib.SGMLParser): i = 0 while f.data[i] == '\n': i = i + 1 - lines = string.split(f.data[i:], '\n') + lines = f.data[i:].split('\n') i = 0 while lines[0][i] == ' ': i = i + 1 - lines = map(lambda l, i=i: l[i:], lines) - path = string.replace(f.name, '__ROOT__', t.workpath('ROOT')) + lines = [l[i:] for l in lines] + path = f.name.replace('__ROOT__', t.workpath('ROOT')) dir, name = os.path.split(f.name) if dir: dir = t.workpath('WORK', dir) if not os.path.exists(dir): os.makedirs(dir) - content = string.join(lines, '\n') - content = string.replace(content, - '__ROOT__', + content = '\n'.join(lines) + content = content.replace('__ROOT__', t.workpath('ROOT')) t.write(t.workpath('WORK', f.name), content) i = len(o.prefix) @@ -431,19 +429,19 @@ class MySGML(sgmllib.SGMLParser): p = o.prefix[i:] for c in o.commandlist: sys.stdout.write(p + Prompt[o.os]) - d = string.replace(c.data, '__ROOT__', '') + d = c.data.replace('__ROOT__', '') sys.stdout.write('' + d + '\n') - e = string.replace(c.data, '__ROOT__', t.workpath('ROOT')) - args = string.split(e)[1:] + e = c.data.replace('__ROOT__', t.workpath('ROOT')) + args = e.split()[1:] os.environ['SCONS_LIB_DIR'] = scons_lib_dir t.run(interpreter = sys.executable, program = scons_py, - arguments = '-f - ' + string.join(args), + arguments = '-f - ' + ' '.join(args), chdir = t.workpath('WORK'), stdin = Stdin % o.os) - out = string.replace(t.stdout(), t.workpath('ROOT'), '') + out = t.stdout().replace(t.workpath('ROOT'), '') if out: - lines = string.split(out, '\n') + lines = out.split('\n') if lines: while lines[-1] == '': lines = lines[:-1] diff --git a/bin/sfsum b/bin/sfsum index a560b7d..22f43d7 100644 --- a/bin/sfsum +++ b/bin/sfsum @@ -25,7 +25,6 @@ import xml.sax import xml.sax.saxutils -import string import sys SFName = { @@ -51,7 +50,7 @@ Artifacts = {} def nws(text): """Normalize white space. This will become important if/when we enhance this to search for arbitrary fields.""" - return string.join(string.split(text), ' ') + return ' '.join(text.split()) class ClassifyArtifacts(xml.sax.saxutils.DefaultHandler): """ diff --git a/bootstrap.py b/bootstrap.py index 4dad44d..37e8e70 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -23,7 +23,6 @@ import os import os.path -import string import sys __doc__ = """bootstrap.py @@ -171,15 +170,15 @@ def find(file, search=search): if os.path.exists(f): return os.path.normpath(f) sys.stderr.write("could not find `%s' in search path:\n" % file) - sys.stderr.write("\t" + string.join(search, "\n\t") + "\n") + sys.stderr.write("\t" + "\n\t".join(search) + "\n") sys.exit(2) scons_py = os.path.join('src', 'script', 'scons.py') src_engine = os.path.join('src', 'engine') MANIFEST_in = find(os.path.join(src_engine, 'MANIFEST.in')) -files = [ scons_py ] + map(lambda x: os.path.join(src_engine, x[:-1]), - open(MANIFEST_in).readlines()) +files = [ scons_py ] + [os.path.join(src_engine, x[:-1]) + for x in open(MANIFEST_in).readlines()] for file in files: src = find(file) @@ -200,7 +199,7 @@ args = [ os.path.join(bootstrap_dir, scons_py) ] + pass_through_args -sys.stdout.write(string.join(args, " ") + '\n') +sys.stdout.write(" ".join(args) + '\n') sys.stdout.flush() os.environ['SCONS_LIB_DIR'] = os.path.join(bootstrap_dir, src_engine) diff --git a/doc/SConscript b/doc/SConscript index b8fc502..7af3d33 100644 --- a/doc/SConscript +++ b/doc/SConscript @@ -24,10 +24,10 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS import os.path import re -import string Import('build_dir', 'env', 'whereis') @@ -93,7 +93,7 @@ def scanxml(node, env, target): if tail == 'doc': break a = [tail] + a - file = apply(os.path.join, a, {}) + file = os.path.join(*a) includes.append(file) return includes @@ -119,8 +119,8 @@ def chop(s): return s[:-1] #manifest_in = File('#src/engine/MANIFEST.in').rstr() manifest_xml_in = File('#src/engine/MANIFEST-xml.in').rstr() -scons_doc_files = map(chop, open(manifest_xml_in).readlines()) -scons_doc_files = map(lambda x: File('#src/engine/'+x).rstr(), scons_doc_files) +scons_doc_files = list(map(chop, open(manifest_xml_in).readlines())) +scons_doc_files = [File('#src/engine/'+x).rstr() for x in scons_doc_files] if not jw: print "jw not found, skipping building User Guide." @@ -240,7 +240,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. # get included by the document XML files in the subdirectories. # manifest = File('MANIFEST').rstr() - src_files = map(lambda x: x[:-1], open(manifest).readlines()) + src_files = [x[:-1] for x in open(manifest).readlines()] for s in src_files: base, ext = os.path.splitext(s) if ext in ['.fig', '.jpg']: @@ -255,8 +255,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. # for doc in docs.keys(): manifest = File(os.path.join(doc, 'MANIFEST')).rstr() - src_files = map(lambda x: x[:-1], - open(manifest).readlines()) + src_files = [x[:-1] for x in open(manifest).readlines()] build_doc = docs[doc].get('scons-doc') and int(ARGUMENTS.get('BUILDDOC', 0)) for s in src_files: doc_s = os.path.join(doc, s) @@ -408,8 +407,7 @@ for m in man_page_list: man_i_files = ['builders.man', 'tools.man', 'variables.man'] -man_intermediate_files = map(lambda x: os.path.join(build, 'man', x), - man_i_files) +man_intermediate_files = [os.path.join(build, 'man', x) for x in man_i_files] cmd = "$PYTHON $SCONS_PROC_PY --man -b ${TARGETS[0]} -t ${TARGETS[1]} -v ${TARGETS[2]} $( $SOURCES $)" man_intermediate_files = env.Command(man_intermediate_files, @@ -444,12 +442,12 @@ for man_1 in man_page_list: def strip_to_first_html_tag(target, source, env): t = str(target[0]) contents = open(t).read() - contents = contents[string.find(contents, ''):] + contents = contents[contents.find(''):] open(t, 'w').write(contents) return 0 cmds = [ - "( cd %s/man && cp %s .. )" % (build, string.join(man_i_files)), + "( cd %s/man && cp %s .. )" % (build, ' '.join(man_i_files)), "( cd ${SOURCE.dir} && man2html ${SOURCE.file} ) > $TARGET", Action(strip_to_first_html_tag), ] @@ -469,15 +467,15 @@ else: # the SConstruct file. e = os.path.join('#src', 'engine') manifest_in = File(os.path.join(e, 'MANIFEST.in')).rstr() - sources = map(lambda x: x[:-1], open(manifest_in).readlines()) - sources = filter(lambda x: string.find(x, 'Optik') == -1, sources) - sources = filter(lambda x: string.find(x, 'Platform') == -1, sources) - sources = filter(lambda x: string.find(x, 'Tool') == -1, sources) + sources = [x[:-1] for x in open(manifest_in).readlines()] + sources = [x for x in sources if x.find('Optik') == -1] + sources = [x for x in sources if x.find('Platform') == -1] + sources = [x for x in sources if x.find('Tool') == -1] # XXX - sources = filter(lambda x: string.find(x, 'Options') == -1, sources) + sources = [x for x in sources if x.find('Options') == -1] e = os.path.join(build, '..', 'scons', 'engine') - sources = map(lambda x, e=e: os.path.join(e, x), sources) + sources = [os.path.join(e, x) for x in sources] epydoc_commands = [ Delete('$OUTDIR'), @@ -519,8 +517,7 @@ else: # for easy distribution to the web site. # if tar_deps: - tar_list = string.join(map(lambda x, b=build+'/': string.replace(x, b, ''), - tar_list)) + tar_list = ' '.join([x.replace(build+'/', '') for x in tar_list]) t = env.Command(dist_doc_tar_gz, tar_deps, "tar cf${TAR_HFLAG} - -C %s %s | gzip > $TARGET" % (build, tar_list)) AddPostAction(dist_doc_tar_gz, Chmod(dist_doc_tar_gz, 0644)) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index fa9b16c..c8017c4 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1841,9 +1841,7 @@ and a same-named environment method that split a single string into a list, separated on strings of white-space characters. -(These are similar to the -string.split() method -from the standard Python library, +(These are similar to the split() member function of Python strings but work even if the input isn't a string.) Like all Python arguments, @@ -1862,7 +1860,7 @@ env.Program('bar', env.Split('bar.c foo.c')) env.Program(source = ['bar.c', 'foo.c'], target = 'bar') env.Program(target = 'bar', Split('bar.c foo.c')) env.Program(target = 'bar', env.Split('bar.c foo.c')) -env.Program('bar', source = string.split('bar.c foo.c')) +env.Program('bar', source = 'bar.c foo.c'.split()) .EE Target and source file names @@ -5534,7 +5532,7 @@ The following statements are equivalent: .ES env.SetDefault(FOO = 'foo') -if not env.has_key('FOO'): env['FOO'] = 'foo' +if 'FOO' not in env: env['FOO'] = 'foo' .EE '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -9901,7 +9899,7 @@ as follows: def pf(env, dir, target, source, arg): top_dir = Dir('#').abspath results = [] - if env.has_key('MYPATH'): + if 'MYPATH' in env: for p in env['MYPATH']: results.append(top_dir + os.sep + p) return results diff --git a/doc/user/less-simple.in b/doc/user/less-simple.in index f7bd7d5..fcffa5e 100644 --- a/doc/user/less-simple.in +++ b/doc/user/less-simple.in @@ -371,7 +371,7 @@ you'll have realized that this is similar to the split() method in the Python standard string module. - Unlike the string.split() method, + Unlike the split() member function of strings, however, the &Split; function does not require a string as input and will wrap up a single non-string object in a list, diff --git a/doc/user/less-simple.xml b/doc/user/less-simple.xml index 0bc382e..8b781dd 100644 --- a/doc/user/less-simple.xml +++ b/doc/user/less-simple.xml @@ -360,7 +360,7 @@ you'll have realized that this is similar to the split() method in the Python standard string module. - Unlike the string.split() method, + Unlike the split() member function of strings, however, the &Split; function does not require a string as input and will wrap up a single non-string object in a list, diff --git a/doc/user/tasks.in b/doc/user/tasks.in index c51ad36..434871f 100644 --- a/doc/user/tasks.in +++ b/doc/user/tasks.in @@ -74,9 +74,8 @@ if filename.find(old_prefix) == 0: or in Python 1.5.2: -import string -if string.find(filename, old_prefix) == 0: - filename = string.replace(filename, old_prefix, new_prefix) +if filename.find(old_prefix) == 0: + filename = filename.replace(old_prefix, new_prefix) diff --git a/doc/user/tasks.xml b/doc/user/tasks.xml index c51ad36..434871f 100644 --- a/doc/user/tasks.xml +++ b/doc/user/tasks.xml @@ -74,9 +74,8 @@ if filename.find(old_prefix) == 0: or in Python 1.5.2: -import string -if string.find(filename, old_prefix) == 0: - filename = string.replace(filename, old_prefix, new_prefix) +if filename.find(old_prefix) == 0: + filename = filename.replace(old_prefix, new_prefix) diff --git a/runtest.py b/runtest.py index a927940..7fb505a 100644 --- a/runtest.py +++ b/runtest.py @@ -84,14 +84,13 @@ # you can find the appropriate code in the 0.04 version of this script, # rather than reinventing that wheel.) # +from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS import getopt import glob import os -import os.path import re import stat -import string import sys import time @@ -216,9 +215,9 @@ for o, a in opts: elif o in ['-q', '--quiet']: printcommand = 0 elif o in ['--sp']: - sp = string.split(a, os.pathsep) + sp = a.split(os.pathsep) elif o in ['--spe']: - spe = string.split(a, os.pathsep) + spe = a.split(os.pathsep) elif o in ['-t', '--time']: print_times = 1 elif o in ['--verbose']: @@ -245,8 +244,8 @@ runtest.py: No tests were specified. if sys.platform in ('win32', 'cygwin'): def whereis(file): - pathext = [''] + string.split(os.environ['PATHEXT'], os.pathsep) - for dir in string.split(os.environ['PATH'], os.pathsep): + pathext = [''] + os.environ['PATHEXT'].split(os.pathsep) + for dir in os.environ['PATH'].split(os.pathsep): f = os.path.join(dir, file) for ext in pathext: fext = f + ext @@ -257,7 +256,7 @@ if sys.platform in ('win32', 'cygwin'): else: def whereis(file): - for dir in string.split(os.environ['PATH'], os.pathsep): + for dir in os.environ['PATH'].split(os.pathsep): f = os.path.join(dir, file) if os.path.isfile(f): try: @@ -295,10 +294,10 @@ if format == '--aegis' and aegis: if change: if sp is None: paths = os.popen("aesub '$sp' 2>/dev/null", "r").read()[:-1] - sp = string.split(paths, os.pathsep) + sp = paths.split(os.pathsep) if spe is None: spe = os.popen("aesub '$spe' 2>/dev/null", "r").read()[:-1] - spe = string.split(spe, os.pathsep) + spe = spe.split(os.pathsep) else: aegis = None @@ -316,7 +315,7 @@ _ws = re.compile('\s') def escape(s): if _ws.search(s): s = '"' + s + '"' - s = string.replace(s, '\\', '\\\\') + s = s.replace('\\', '\\\\') return s # Set up lowest-common-denominator spawning of a process on both Windows @@ -334,7 +333,7 @@ except AttributeError: else: def spawn_it(command_args): command = command_args[0] - command_args = map(escape, command_args) + command_args = list(map(escape, command_args)) return os.spawnv(os.P_WAIT, command, command_args) class Base: @@ -447,7 +446,7 @@ if package: 'deb' : os.path.join('python2.1', 'site-packages') } - if not dir.has_key(package): + if package not in dir: sys.stderr.write("Unknown package '%s'\n" % package) sys.exit(2) @@ -490,7 +489,7 @@ else: # sd = d # scons = f # spe = map(lambda x: os.path.join(x, 'src', 'engine'), spe) - # ld = string.join(spe, os.pathsep) + # ld = os.pathsep.join(spe) if not baseline or baseline == '.': base = cwd @@ -569,9 +568,9 @@ for dir in sp: q = os.path.join(dir, 'QMTest') pythonpaths.append(q) -os.environ['SCONS_SOURCE_PATH_EXECUTABLE'] = string.join(spe, os.pathsep) +os.environ['SCONS_SOURCE_PATH_EXECUTABLE'] = os.pathsep.join(spe) -os.environ['PYTHONPATH'] = string.join(pythonpaths, os.pathsep) +os.environ['PYTHONPATH'] = os.pathsep.join(pythonpaths) if old_pythonpath: os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + \ @@ -581,21 +580,21 @@ if old_pythonpath: tests = [] def find_Tests_py(tdict, dirname, names): - for n in filter(lambda n: n[-8:] == "Tests.py", names): + for n in [n for n in names if n[-8:] == "Tests.py"]: tdict[os.path.join(dirname, n)] = 1 def find_py(tdict, dirname, names): - tests = filter(lambda n: n[-3:] == ".py", names) + tests = [n for n in names if n[-3:] == ".py"] try: excludes = open(os.path.join(dirname,".exclude_tests")).readlines() except (OSError, IOError): pass else: for exclude in excludes: - exclude = string.split(exclude, '#' , 1)[0] - exclude = string.strip(exclude) + exclude = exclude.split('#' , 1)[0] + exclude = exclude.strip() if not exclude: continue - tests = filter(lambda n, ex = exclude: n != ex, tests) + tests = [n for n in tests if n != exclude] for n in tests: tdict[os.path.join(dirname, n)] = 1 @@ -627,8 +626,8 @@ if args: tests.append(path) elif testlistfile: tests = open(testlistfile, 'r').readlines() - tests = filter(lambda x: x[0] != '#', tests) - tests = map(lambda x: x[:-1], tests) + tests = [x for x in tests if x[0] != '#'] + tests = [x[:-1] for x in tests] elif all and not qmtest: # Find all of the SCons functional tests in the local directory # tree. This is anything under the 'src' subdirectory that ends @@ -647,16 +646,16 @@ elif all and not qmtest: if format == '--aegis' and aegis: cmd = "aegis -list -unf pf 2>/dev/null" for line in os.popen(cmd, "r").readlines(): - a = string.split(line) - if a[0] == "test" and not tdict.has_key(a[-1]): + a = line.split() + if a[0] == "test" and a[-1] not in tdict: tdict[a[-1]] = Test(a[-1], spe) cmd = "aegis -list -unf cf 2>/dev/null" for line in os.popen(cmd, "r").readlines(): - a = string.split(line) + a = line.split() if a[0] == "test": if a[1] == "remove": del tdict[a[-1]] - elif not tdict.has_key(a[-1]): + elif a[-1] not in tdict: tdict[a[-1]] = Test(a[-1], spe) tests = tdict.keys() @@ -701,11 +700,11 @@ if qmtest: qmtest_args.append(rs) if format == '--aegis': - tests = map(lambda x: string.replace(x, cwd+os.sep, ''), tests) + tests = [x.replace(cwd+os.sep, '') for x in tests] else: os.environ['SCONS'] = os.path.join(cwd, 'src', 'script', 'scons.py') - cmd = string.join(qmtest_args + tests, ' ') + cmd = ' '.join(qmtest_args + tests) if printcommand: sys.stdout.write(cmd + '\n') sys.stdout.flush() @@ -719,7 +718,7 @@ if qmtest: #except OSError: # pass -tests = map(Test, tests) +tests = list(map(Test, tests)) class Unbuffered: def __init__(self, file): @@ -766,7 +765,7 @@ for t in tests: command_args.append(debug) command_args.append(t.path) t.command_args = [python] + command_args - t.command_str = string.join([escape(python)] + command_args, " ") + t.command_str = " ".join([escape(python)] + command_args) if printcommand: sys.stdout.write(t.command_str + "\n") test_start_time = time_func() @@ -778,9 +777,9 @@ if len(tests) > 0: tests[0].total_time = time_func() - total_start_time print_time_func("Total execution time for all tests: %.1f seconds\n", tests[0].total_time) -passed = filter(lambda t: t.status == 0, tests) -fail = filter(lambda t: t.status == 1, tests) -no_result = filter(lambda t: t.status == 2, tests) +passed = [t for t in tests if t.status == 0] +fail = [t for t in tests if t.status == 1] +no_result = [t for t in tests if t.status == 2] if len(tests) != 1 and execute_tests: if passed and print_passed_summary: @@ -788,22 +787,22 @@ if len(tests) != 1 and execute_tests: sys.stdout.write("\nPassed the following test:\n") else: sys.stdout.write("\nPassed the following %d tests:\n" % len(passed)) - paths = map(lambda x: x.path, passed) - sys.stdout.write("\t" + string.join(paths, "\n\t") + "\n") + paths = [x.path for x in passed] + sys.stdout.write("\t" + "\n\t".join(paths) + "\n") if fail: if len(fail) == 1: sys.stdout.write("\nFailed the following test:\n") else: sys.stdout.write("\nFailed the following %d tests:\n" % len(fail)) - paths = map(lambda x: x.path, fail) - sys.stdout.write("\t" + string.join(paths, "\n\t") + "\n") + paths = [x.path for x in fail] + sys.stdout.write("\t" + "\n\t".join(paths) + "\n") if no_result: if len(no_result) == 1: sys.stdout.write("\nNO RESULT from the following test:\n") else: sys.stdout.write("\nNO RESULT from the following %d tests:\n" % len(no_result)) - paths = map(lambda x: x.path, no_result) - sys.stdout.write("\t" + string.join(paths, "\n\t") + "\n") + paths = [x.path for x in no_result] + sys.stdout.write("\t" + "\n\t".join(paths) + "\n") if outputfile: if outputfile == '-': diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 41c73ad..35c7316 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -96,6 +96,7 @@ way for wrapping up the functions. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -103,7 +104,6 @@ import cPickle import dis import os import re -import string import sys import subprocess @@ -153,7 +153,7 @@ else: else: result.append(c) i = i+1 - return string.join(result, '') + return ''.join(result) strip_quotes = re.compile('^[\'"](.*)[\'"]$') @@ -249,19 +249,19 @@ def _code_contents(code): # Note that we also always ignore the first entry of co_consts # which contains the function doc string. We assume that the # function does not access its doc string. - contents.append(',(' + string.join(map(_object_contents,code.co_consts[1:]),',') + ')') + contents.append(',(' + ','.join(map(_object_contents,code.co_consts[1:])) + ')') # The code contents depends on the variable names used to # accessed global variable, as changing the variable name changes # the variable actually accessed and therefore changes the # function result. - contents.append(',(' + string.join(map(_object_contents,code.co_names),',') + ')') + contents.append(',(' + ','.join(map(_object_contents,code.co_names)) + ')') # The code contents depends on its actual code!!! contents.append(',(' + str(remove_set_lineno_codes(code.co_code)) + ')') - return string.join(contents, '') + return ''.join(contents) def _function_contents(func): @@ -271,7 +271,7 @@ def _function_contents(func): # The function contents depends on the value of defaults arguments if func.func_defaults: - contents.append(',(' + string.join(map(_object_contents,func.func_defaults),',') + ')') + contents.append(',(' + ','.join(map(_object_contents,func.func_defaults)) + ')') else: contents.append(',()') @@ -284,12 +284,12 @@ def _function_contents(func): #xxx = [_object_contents(x.cell_contents) for x in closure] try: - xxx = map(lambda x: _object_contents(x.cell_contents), closure) + xxx = [_object_contents(x.cell_contents) for x in closure] except AttributeError: xxx = [] - contents.append(',(' + string.join(xxx, ',') + ')') + contents.append(',(' + ','.join(xxx) + ')') - return string.join(contents, '') + return ''.join(contents) def _actionAppend(act1, act2): @@ -354,7 +354,7 @@ def _do_create_action(act, kw): if is_List(act): #TODO(1.5) return CommandAction(act, **kw) - return apply(CommandAction, (act,), kw) + return CommandAction(act, **kw) if callable(act): try: @@ -378,10 +378,10 @@ def _do_create_action(act, kw): # like a function or a CommandGenerator in that variable # instead of a string. return LazyAction(var, kw) - commands = string.split(str(act), '\n') + commands = str(act).split('\n') if len(commands) == 1: #TODO(1.5) return CommandAction(commands[0], **kw) - return apply(CommandAction, (commands[0],), kw) + return CommandAction(commands[0], **kw) # The list of string commands may include a LazyAction, so we # reprocess them via _do_create_list_action. return _do_create_list_action(commands, kw) @@ -434,7 +434,7 @@ class ActionBase: if is_String(vl): vl = (vl,) for v in vl: result.append(env.subst('${'+v+'}')) - return string.join(result, '') + return ''.join(result) def __add__(self, other): return _actionAppend(self, other) @@ -450,7 +450,7 @@ class ActionBase: # and CommandGeneratorAction will use this env # when it calls its _generate method. self.presub_env = env - lines = string.split(str(self), '\n') + lines = str(self).split('\n') self.presub_env = None # don't need this any more return lines @@ -534,8 +534,8 @@ class _ActionAction(ActionBase): if executor: target = executor.get_all_targets() source = executor.get_all_sources() - t = string.join(map(str, target), ' and ') - l = string.join(self.presub_lines(env), '\n ') + t = ' and '.join(map(str, target)) + l = '\n '.join(self.presub_lines(env)) out = "Building %s with action:\n %s\n" % (t, l) sys.stdout.write(out) cmd = None @@ -590,7 +590,7 @@ def _string_from_cmd_list(cmd_list): if ' ' in arg or '\t' in arg: arg = '"' + arg + '"' cl.append(arg) - return string.join(cl) + return ' '.join(cl) # A fiddlin' little function that has an 'import SCons.Environment' which # can't be moved to the top level without creating an import loop. Since @@ -642,7 +642,7 @@ def _subproc(env, cmd, error = 'ignore', **kw): # because that's a pretty common list-like value to stick # in an environment variable: value = SCons.Util.flatten_sequence(value) - new_env[key] = string.join(map(str, value), os.pathsep) + new_env[key] = os.pathsep.join(map(str, value)) else: # It's either a string or something else. If it's a string, # we still want to call str() because it might be a *Unicode* @@ -655,7 +655,7 @@ def _subproc(env, cmd, error = 'ignore', **kw): try: #FUTURE return subprocess.Popen(cmd, **kw) - return apply(subprocess.Popen, (cmd,), kw) + return subprocess.Popen(cmd, **kw) except EnvironmentError, e: if error == 'raise': raise # return a dummy Popen instance that only returns error @@ -685,16 +685,16 @@ class CommandAction(_ActionAction): if __debug__: logInstanceCreation(self, 'Action.CommandAction') #TODO(1.5) _ActionAction.__init__(self, **kw) - apply(_ActionAction.__init__, (self,), kw) + _ActionAction.__init__(self, **kw) if is_List(cmd): - if filter(is_List, cmd): + if list(filter(is_List, cmd)): raise TypeError, "CommandAction should be given only " \ "a single command" self.cmd_list = cmd def __str__(self): if is_List(self.cmd_list): - return string.join(map(str, self.cmd_list), ' ') + return ' '.join(map(str, self.cmd_list)) return str(self.cmd_list) def process(self, target, source, env, executor=None): @@ -771,7 +771,7 @@ class CommandAction(_ActionAction): # path list, because that's a pretty common list-like # value to stick in an environment variable: value = flatten_sequence(value) - ENV[key] = string.join(map(str, value), os.pathsep) + ENV[key] = os.pathsep.join(map(str, value)) else: # If it isn't a string or a list, then we just coerce # it to a string, which is the proper way to handle @@ -782,7 +782,7 @@ class CommandAction(_ActionAction): if executor: target = executor.get_all_targets() source = executor.get_all_sources() - cmd_list, ignore, silent = self.process(target, map(rfile, source), env, executor) + cmd_list, ignore, silent = self.process(target, list(map(rfile, source)), env, executor) # Use len() to filter out any "command" that's zero-length. for cmd_line in filter(len, cmd_list): @@ -806,7 +806,7 @@ class CommandAction(_ActionAction): from SCons.Subst import SUBST_SIG cmd = self.cmd_list if is_List(cmd): - cmd = string.join(map(str, cmd)) + cmd = ' '.join(map(str, cmd)) else: cmd = str(cmd) if executor: @@ -860,7 +860,7 @@ class CommandGeneratorAction(ActionBase): env=env, for_signature=for_signature) #TODO(1.5) gen_cmd = Action(ret, **self.gen_kw) - gen_cmd = apply(Action, (ret,), self.gen_kw) + gen_cmd = Action(ret, **self.gen_kw) if not gen_cmd: raise SCons.Errors.UserError("Object returned from command generator: %s cannot be used to create an Action." % repr(ret)) return gen_cmd @@ -885,7 +885,9 @@ class CommandGeneratorAction(ActionBase): show=_null, execute=_null, chdir=_null, executor=None): act = self._generate(target, source, env, 0, executor) if act is None: - raise UserError("While building `%s': Cannot deduce file extension from source files: %s" % (repr(map(str, target)), repr(map(str, source)))) + raise UserError("While building `%s': " + "Cannot deduce file extension from source files: %s" + % (repr(list(map(str, target))), repr(list(map(str, source))))) return act(target, source, env, exitstatfunc, presub, show, execute, chdir, executor) @@ -930,7 +932,7 @@ class LazyAction(CommandGeneratorAction, CommandAction): def __init__(self, var, kw): if __debug__: logInstanceCreation(self, 'Action.LazyAction') #FUTURE CommandAction.__init__(self, '${'+var+'}', **kw) - apply(CommandAction.__init__, (self, '${'+var+'}'), kw) + CommandAction.__init__(self, '${'+var+'}', **kw) self.var = SCons.Util.to_String(var) self.gen_kw = kw @@ -946,7 +948,7 @@ class LazyAction(CommandGeneratorAction, CommandAction): else: c = '' #TODO(1.5) gen_cmd = Action(c, **self.gen_kw) - gen_cmd = apply(Action, (c,), self.gen_kw) + gen_cmd = Action(c, **self.gen_kw) if not gen_cmd: raise SCons.Errors.UserError("$%s value %s cannot be used to create an Action." % (self.var, repr(c))) return gen_cmd @@ -955,10 +957,8 @@ class LazyAction(CommandGeneratorAction, CommandAction): return self._generate_cache(env) def __call__(self, target, source, env, *args, **kw): - args = (self, target, source, env) + args c = self.get_parent_class(env) - #TODO(1.5) return c.__call__(*args, **kw) - return apply(c.__call__, args, kw) + return c.__call__(self, target, source, env, *args, **kw) def get_presig(self, target, source, env): c = self.get_parent_class(env) @@ -987,7 +987,7 @@ class FunctionAction(_ActionAction): self.funccontents = _object_contents(execfunction) #TODO(1.5) _ActionAction.__init__(self, **kw) - apply(_ActionAction.__init__, (self,), kw) + _ActionAction.__init__(self, **kw) def function_name(self): try: @@ -1018,7 +1018,7 @@ class FunctionAction(_ActionAction): else: s = str_for_display() return s - return '[' + string.join(map(quote, a), ", ") + ']' + return '[' + ", ".join(map(quote, a)) + ']' try: strfunc = self.execfunction.strfunction except AttributeError: @@ -1045,7 +1045,7 @@ class FunctionAction(_ActionAction): if executor: target = executor.get_all_targets() source = executor.get_all_sources() - rsources = map(rfile, source) + rsources = list(map(rfile, source)) try: result = self.execfunction(target=target, source=rsources, env=env) except KeyboardInterrupt, e: @@ -1095,40 +1095,34 @@ class FunctionAction(_ActionAction): class ListAction(ActionBase): """Class for lists of other actions.""" - def __init__(self, list): + def __init__(self, actionlist): if __debug__: logInstanceCreation(self, 'Action.ListAction') def list_of_actions(x): if isinstance(x, ActionBase): return x return Action(x) - self.list = map(list_of_actions, list) + self.list = list(map(list_of_actions, actionlist)) # our children will have had any varlist # applied; we don't need to do it again self.varlist = () self.targets = '$TARGETS' def genstring(self, target, source, env): - return string.join(map(lambda a, t=target, s=source, e=env: - a.genstring(t, s, e), - self.list), - '\n') + return '\n'.join([a.genstring(target, source, env) for a in self.list]) def __str__(self): - return string.join(map(str, self.list), '\n') + return '\n'.join(map(str, self.list)) def presub_lines(self, env): return SCons.Util.flatten_sequence( - map(lambda a, env=env: a.presub_lines(env), self.list)) + [a.presub_lines(env) for a in self.list]) def get_presig(self, target, source, env): """Return the signature contents of this action list. Simple concatenation of the signatures of the elements. """ - return string.join(map(lambda x, t=target, s=source, e=env: - x.get_contents(t, s, e), - self.list), - "") + return "".join([x.get_contents(target, source, env) for x in self.list]) def __call__(self, target, source, env, exitstatfunc=_null, presub=_null, show=_null, execute=_null, chdir=_null, executor=None): @@ -1204,9 +1198,7 @@ class ActionCaller: return self.parent.convert(s) def subst_args(self, target, source, env): - return map(lambda x, self=self, t=target, s=source, e=env: - self.subst(x, t, s, e), - self.args) + return [self.subst(x, target, source, env) for x in self.args] def subst_kw(self, target, source, env): kw = {} @@ -1218,17 +1210,17 @@ class ActionCaller: args = self.subst_args(target, source, env) kw = self.subst_kw(target, source, env) #TODO(1.5) return self.parent.actfunc(*args, **kw) - return apply(self.parent.actfunc, args, kw) + return self.parent.actfunc(*args, **kw) def strfunction(self, target, source, env): args = self.subst_args(target, source, env) kw = self.subst_kw(target, source, env) #TODO(1.5) return self.parent.strfunc(*args, **kw) - return apply(self.parent.strfunc, args, kw) + return self.parent.strfunc(*args, **kw) def __str__(self): #TODO(1.5) return self.parent.strfunc(*self.args, **self.kw) - return apply(self.parent.strfunc, self.args, self.kw) + return self.parent.strfunc(*self.args, **self.kw) class ActionFactory: """A factory class that will wrap up an arbitrary function diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index ef91af4..12756e5 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -37,7 +37,6 @@ class GlobalActFunc: import os import re import StringIO -import string import sys import types import unittest @@ -68,16 +67,16 @@ try: except: pass f.close() -if os.environ.has_key( 'ACTPY_PIPE' ): - if os.environ.has_key( 'PIPE_STDOUT_FILE' ): +if 'ACTPY_PIPE' in os.environ: + if 'PIPE_STDOUT_FILE' in os.environ: stdout_msg = open(os.environ['PIPE_STDOUT_FILE'], 'r').read() else: - stdout_msg = "act.py: stdout: executed act.py %s\\n" % string.join(sys.argv[1:]) + stdout_msg = "act.py: stdout: executed act.py %s\\n" % ' '.join(sys.argv[1:]) sys.stdout.write( stdout_msg ) - if os.environ.has_key( 'PIPE_STDERR_FILE' ): + if 'PIPE_STDERR_FILE' in os.environ: stderr_msg = open(os.environ['PIPE_STDERR_FILE'], 'r').read() else: - stderr_msg = "act.py: stderr: executed act.py %s\\n" % string.join(sys.argv[1:]) + stderr_msg = "act.py: stderr: executed act.py %s\\n" % ' '.join(sys.argv[1:]) sys.stderr.write( stderr_msg ) sys.exit(0) """) @@ -147,7 +146,7 @@ class Environment: def __setitem__(self, item, value): self.d[item] = value def has_key(self, item): - return self.d.has_key(item) + return item in self.d def get(self, key, value=None): return self.d.get(key, value) def items(self): @@ -193,7 +192,7 @@ _null = SCons.Action._null def test_varlist(pos_call, str_call, cmd, cmdstrfunc, **kw): def call_action(a, pos_call=pos_call, str_call=str_call, kw=kw): #FUTURE a = SCons.Action.Action(*a, **kw) - a = apply(SCons.Action.Action, a, kw) + a = SCons.Action.Action(*a, **kw) # returned object must provide these entry points assert hasattr(a, '__call__') assert hasattr(a, 'get_contents') @@ -229,7 +228,7 @@ def test_positional_args(pos_callback, cmd, **kw): """Test that Action() returns the expected type and that positional args work. """ #FUTURE act = SCons.Action.Action(cmd, **kw) - act = apply(SCons.Action.Action, (cmd,), kw) + act = SCons.Action.Action(cmd, **kw) pos_callback(act) assert act.varlist is (), act.varlist @@ -237,7 +236,7 @@ def test_positional_args(pos_callback, cmd, **kw): # only valid cmdstrfunc is None def none(a): pass #FUTURE test_varlist(pos_callback, none, cmd, None, **kw) - apply(test_varlist, (pos_callback, none, cmd, None), kw) + test_varlist(pos_callback, none, cmd, None, **kw) else: # _ActionAction should have set these assert hasattr(act, 'strfunction') @@ -251,29 +250,29 @@ def test_positional_args(pos_callback, cmd, **kw): assert hasattr(a, 'strfunction') assert a.cmdstr == 'cmdstr', a.cmdstr #FUTURE test_varlist(pos_callback, cmdstr, cmd, 'cmdstr', **kw) - apply(test_varlist, (pos_callback, cmdstr, cmd, 'cmdstr'), kw) + test_varlist(pos_callback, cmdstr, cmd, 'cmdstr', **kw) def fun(): pass def strfun(a, fun=fun): assert a.strfunction is fun, a.strfunction assert a.cmdstr == _null, a.cmdstr #FUTURE test_varlist(pos_callback, strfun, cmd, fun, **kw) - apply(test_varlist, (pos_callback, strfun, cmd, fun), kw) + test_varlist(pos_callback, strfun, cmd, fun, **kw) def none(a): assert hasattr(a, 'strfunction') assert a.cmdstr is None, a.cmdstr #FUTURE test_varlist(pos_callback, none, cmd, None, **kw) - apply(test_varlist, (pos_callback, none, cmd, None), kw) + test_varlist(pos_callback, none, cmd, None, **kw) """Test handling of bad cmdstrfunc arguments """ try: #FUTURE a = SCons.Action.Action(cmd, [], **kw) - a = apply(SCons.Action.Action, (cmd, []), kw) + a = SCons.Action.Action(cmd, [], **kw) except SCons.Errors.UserError, e: s = str(e) m = 'Invalid command display variable' - assert string.find(s, m) != -1, 'Unexpected string: %s' % s + assert s.find(m) != -1, 'Unexpected string: %s' % s else: raise Exception, "did not catch expected UserError" @@ -490,7 +489,7 @@ class _ActionActionTestCase(unittest.TestCase): except SCons.Errors.UserError, e: s = str(e) m = 'Cannot have both strfunction and cmdstr args to Action()' - assert string.find(s, m) != -1, 'Unexpected string: %s' % s + assert s.find(m) != -1, 'Unexpected string: %s' % s else: raise Exception, "did not catch expected UserError" @@ -752,8 +751,7 @@ class _ActionActionTestCase(unittest.TestCase): sum = act1 + act2 assert isinstance(sum, SCons.Action.ListAction), str(sum) assert len(sum.list) == 3, len(sum.list) - assert map(lambda x: isinstance(x, SCons.Action.ActionBase), - sum.list) == [ 1, 1, 1 ] + assert [isinstance(x, SCons.Action.ActionBase) for x in sum.list] == [ 1, 1, 1 ] sum = act1 + act1 assert isinstance(sum, SCons.Action.ListAction), str(sum) @@ -1050,7 +1048,7 @@ class CommandActionTestCase(unittest.TestCase): cmd3 = r'%s %s %s ${TARGETS}' % (_python_, act_py, outfile) act = SCons.Action.CommandAction(cmd3) - r = act(map(DummyNode, ['aaa', 'bbb']), [], env.Clone()) + r = act(list(map(DummyNode, ['aaa', 'bbb'])), [], env.Clone()) assert r == 0 c = test.read(outfile, 'r') assert c == "act.py: 'aaa' 'bbb'\n", c @@ -1077,7 +1075,7 @@ class CommandActionTestCase(unittest.TestCase): act = SCons.Action.CommandAction(cmd5) env5 = Environment() - if scons_env.has_key('ENV'): + if 'ENV' in scons_env: env5['ENV'] = scons_env['ENV'] PATH = scons_env['ENV'].get('PATH', '') else: @@ -1332,8 +1330,8 @@ class CommandActionTestCase(unittest.TestCase): # that scheme, then all of the '__t1__' and '__s6__' file names # in the asserts below would change to 't1' and 's6' and the # like. - t = map(DummyNode, ['t1', 't2', 't3', 't4', 't5', 't6']) - s = map(DummyNode, ['s1', 's2', 's3', 's4', 's5', 's6']) + t = list(map(DummyNode, ['t1', 't2', 't3', 't4', 't5', 't6'])) + s = list(map(DummyNode, ['s1', 's2', 's3', 's4', 's5', 's6'])) env = Environment() a = SCons.Action.CommandAction(["$TARGET"]) @@ -1528,7 +1526,7 @@ class CommandGeneratorActionTestCase(unittest.TestCase): def f_local(target, source, env, for_signature, LocalFunc=LocalFunc): return SCons.Action.Action(LocalFunc, varlist=['XYZ']) - matches_foo = map(lambda x: x + "foo", func_matches) + matches_foo = [x + "foo" for x in func_matches] a = self.factory(f_global) c = a.get_contents(target=[], source=[], env=env) @@ -1676,7 +1674,7 @@ class FunctionActionTestCase(unittest.TestCase): c = a.get_contents(target=[], source=[], env=Environment()) assert c in func_matches, repr(c) - matches_foo = map(lambda x: x + "foo", func_matches) + matches_foo = [x + "foo" for x in func_matches] a = factory(GlobalFunc, varlist=['XYZ']) c = a.get_contents(target=[], source=[], env=Environment()) @@ -1892,7 +1890,7 @@ class LazyActionTestCase(unittest.TestCase): c = a.get_contents(target=[], source=[], env=env) assert c in func_matches, repr(c) - matches_foo = map(lambda x: x + "foo", func_matches) + matches_foo = [x + "foo" for x in func_matches] env = Environment(FOO = factory(GlobalFunc, varlist=['XYZ'])) c = a.get_contents(target=[], source=[], env=env) @@ -2096,7 +2094,7 @@ if __name__ == "__main__": ActionCompareTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 6405da3..c999afd 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -97,6 +97,7 @@ There are the following methods for internal use within this module: # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -120,10 +121,9 @@ _null = _Null def match_splitext(path, suffixes = []): if suffixes: - matchsuf = filter(lambda S,path=path: path[-len(S):] == S, - suffixes) + matchsuf = [S for S in suffixes if path[-len(S):] == S] if matchsuf: - suf = max(map(None, map(len, matchsuf), matchsuf))[1] + suf = max(list(map(None, list(map(len, matchsuf)), matchsuf)))[1] return [path[:-len(suf)], path[-len(suf):]] return SCons.Util.splitext(path) @@ -156,14 +156,17 @@ class DictCmdGenerator(SCons.Util.Selector): for src in map(str, source): my_ext = match_splitext(src, suffixes)[1] if ext and my_ext != ext: - raise UserError("While building `%s' from `%s': Cannot build multiple sources with different extensions: %s, %s" % (repr(map(str, target)), src, ext, my_ext)) + raise UserError("While building `%s' from `%s': Cannot build multiple sources with different extensions: %s, %s" + % (repr(list(map(str, target))), src, ext, my_ext)) ext = my_ext else: ext = match_splitext(str(source[0]), self.src_suffixes())[1] if not ext: #return ext - raise UserError("While building `%s': Cannot deduce file extension from source files: %s" % (repr(map(str, target)), repr(map(str, source)))) + raise UserError("While building `%s': " + "Cannot deduce file extension from source files: %s" + % (repr(list(map(str, target))), repr(list(map(str, source))))) try: ret = SCons.Util.Selector.__call__(self, env, source, ext) @@ -171,7 +174,7 @@ class DictCmdGenerator(SCons.Util.Selector): raise UserError("Ambiguous suffixes after environment substitution: %s == %s == %s" % (e[0], e[1], e[2])) if ret is None: raise UserError("While building `%s' from `%s': Don't know how to build from a source file with suffix `%s'. Expected a suffix in this list: %s." % \ - (repr(map(str, target)), repr(map(str, source)), ext, repr(self.keys()))) + (repr(list(map(str, target))), repr(list(map(str, source))), ext, repr(self.keys()))) return ret class CallableSelector(SCons.Util.Selector): @@ -231,7 +234,7 @@ class OverrideWarner(UserDict.UserDict): if self.already_warned: return for k in self.keys(): - if misleading_keywords.has_key(k): + if k in misleading_keywords: alt = misleading_keywords[k] msg = "Did you mean to use `%s' instead of `%s'?" % (alt, k) SCons.Warnings.warn(SCons.Warnings.MisleadingKeywordsWarning, msg) @@ -240,14 +243,14 @@ class OverrideWarner(UserDict.UserDict): def Builder(**kw): """A factory for builder objects.""" composite = None - if kw.has_key('generator'): - if kw.has_key('action'): + if 'generator' in kw: + if 'action' in kw: raise UserError, "You must not specify both an action and a generator." kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator'], {}) del kw['generator'] - elif kw.has_key('action'): + elif 'action' in kw: source_ext_match = kw.get('source_ext_match', 1) - if kw.has_key('source_ext_match'): + if 'source_ext_match' in kw: del kw['source_ext_match'] if SCons.Util.is_Dict(kw['action']): composite = DictCmdGenerator(kw['action'], source_ext_match) @@ -256,7 +259,7 @@ def Builder(**kw): else: kw['action'] = SCons.Action.Action(kw['action']) - if kw.has_key('emitter'): + if 'emitter' in kw: emitter = kw['emitter'] if SCons.Util.is_String(emitter): # This allows users to pass in an Environment @@ -272,7 +275,7 @@ def Builder(**kw): elif SCons.Util.is_List(emitter): kw['emitter'] = ListEmitter(emitter) - result = apply(BuilderBase, (), kw) + result = BuilderBase(**kw) if not composite is None: result = CompositeBuilder(result, composite) @@ -308,15 +311,15 @@ def _node_errors(builder, env, tlist, slist): raise UserError, msg # TODO(batch): list constructed each time! if t.get_executor().get_all_targets() != tlist: - msg = "Two different target lists have a target in common: %s (from %s and from %s)" % (t, map(str, t.get_executor().get_all_targets()), map(str, tlist)) + msg = "Two different target lists have a target in common: %s (from %s and from %s)" % (t, list(map(str, t.get_executor().get_all_targets())), list(map(str, tlist))) raise UserError, msg elif t.sources != slist: - msg = "Multiple ways to build the same target were specified for: %s (from %s and from %s)" % (t, map(str, t.sources), map(str, slist)) + msg = "Multiple ways to build the same target were specified for: %s (from %s and from %s)" % (t, list(map(str, t.sources)), list(map(str, slist))) raise UserError, msg if builder.single_source: if len(slist) > 1: - raise UserError, "More than one source given for single-source builder: targets=%s sources=%s" % (map(str,tlist), map(str,slist)) + raise UserError, "More than one source given for single-source builder: targets=%s sources=%s" % (list(map(str,tlist)), list(map(str,slist))) class EmitterProxy: """This is a callable class that can act as a @@ -334,7 +337,7 @@ class EmitterProxy: # Recursively substitute the variable. # We can't use env.subst() because it deals only # in strings. Maybe we should change that? - while SCons.Util.is_String(emitter) and env.has_key(emitter): + while SCons.Util.is_String(emitter) and emitter in env: emitter = env[emitter] if callable(emitter): target, source = emitter(target, source, env) @@ -387,13 +390,13 @@ class BuilderBase: suffix = CallableSelector(suffix) self.env = env self.single_source = single_source - if overrides.has_key('overrides'): + if 'overrides' in overrides: SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning, "The \"overrides\" keyword to Builder() creation has been deprecated;\n" +\ "\tspecify the items as keyword arguments to the Builder() call instead.") overrides.update(overrides['overrides']) del overrides['overrides'] - if overrides.has_key('scanner'): + if 'scanner' in overrides: SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning, "The \"scanner\" keyword to Builder() creation has been deprecated;\n" "\tuse: source_scanner or target_scanner as appropriate.") @@ -493,7 +496,7 @@ class BuilderBase: except IndexError: tlist = [] else: - splitext = lambda S,self=self,env=env: self.splitext(S,env) + splitext = lambda S: self.splitext(S,env) tlist = [ t_from_s(pre, suf, splitext) ] else: target = self._adjustixes(target, pre, suf, self.ensure_suffix) @@ -574,7 +577,7 @@ class BuilderBase: if not self.action: fmt = "Builder %s must have an action to build %s." raise UserError, fmt % (self.get_name(env or self.env), - map(str,tlist)) + list(map(str,tlist))) key = self.action.batch_key(env or self.env, tlist, slist) if key: try: @@ -611,7 +614,7 @@ class BuilderBase: ekw = self.executor_kw.copy() ekw['chdir'] = chdir if kw: - if kw.has_key('srcdir'): + if 'srcdir' in kw: def prependDirIfRelative(f, srcdir=kw['srcdir']): import os.path if SCons.Util.is_String(f) and not os.path.isabs(f): @@ -619,7 +622,7 @@ class BuilderBase: return f if not SCons.Util.is_List(source): source = [source] - source = map(prependDirIfRelative, source) + source = list(map(prependDirIfRelative, source)) del kw['srcdir'] if self.overrides: env_kw = self.overrides.copy() @@ -658,9 +661,7 @@ class BuilderBase: src_suffix = [] elif not SCons.Util.is_List(src_suffix): src_suffix = [ src_suffix ] - adjust = lambda suf, s=self: \ - callable(suf) and suf or s.adjust_suffix(suf) - self.src_suffix = map(adjust, src_suffix) + self.src_suffix = [callable(suf) and suf or self.adjust_suffix(suf) for suf in src_suffix] def get_src_suffix(self, env): """Get the first src_suffix in the list of src_suffixes.""" @@ -723,7 +724,7 @@ class BuilderBase: lengths = list(set(map(len, src_suffixes))) def match_src_suffix(name, src_suffixes=src_suffixes, lengths=lengths): - node_suffixes = map(lambda l, n=name: n[-l:], lengths) + node_suffixes = [name[-l:] for l in lengths] for suf in src_suffixes: if suf in node_suffixes: return suf @@ -749,8 +750,7 @@ class BuilderBase: # target, then filter out any sources that this # Builder isn't capable of building. if len(tlist) > 1: - mss = lambda t, m=match_src_suffix: m(t.name) - tlist = filter(mss, tlist) + tlist = [t for t in tlist if match_src_suffix(t.name)] result.extend(tlist) else: result.append(s) @@ -819,7 +819,7 @@ class BuilderBase: return memo_dict[memo_key] except KeyError: pass - suffixes = map(lambda x, s=self, e=env: e.subst(x), self.src_suffix) + suffixes = [env.subst(x) for x in self.src_suffix] memo_dict[memo_key] = suffixes return suffixes @@ -838,7 +838,7 @@ class BuilderBase: sdict[s] = 1 for builder in self.get_src_builders(env): for s in builder.src_suffixes(env): - if not sdict.has_key(s): + if s not in sdict: sdict[s] = 1 suffixes.append(s) return suffixes diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index dc60d06..d14f777 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -118,14 +118,16 @@ class Environment: self.d[item] = var def __getitem__(self, item): return self.d[item] + def __contains__(self, item): + return self.d.__contains__(item) def has_key(self, item): - return self.d.has_key(item) + return item in self.d def keys(self): return self.d.keys() def get(self, key, value=None): return self.d.get(key, value) def Override(self, overrides): - env = apply(Environment, (), self.d) + env = Environment(**self.d) env.d.update(overrides) env.scanner = self.scanner return env @@ -255,7 +257,7 @@ class BuilderTestCase(unittest.TestCase): l.extend(ul) except TypeError: def mystr(l): - return str(map(str, l)) + return str(list(map(str, l))) else: mystr = str @@ -264,14 +266,14 @@ class BuilderTestCase(unittest.TestCase): tlist = builder(env, target = [nnn1, nnn2], source = []) s = mystr(tlist) assert s == "['nnn1', 'nnn2']", s - l = map(str, tlist) + l = list(map(str, tlist)) assert l == ['nnn1', 'nnn2'], l tlist = builder(env, target = 'n3', source = 'n4') s = mystr(tlist) assert s == "['n3']", s target = tlist[0] - l = map(str, tlist) + l = list(map(str, tlist)) assert l == ['n3'], l assert target.name == 'n3' assert target.sources[0].name == 'n4' @@ -279,7 +281,7 @@ class BuilderTestCase(unittest.TestCase): tlist = builder(env, target = 'n4 n5', source = ['n6 n7']) s = mystr(tlist) assert s == "['n4 n5']", s - l = map(str, tlist) + l = list(map(str, tlist)) assert l == ['n4 n5'], l target = tlist[0] assert target.name == 'n4 n5' @@ -288,7 +290,7 @@ class BuilderTestCase(unittest.TestCase): tlist = builder(env, target = ['n8 n9'], source = 'n10 n11') s = mystr(tlist) assert s == "['n8 n9']", s - l = map(str, tlist) + l = list(map(str, tlist)) assert l == ['n8 n9'], l target = tlist[0] assert target.name == 'n8 n9' @@ -618,7 +620,7 @@ class BuilderTestCase(unittest.TestCase): src_suffix='.obj', suffix='.exe') tgt = b2(env, target=None, source=['foo$OBJSUFFIX']) - s = map(str, tgt[0].sources) + s = list(map(str, tgt[0].sources)) assert s == ['foo.obj'], s def test_suffix(self): @@ -715,10 +717,10 @@ class BuilderTestCase(unittest.TestCase): # support anyway, don't bother trying to test for it. pass else: - s = map(str, tgts) + s = list(map(str, tgts)) expect = [test.workpath('2.out'), test.workpath('3.out')] - expect = map(os.path.normcase, expect) - assert map(os.path.normcase, s) == expect, s + expect = list(map(os.path.normcase, expect)) + assert list(map(os.path.normcase, s)) == expect, s for t in tgts: t.prepare() tgts[0].build() tgts[1].build() @@ -744,7 +746,7 @@ class BuilderTestCase(unittest.TestCase): for t in target: open(str(t), 'w').write("function2\n") for t in tlist: - if not t in map(str, target): + if not t in list(map(str, target)): open(t, 'w').write("function2\n") return 1 @@ -773,7 +775,7 @@ class BuilderTestCase(unittest.TestCase): for t in target: open(str(t), 'w').write("function3\n") for t in tlist: - if not t in map(str, target): + if not t in list(map(str, target)): open(t, 'w').write("function3\n") return 1 @@ -811,17 +813,17 @@ class BuilderTestCase(unittest.TestCase): tgt = builder2(env, target='baz', source=sources)[0] s = str(tgt) assert s == 'baz', s - s = map(str, tgt.sources) + s = list(map(str, tgt.sources)) assert s == ['test.foo', 'test2.foo', 'test3.txt', 'test4.foo'], s - s = map(str, tgt.sources[0].sources) + s = list(map(str, tgt.sources[0].sources)) assert s == ['test.bar'], s tgt = builder2(env, None, 'aaa.bar')[0] s = str(tgt) assert s == 'aaa', s - s = map(str, tgt.sources) + s = list(map(str, tgt.sources)) assert s == ['aaa.foo'], s - s = map(str, tgt.sources[0].sources) + s = list(map(str, tgt.sources[0].sources)) assert s == ['aaa.bar'], s builder3 = SCons.Builder.Builder(action='bld3') @@ -841,11 +843,11 @@ class BuilderTestCase(unittest.TestCase): tgt = builder6(env, 'test', 'test.i')[0] s = str(tgt) assert s == 'test.exe', s - s = map(str, tgt.sources) + s = list(map(str, tgt.sources)) assert s == ['test_wrap.obj'], s - s = map(str, tgt.sources[0].sources) + s = list(map(str, tgt.sources[0].sources)) assert s == ['test_wrap.c'], s - s = map(str, tgt.sources[0].sources[0].sources) + s = list(map(str, tgt.sources[0].sources[0].sources)) assert s == ['test.i'], s def test_target_scanner(self): @@ -1198,14 +1200,14 @@ class BuilderTestCase(unittest.TestCase): tgt = builder(env, target='foo3', source='bar', foo=1) assert len(tgt) == 2, len(tgt) - assert 'foo3' in map(str, tgt), map(str, tgt) - assert 'bar1' in map(str, tgt), map(str, tgt) + assert 'foo3' in list(map(str, tgt)), list(map(str, tgt)) + assert 'bar1' in list(map(str, tgt)), list(map(str, tgt)) tgt = builder(env, target='foo4', source='bar', bar=1)[0] assert str(tgt) == 'foo4', str(tgt) assert len(tgt.sources) == 2, len(tgt.sources) - assert 'baz' in map(str, tgt.sources), map(str, tgt.sources) - assert 'bar' in map(str, tgt.sources), map(str, tgt.sources) + assert 'baz' in list(map(str, tgt.sources)), list(map(str, tgt.sources)) + assert 'bar' in list(map(str, tgt.sources)), list(map(str, tgt.sources)) env2=Environment(FOO=emit) builder2=SCons.Builder.Builder(action='foo', @@ -1226,14 +1228,14 @@ class BuilderTestCase(unittest.TestCase): tgt = builder2(env2, target='foo6', source='bar', foo=2) assert len(tgt) == 2, len(tgt) - assert 'foo6' in map(str, tgt), map(str, tgt) - assert 'bar2' in map(str, tgt), map(str, tgt) + assert 'foo6' in list(map(str, tgt)), list(map(str, tgt)) + assert 'bar2' in list(map(str, tgt)), list(map(str, tgt)) tgt = builder2(env2, target='foo7', source='bar', bar=1)[0] assert str(tgt) == 'foo7', str(tgt) assert len(tgt.sources) == 2, len(tgt.sources) - assert 'baz' in map(str, tgt.sources), map(str, tgt.sources) - assert 'bar' in map(str, tgt.sources), map(str, tgt.sources) + assert 'baz' in list(map(str, tgt.sources)), list(map(str, tgt.sources)) + assert 'bar' in list(map(str, tgt.sources)), list(map(str, tgt.sources)) def test_emitter_preserve_builder(self): """Test an emitter not overwriting a newly-set builder""" @@ -1262,12 +1264,12 @@ class BuilderTestCase(unittest.TestCase): env = Environment() def emit4a(target, source, env): - source = map(str, source) - target = map(lambda x: 'emit4a-' + x[:-3], source) + source = list(map(str, source)) + target = ['emit4a-' + x[:-3] for x in source] return (target, source) def emit4b(target, source, env): - source = map(str, source) - target = map(lambda x: 'emit4b-' + x[:-3], source) + source = list(map(str, source)) + target = ['emit4b-' + x[:-3] for x in source] return (target, source) builder = SCons.Builder.Builder(action='foo', @@ -1283,8 +1285,8 @@ class BuilderTestCase(unittest.TestCase): assert str(tgt) == 'ccc', str(tgt) def emit4c(target, source, env): - source = map(str, source) - target = map(lambda x: 'emit4c-' + x[:-3], source) + source = list(map(str, source)) + target = ['emit4c-' + x[:-3] for x in source] return (target, source) builder.add_emitter('.4c', emit4c) @@ -1296,29 +1298,29 @@ class BuilderTestCase(unittest.TestCase): env = Environment() def emit1a(target, source, env): - source = map(str, source) - target = target + map(lambda x: 'emit1a-' + x[:-2], source) + source = list(map(str, source)) + target = target + ['emit1a-' + x[:-2] for x in source] return (target, source) def emit1b(target, source, env): - source = map(str, source) - target = target + map(lambda x: 'emit1b-' + x[:-2], source) + source = list(map(str, source)) + target = target + ['emit1b-' + x[:-2] for x in source] return (target, source) builder1 = SCons.Builder.Builder(action='foo', emitter=[emit1a, emit1b], node_factory=MyNode) tgts = builder1(env, target='target-1', source='aaa.1') - tgts = map(str, tgts) + tgts = list(map(str, tgts)) assert tgts == ['target-1', 'emit1a-aaa', 'emit1b-aaa'], tgts # Test a list of emitter functions through the environment. def emit2a(target, source, env): - source = map(str, source) - target = target + map(lambda x: 'emit2a-' + x[:-2], source) + source = list(map(str, source)) + target = target + ['emit2a-' + x[:-2] for x in source] return (target, source) def emit2b(target, source, env): - source = map(str, source) - target = target + map(lambda x: 'emit2b-' + x[:-2], source) + source = list(map(str, source)) + target = target + ['emit2b-' + x[:-2] for x in source] return (target, source) builder2 = SCons.Builder.Builder(action='foo', emitter='$EMITTERLIST', @@ -1327,7 +1329,7 @@ class BuilderTestCase(unittest.TestCase): env = Environment(EMITTERLIST = [emit2a, emit2b]) tgts = builder2(env, target='target-2', source='aaa.2') - tgts = map(str, tgts) + tgts = list(map(str, tgts)) assert tgts == ['target-2', 'emit2a-aaa', 'emit2b-aaa'], tgts def test_emitter_TARGET_SOURCE(self): @@ -1345,8 +1347,8 @@ class BuilderTestCase(unittest.TestCase): targets = builder(env, target = 'TTT', source ='SSS') sources = targets[0].sources - targets = map(str, targets) - sources = map(str, sources) + targets = list(map(str, targets)) + sources = list(map(str, sources)) assert targets == ['TTT', 'SSS.s1', 'TTT.t1'], targets assert sources == ['SSS', 'TTT.t2', 'SSS.s2'], targets @@ -1358,53 +1360,53 @@ class BuilderTestCase(unittest.TestCase): tgt = b(env, None, 'aaa')[0] assert str(tgt) == 'aaa.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'aaa', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'aaa', list(map(str, tgt.sources)) tgt = b(env, None, 'bbb.c')[0] assert str(tgt) == 'bbb.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'bbb.c', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'bbb.c', list(map(str, tgt.sources)) tgt = b(env, None, 'ccc.x.c')[0] assert str(tgt) == 'ccc.x.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'ccc.x.c', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'ccc.x.c', list(map(str, tgt.sources)) tgt = b(env, None, ['d0.c', 'd1.c'])[0] assert str(tgt) == 'd0.o', str(tgt) - assert len(tgt.sources) == 2, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'd0.c', map(str, tgt.sources) - assert str(tgt.sources[1]) == 'd1.c', map(str, tgt.sources) + assert len(tgt.sources) == 2, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'd0.c', list(map(str, tgt.sources)) + assert str(tgt.sources[1]) == 'd1.c', list(map(str, tgt.sources)) tgt = b(env, target = None, source='eee')[0] assert str(tgt) == 'eee.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'eee', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'eee', list(map(str, tgt.sources)) tgt = b(env, target = None, source='fff.c')[0] assert str(tgt) == 'fff.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'fff.c', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'fff.c', list(map(str, tgt.sources)) tgt = b(env, target = None, source='ggg.x.c')[0] assert str(tgt) == 'ggg.x.o', str(tgt) - assert len(tgt.sources) == 1, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'ggg.x.c', map(str, tgt.sources) + assert len(tgt.sources) == 1, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'ggg.x.c', list(map(str, tgt.sources)) tgt = b(env, target = None, source=['h0.c', 'h1.c'])[0] assert str(tgt) == 'h0.o', str(tgt) - assert len(tgt.sources) == 2, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'h0.c', map(str, tgt.sources) - assert str(tgt.sources[1]) == 'h1.c', map(str, tgt.sources) + assert len(tgt.sources) == 2, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'h0.c', list(map(str, tgt.sources)) + assert str(tgt.sources[1]) == 'h1.c', list(map(str, tgt.sources)) w = b(env, target='i0.w', source=['i0.x'])[0] y = b(env, target='i1.y', source=['i1.z'])[0] tgt = b(env, None, source=[w, y])[0] assert str(tgt) == 'i0.o', str(tgt) - assert len(tgt.sources) == 2, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'i0.w', map(str, tgt.sources) - assert str(tgt.sources[1]) == 'i1.y', map(str, tgt.sources) + assert len(tgt.sources) == 2, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'i0.w', list(map(str, tgt.sources)) + assert str(tgt.sources[1]) == 'i1.y', list(map(str, tgt.sources)) def test_get_name(self): """Test getting name of builder. @@ -1642,7 +1644,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/CacheDir.py b/src/engine/SCons/CacheDir.py index 73bfe6b..d585888 100644 --- a/src/engine/SCons/CacheDir.py +++ b/src/engine/SCons/CacheDir.py @@ -29,7 +29,6 @@ CacheDir support import os.path import stat -import string import sys import SCons.Action @@ -158,7 +157,7 @@ class CacheDir: return None, None sig = node.get_cachedir_bsig() - subdir = string.upper(sig[0]) + subdir = sig[0].upper() dir = os.path.join(self.path, subdir) return dir, os.path.join(dir, sig) diff --git a/src/engine/SCons/CacheDirTests.py b/src/engine/SCons/CacheDirTests.py index 5e63548..5447509 100644 --- a/src/engine/SCons/CacheDirTests.py +++ b/src/engine/SCons/CacheDirTests.py @@ -286,7 +286,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Conftest.py b/src/engine/SCons/Conftest.py index e995e77..9221e2f 100644 --- a/src/engine/SCons/Conftest.py +++ b/src/engine/SCons/Conftest.py @@ -101,7 +101,6 @@ Autoconf-like configuration support; low level implementation of tests. # import re -import string from types import IntType # @@ -230,7 +229,7 @@ int main() def _check_empty_program(context, comp, text, language, use_shared = False): """Return 0 on success, 1 otherwise.""" - if not context.env.has_key(comp) or not context.env[comp]: + if comp not in context.env or not context.env[comp]: # The compiler construction variable is not set or empty return 1 @@ -636,7 +635,7 @@ return 0; """ % (call or "") if call: - i = string.find(call, "\n") + i = call.find("\n") if i > 0: calltext = call[:i] + ".." elif call[-1] == ';': @@ -723,7 +722,7 @@ def _Have(context, key, have, comment = None): Give "have" as is should appear in the header file, include quotes when desired and escape special characters! """ - key_up = string.upper(key) + key_up = key.upper() key_up = re.sub('[^A-Z0-9_]', '_', key_up) context.havedict[key_up] = have if have == 1: @@ -755,7 +754,7 @@ def _LogFailed(context, text, msg): """ if LogInputFiles: context.Log("Failed program was:\n") - lines = string.split(text, '\n') + lines = text.split('\n') if len(lines) and lines[-1] == '': lines = lines[:-1] # remove trailing empty line n = 1 diff --git a/src/engine/SCons/Debug.py b/src/engine/SCons/Debug.py index 90e5a82..a6c0cb5 100644 --- a/src/engine/SCons/Debug.py +++ b/src/engine/SCons/Debug.py @@ -32,7 +32,6 @@ needed by most users. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os -import string import sys import time @@ -46,7 +45,7 @@ else: def logInstanceCreation(instance, name=None): if name is None: name = instance.__class__.__name__ - if not tracked_classes.has_key(name): + if name not in tracked_classes: tracked_classes[name] = [] tracked_classes[name].append(weakref.ref(instance)) @@ -60,11 +59,11 @@ def string_to_classes(s): c.sort() return c else: - return string.split(s) + return s.split() def fetchLoggedInstances(classes="*"): classnames = string_to_classes(classes) - return map(lambda cn: (cn, len(tracked_classes[cn])), classnames) + return [(cn, len(tracked_classes[cn])) for cn in classnames] def countLoggedInstances(classes, file=sys.stdout): for classname in string_to_classes(classes): @@ -94,7 +93,7 @@ if sys.platform[:5] == "linux": # Linux doesn't actually support memory usage stats from getrusage(). def memory(): mstr = open('/proc/self/stat').read() - mstr = string.split(mstr)[22] + mstr = mstr.split()[22] return int(mstr) else: try: @@ -156,7 +155,7 @@ def _dump_one_caller(key, file, level=0): leader = ' '*level for v,c in l: file.write("%s %6d %s:%d(%s)\n" % ((leader,-v) + func_shorten(c[-3:]))) - if caller_dicts.has_key(c): + if c in caller_dicts: _dump_one_caller(c, file, level+1) # print each call tree @@ -175,15 +174,12 @@ shorten_list = [ ] if os.sep != '/': - def platformize(t): - return (string.replace(t[0], '/', os.sep), t[1]) - shorten_list = map(platformize, shorten_list) - del platformize + shorten_list = [(t[0].replace('/', os.sep), t[1]) for t in shorten_list] def func_shorten(func_tuple): f = func_tuple[0] for t in shorten_list: - i = string.find(f, t[0]) + i = f.find(t[0]) if i >= 0: if t[1]: i = i + len(t[0]) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 7ce981d..2f48d0d 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -41,7 +41,6 @@ import os.path import errno import shutil import stat -import string import time import types import sys @@ -88,7 +87,7 @@ def DefaultEnvironment(*args, **kw): global _default_env if not _default_env: import SCons.Util - _default_env = apply(SCons.Environment.Environment, args, kw) + _default_env = SCons.Environment.Environment(*args, **kw) if SCons.Util.md5: _default_env.Decider('MD5') else: @@ -165,7 +164,7 @@ def get_paths_str(dest): elem_strs = [] for element in dest: elem_strs.append('"' + str(element) + '"') - return '[' + string.join(elem_strs, ', ') + ']' + return '[' + ', '.join(elem_strs) + ']' else: return '"' + str(dest) + '"' @@ -315,16 +314,16 @@ def _concat_ixes(prefix, list, suffix, env): return result -def _stripixes(prefix, list, suffix, stripprefixes, stripsuffixes, env, c=None): +def _stripixes(prefix, itms, suffix, stripprefixes, stripsuffixes, env, c=None): """ - This is a wrapper around _concat()/_concat_ixes() that checks for the - existence of prefixes or suffixes on list elements and strips them + This is a wrapper around _concat()/_concat_ixes() that checks for + the existence of prefixes or suffixes on list items and strips them where it finds them. This is used by tools (like the GNU linker) that need to turn something like 'libfoo.a' into '-lfoo'. """ - if not list: - return list + if not itms: + return itms if not callable(c): env_c = env['_concat'] @@ -337,11 +336,11 @@ def _stripixes(prefix, list, suffix, stripprefixes, stripsuffixes, env, c=None): else: c = _concat_ixes - stripprefixes = map(env.subst, SCons.Util.flatten(stripprefixes)) - stripsuffixes = map(env.subst, SCons.Util.flatten(stripsuffixes)) + stripprefixes = list(map(env.subst, SCons.Util.flatten(stripprefixes))) + stripsuffixes = list(map(env.subst, SCons.Util.flatten(stripsuffixes))) stripped = [] - for l in SCons.PathList.PathList(list).subst_path(env, None, None): + for l in SCons.PathList.PathList(itms).subst_path(env, None, None): if isinstance(l, SCons.Node.FS.File): stripped.append(l) continue @@ -446,11 +445,11 @@ class Variable_Method_Caller: frame = sys.exc_info()[2].tb_frame.f_back variable = self.variable while frame: - if frame.f_locals.has_key(variable): + if variable in frame.f_locals: v = frame.f_locals[variable] if v: method = getattr(v, self.method) - return apply(method, args, kw) + return method(*args, **kw) frame = frame.f_back return None diff --git a/src/engine/SCons/DefaultsTests.py b/src/engine/SCons/DefaultsTests.py index 3d9c1ee..8534cf8 100644 --- a/src/engine/SCons/DefaultsTests.py +++ b/src/engine/SCons/DefaultsTests.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import StringIO import sys import types @@ -83,7 +82,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index f840dfc..3ebba12 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -31,6 +31,7 @@ Environment # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -40,7 +41,6 @@ import os import sys import re import shlex -import string from UserDict import UserDict import SCons.Action @@ -98,11 +98,11 @@ def apply_tools(env, tools, toolpath): if not tools: return # Filter out null tools from the list. - for tool in filter(None, tools): + for tool in [_f for _f in tools if _f]: if SCons.Util.is_List(tool) or type(tool)==type(()): toolname = tool[0] toolargs = tool[1] # should be a dict of kw args - tool = apply(env.Tool, [toolname], toolargs) + tool = env.Tool(toolname, **toolargs) else: env.Tool(tool) @@ -173,7 +173,7 @@ def _delete_duplicates(l, keep_last): l.reverse() for i in l: try: - if not seen.has_key(i): + if i not in seen: result.append(i) seen[i]=1 except TypeError: @@ -221,7 +221,7 @@ class MethodWrapper: def __call__(self, *args, **kwargs): nargs = (self.object,) + args - return apply(self.method, nargs, kwargs) + return self.method(*nargs, **kwargs) def clone(self, new_object): """ @@ -257,7 +257,7 @@ class BuilderWrapper(MethodWrapper): target = [target] if source is not None and not SCons.Util.is_List(source): source = [source] - return apply(MethodWrapper.__call__, (self, target, source) + args, kw) + return MethodWrapper.__call__(self, target, source, *args, **kw) def __repr__(self): return '' % repr(self.name) @@ -290,7 +290,7 @@ class BuilderWrapper(MethodWrapper): # future, so leave it for now. #def execute(self, **kw): # kw['env'] = self.env - # apply(self.builder.execute, (), kw) + # self.builder.execute(**kw) class BuilderDict(UserDict): """This is a dictionary-like class used by an Environment to hold @@ -430,7 +430,7 @@ class SubstitutionEnvironment: # key and we don't need to check. If we do check, using a # global, pre-compiled regular expression directly is more # efficient than calling another function or a method. - if not self._dict.has_key(key) \ + if key not in self._dict \ and not _is_valid_var.match(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key self._dict[key] = value @@ -440,7 +440,7 @@ class SubstitutionEnvironment: return self._dict.get(key, default) def has_key(self, key): - return self._dict.has_key(key) + return key in self._dict def __contains__(self, key): return self._dict.__contains__(key) @@ -471,7 +471,7 @@ class SubstitutionEnvironment: if SCons.Util.is_String(n): # n = self.subst(n, raw=1, **kw) kw['raw'] = 1 - n = apply(self.subst, (n,), kw) + n = self.subst(n, **kw) if node_factory: n = node_factory(n) if SCons.Util.is_List(n): @@ -481,7 +481,7 @@ class SubstitutionEnvironment: elif node_factory: # v = node_factory(self.subst(v, raw=1, **kw)) kw['raw'] = 1 - v = node_factory(apply(self.subst, (v,), kw)) + v = node_factory(self.subst(v, **kw)) if SCons.Util.is_List(v): nodes.extend(v) else: @@ -566,7 +566,7 @@ class SubstitutionEnvironment: # We have an object plus a string, or multiple # objects that we need to smush together. No choice # but to make them into a string. - p = string.join(map(SCons.Util.to_String_for_subst, p), '') + p = ''.join(map(SCons.Util.to_String_for_subst, p)) else: p = s(p) r.append(p) @@ -587,7 +587,7 @@ class SubstitutionEnvironment: if not SCons.Util.is_List(command): kw['shell'] = True # run constructed command #TODO(1.5) p = SCons.Action._subproc(self, command, **kw) - p = apply(SCons.Action._subproc, (self, command), kw) + p = SCons.Action._subproc(self, command, **kw) out,err = p.communicate() status = p.wait() if err: @@ -610,8 +610,7 @@ class SubstitutionEnvironment: Removes the specified function's MethodWrapper from the added_methods list, so we don't re-bind it when making a clone. """ - is_not_func = lambda dm, f=function: not dm.method is f - self.added_methods = filter(is_not_func, self.added_methods) + self.added_methods = [dm for dm in self.added_methods if not dm.method is function] def Override(self, overrides): """ @@ -681,11 +680,11 @@ class SubstitutionEnvironment: # utility function to deal with -D option def append_define(name, dict = dict): - t = string.split(name, '=') + t = name.split('=') if len(t) == 1: dict['CPPDEFINES'].append(name) else: - dict['CPPDEFINES'].append([t[0], string.join(t[1:], '=')]) + dict['CPPDEFINES'].append([t[0], '='.join(t[1:])]) # Loop through the flags and add them to the appropriate option. # This tries to strike a balance between checking for all possible @@ -807,7 +806,7 @@ class SubstitutionEnvironment: if not SCons.Util.is_Dict(args): args = self.ParseFlags(args) if not unique: - apply(self.Append, (), args) + self.Append(**args) return self for key, value in args.items(): if not value: @@ -866,9 +865,9 @@ class SubstitutionEnvironment: # if not pathval: # continue # if prepend: -# apply(self.PrependENVPath, (pathname, pathval)) +# self.PrependENVPath(pathname, pathval) # else: -# apply(self.AppendENVPath, (pathname, pathval)) +# self.AppendENVPath(pathname, pathval) # Used by the FindSourceFiles() method, below. @@ -979,12 +978,12 @@ class Base(SubstitutionEnvironment): # Apply the passed-in and customizable variables to the # environment before calling the tools, because they may use # some of them during initialization. - if kw.has_key('options'): + if 'options' in kw: # Backwards compatibility: they may stll be using the # old "options" keyword. variables = kw['options'] del kw['options'] - apply(self.Replace, (), kw) + self.Replace(**kw) keys = kw.keys() if variables: keys = keys + variables.keys() @@ -1100,7 +1099,7 @@ class Base(SubstitutionEnvironment): for scanner in scanners: for k in scanner.get_skeys(self): if k and self['PLATFORM'] == 'win32': - k = string.lower(k) + k = k.lower() result[k] = scanner self._memo['_gsm'] = result @@ -1111,7 +1110,7 @@ class Base(SubstitutionEnvironment): """Find the appropriate scanner given a key (usually a file suffix). """ if skey and self['PLATFORM'] == 'win32': - skey = string.lower(skey) + skey = skey.lower() return self._gsm().get(skey) def scanner_map_delete(self, kw=None): @@ -1240,13 +1239,13 @@ class Base(SubstitutionEnvironment): """ orig = '' - if self._dict.has_key(envname) and self._dict[envname].has_key(name): + if envname in self._dict and name in self._dict[envname]: orig = self._dict[envname][name] nv = SCons.Util.AppendPath(orig, newpath, sep, delete_existing, canonicalize=self._canonicalize) - if not self._dict.has_key(envname): + if envname not in self._dict: self._dict[envname] = {} self._dict[envname][name] = nv @@ -1261,7 +1260,7 @@ class Base(SubstitutionEnvironment): for key, val in kw.items(): if SCons.Util.is_List(val): val = _delete_duplicates(val, delete_existing) - if not self._dict.has_key(key) or self._dict[key] in ('', None): + if key not in self._dict or self._dict[key] in ('', None): self._dict[key] = val elif SCons.Util.is_Dict(self._dict[key]) and \ SCons.Util.is_Dict(val): @@ -1271,9 +1270,9 @@ class Base(SubstitutionEnvironment): if not SCons.Util.is_List(dk): dk = [dk] if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] else: - val = filter(lambda x, dk=dk: x not in dk, val) + val = [x for x in val if x not in dk] self._dict[key] = dk + val else: dk = self._dict[key] @@ -1281,14 +1280,14 @@ class Base(SubstitutionEnvironment): # By elimination, val is not a list. Since dk is a # list, wrap val in a list first. if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] self._dict[key] = dk + [val] else: if not val in dk: self._dict[key] = dk + [val] else: if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] self._dict[key] = dk + val self.scanner_map_delete(kw) @@ -1327,12 +1326,12 @@ class Base(SubstitutionEnvironment): new = {} for key, value in kw.items(): new[key] = SCons.Subst.scons_subst_once(value, self, key) - apply(clone.Replace, (), new) + clone.Replace(**new) apply_tools(clone, tools, toolpath) # apply them again in case the tools overwrote them - apply(clone.Replace, (), new) + clone.Replace(**new) # Finally, apply any flags to be merged in if parse_flags: clone.MergeFlags(parse_flags) @@ -1346,7 +1345,7 @@ class Base(SubstitutionEnvironment): msg = "The env.Copy() method is deprecated; use the env.Clone() method instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedCopyWarning, msg) _warn_copy_deprecated = False - return apply(self.Clone, args, kw) + return self.Clone(*args, **kw) def _changed_build(self, dependency, target, prev_ni): if dependency.changed_state(target, prev_ni): @@ -1416,7 +1415,7 @@ class Base(SubstitutionEnvironment): def Dictionary(self, *args): if not args: return self._dict - dlist = map(lambda x, s=self: s._dict[x], args) + dlist = [self._dict[x] for x in args] if len(dlist) == 1: dlist = dlist[0] return dlist @@ -1472,7 +1471,7 @@ class Base(SubstitutionEnvironment): return env.MergeFlags(cmd, unique) function = parse_conf if SCons.Util.is_List(command): - command = string.join(command) + command = ' '.join(command) command = self.subst(command) return function(self, self.backtick(command)) @@ -1494,11 +1493,11 @@ class Base(SubstitutionEnvironment): raise return lines = SCons.Util.LogicalLines(fp).readlines() - lines = filter(lambda l: l[0] != '#', lines) + lines = [l for l in lines if l[0] != '#'] tdlist = [] for line in lines: try: - target, depends = string.split(line, ':', 1) + target, depends = line.split(':', 1) except (AttributeError, TypeError, ValueError): # Python 1.5.2 throws TypeError if line isn't a string, # Python 2.x throws AttributeError because it tries @@ -1506,11 +1505,13 @@ class Base(SubstitutionEnvironment): # if the line doesn't split into two or more elements. pass else: - tdlist.append((string.split(target), string.split(depends))) + tdlist.append((target.split(), depends.split())) if only_one: - targets = reduce(lambda x, y: x+y, map(lambda p: p[0], tdlist)) + targets = reduce(lambda x, y: x+y, [p[0] for p in tdlist]) if len(targets) > 1: - raise SCons.Errors.UserError, "More than one dependency target found in `%s': %s" % (filename, targets) + raise SCons.Errors.UserError( + "More than one dependency target found in `%s': %s" + % (filename, targets)) for target, depends in tdlist: self.Depends(target, depends) @@ -1596,13 +1597,13 @@ class Base(SubstitutionEnvironment): """ orig = '' - if self._dict.has_key(envname) and self._dict[envname].has_key(name): + if envname in self._dict and name in self._dict[envname]: orig = self._dict[envname][name] nv = SCons.Util.PrependPath(orig, newpath, sep, delete_existing, canonicalize=self._canonicalize) - if not self._dict.has_key(envname): + if envname not in self._dict: self._dict[envname] = {} self._dict[envname][name] = nv @@ -1617,7 +1618,7 @@ class Base(SubstitutionEnvironment): for key, val in kw.items(): if SCons.Util.is_List(val): val = _delete_duplicates(val, not delete_existing) - if not self._dict.has_key(key) or self._dict[key] in ('', None): + if key not in self._dict or self._dict[key] in ('', None): self._dict[key] = val elif SCons.Util.is_Dict(self._dict[key]) and \ SCons.Util.is_Dict(val): @@ -1627,9 +1628,9 @@ class Base(SubstitutionEnvironment): if not SCons.Util.is_List(dk): dk = [dk] if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] else: - val = filter(lambda x, dk=dk: x not in dk, val) + val = [x for x in val if x not in dk] self._dict[key] = val + dk else: dk = self._dict[key] @@ -1637,14 +1638,14 @@ class Base(SubstitutionEnvironment): # By elimination, val is not a list. Since dk is a # list, wrap val in a list first. if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] self._dict[key] = [val] + dk else: if not val in dk: self._dict[key] = [val] + dk else: if delete_existing: - dk = filter(lambda x, val=val: x not in val, dk) + dk = [x for x in dk if x not in val] self._dict[key] = val + dk self.scanner_map_delete(kw) @@ -1690,9 +1691,9 @@ class Base(SubstitutionEnvironment): def SetDefault(self, **kw): for k in kw.keys(): - if self._dict.has_key(k): + if k in self._dict: del kw[k] - apply(self.Replace, (), kw) + self.Replace(**kw) def _find_toolpath_dir(self, tp): return self.fs.Dir(self.subst(tp)).srcnode().abspath @@ -1702,8 +1703,8 @@ class Base(SubstitutionEnvironment): tool = self.subst(tool) if toolpath is None: toolpath = self.get('toolpath', []) - toolpath = map(self._find_toolpath_dir, toolpath) - tool = apply(SCons.Tool.Tool, (tool, toolpath), kw) + toolpath = list(map(self._find_toolpath_dir, toolpath)) + tool = SCons.Tool.Tool(tool, toolpath, **kw) tool(self) def WhereIs(self, prog, path=None, pathext=None, reject=[]): @@ -1741,15 +1742,15 @@ class Base(SubstitutionEnvironment): if SCons.Util.is_String(a): a = self.subst(a) return a - nargs = map(subst_string, args) + nargs = list(map(subst_string, args)) nkw = self.subst_kw(kw) - return apply(SCons.Action.Action, nargs, nkw) + return SCons.Action.Action(*nargs, **nkw) def AddPreAction(self, files, action): nodes = self.arg2nodes(files, self.fs.Entry) action = SCons.Action.Action(action) uniq = {} - for executor in map(lambda n: n.get_executor(), nodes): + for executor in [n.get_executor() for n in nodes]: uniq[executor] = 1 for executor in uniq.keys(): executor.add_pre_action(action) @@ -1759,7 +1760,7 @@ class Base(SubstitutionEnvironment): nodes = self.arg2nodes(files, self.fs.Entry) action = SCons.Action.Action(action) uniq = {} - for executor in map(lambda n: n.get_executor(), nodes): + for executor in [n.get_executor() for n in nodes]: uniq[executor] = 1 for executor in uniq.keys(): executor.add_post_action(action) @@ -1769,7 +1770,7 @@ class Base(SubstitutionEnvironment): tlist = self.arg2nodes(target, self.ans.Alias) if not SCons.Util.is_List(source): source = [source] - source = filter(None, source) + source = [_f for _f in source if _f] if not action: if not source: @@ -1796,7 +1797,7 @@ class Base(SubstitutionEnvironment): 'multi' : 1, 'is_explicit' : None, }) - bld = apply(SCons.Builder.Builder, (), nkw) + bld = SCons.Builder.Builder(**nkw) # Apply the Builder separately to each target so that the Aliases # stay separate. If we did one "normal" Builder call with the @@ -1813,7 +1814,7 @@ class Base(SubstitutionEnvironment): b = bld else: nkw['action'] = b.action + action - b = apply(SCons.Builder.Builder, (), nkw) + b = SCons.Builder.Builder(**nkw) t.convert() result.extend(b(self, t, t.sources + source)) return result @@ -1827,14 +1828,14 @@ class Base(SubstitutionEnvironment): return tlist def BuildDir(self, *args, **kw): - if kw.has_key('build_dir'): + if 'build_dir' in kw: kw['variant_dir'] = kw['build_dir'] del kw['build_dir'] - return apply(self.VariantDir, args, kw) + return self.VariantDir(*args, **kw) def Builder(self, **kw): nkw = self.subst_kw(kw) - return apply(SCons.Builder.Builder, [], nkw) + return SCons.Builder.Builder(**nkw) def CacheDir(self, path): import SCons.CacheDir @@ -1862,7 +1863,7 @@ class Base(SubstitutionEnvironment): nkw['custom_tests'] = self.subst_kw(nkw['custom_tests']) except KeyError: pass - return apply(SCons.SConf.SConf, nargs, nkw) + return SCons.SConf.SConf(*nargs, **nkw) def Command(self, target, source, action, **kw): """Builds the supplied target files from the supplied @@ -1877,8 +1878,8 @@ class Base(SubstitutionEnvironment): try: bkw['source_scanner'] = kw['source_scanner'] except KeyError: pass else: del kw['source_scanner'] - bld = apply(SCons.Builder.Builder, (), bkw) - return apply(bld, (self, target, source), kw) + bld = SCons.Builder.Builder(**bkw) + return bld(self, target, source, **kw) def Depends(self, target, dependency): """Explicity specify that 'target's depend on 'dependency'.""" @@ -1895,9 +1896,9 @@ class Base(SubstitutionEnvironment): if SCons.Util.is_Sequence(s): result=[] for e in s: - result.append(apply(self.fs.Dir, (e,) + args, kw)) + result.append(self.fs.Dir(e, *args, **kw)) return result - return apply(self.fs.Dir, (s,) + args, kw) + return self.fs.Dir(s, *args, **kw) def NoClean(self, *targets): """Tags a target so that it will not be cleaned by -c""" @@ -1924,17 +1925,17 @@ class Base(SubstitutionEnvironment): if SCons.Util.is_Sequence(s): result=[] for e in s: - result.append(apply(self.fs.Entry, (e,) + args, kw)) + result.append(self.fs.Entry(e, *args, **kw)) return result - return apply(self.fs.Entry, (s,) + args, kw) + return self.fs.Entry(s, *args, **kw) def Environment(self, **kw): - return apply(SCons.Environment.Environment, [], self.subst_kw(kw)) + return SCons.Environment.Environment(**self.subst_kw(kw)) def Execute(self, action, *args, **kw): """Directly execute an action through an Environment """ - action = apply(self.Action, (action,) + args, kw) + action = self.Action(action, *args, **kw) result = action([], [], self) if isinstance(result, SCons.Errors.BuildError): errstr = result.errstr @@ -1952,9 +1953,9 @@ class Base(SubstitutionEnvironment): if SCons.Util.is_Sequence(s): result=[] for e in s: - result.append(apply(self.fs.File, (e,) + args, kw)) + result.append(self.fs.File(e, *args, **kw)) return result - return apply(self.fs.File, (s,) + args, kw) + return self.fs.File(s, *args, **kw) def FindFile(self, file, dirs): file = self.subst(file) @@ -1965,7 +1966,7 @@ class Base(SubstitutionEnvironment): return SCons.Util.flatten(sequence) def GetBuildPath(self, files): - result = map(str, self.arg2nodes(files, self.fs.Entry)) + result = list(map(str, self.arg2nodes(files, self.fs.Entry))) if SCons.Util.is_List(files): return result else: @@ -2007,7 +2008,7 @@ class Base(SubstitutionEnvironment): def Repository(self, *dirs, **kw): dirs = self.arg2nodes(list(dirs), self.fs.Dir) - apply(self.fs.Repository, dirs, kw) + self.fs.Repository(*dirs, **kw) def Requires(self, target, prerequisite): """Specify that 'prerequisite' must be built before 'target', @@ -2026,7 +2027,7 @@ class Base(SubstitutionEnvironment): arg = self.subst(arg) nargs.append(arg) nkw = self.subst_kw(kw) - return apply(SCons.Scanner.Base, nargs, nkw) + return SCons.Scanner.Base(*nargs, **nkw) def SConsignFile(self, name=".sconsign", dbm_module=None): if name is not None: @@ -2093,9 +2094,9 @@ class Base(SubstitutionEnvironment): in the list are not split at spaces. In all cases, the function returns a list of Nodes and strings.""" if SCons.Util.is_List(arg): - return map(self.subst, arg) + return list(map(self.subst, arg)) elif SCons.Util.is_String(arg): - return string.split(self.subst(arg)) + return self.subst(arg).split() else: return [self.subst(arg)] @@ -2235,7 +2236,7 @@ class OverrideEnvironment(Base): self.__dict__['overrides'][key] return 1 except KeyError: - return self.__dict__['__subject'].has_key(key) + return key in self.__dict__['__subject'] def __contains__(self, key): if self.__dict__['overrides'].__contains__(key): return 1 @@ -2314,13 +2315,13 @@ def NoSubstitutionProxy(subject): nkw = kwargs.copy() nkw['gvars'] = {} self.raw_to_mode(nkw) - return apply(SCons.Subst.scons_subst_list, nargs, nkw) + return SCons.Subst.scons_subst_list(*nargs, **nkw) def subst_target_source(self, string, *args, **kwargs): nargs = (string, self,) + args nkw = kwargs.copy() nkw['gvars'] = {} self.raw_to_mode(nkw) - return apply(SCons.Subst.scons_subst, nargs, nkw) + return SCons.Subst.scons_subst(*nargs, **nkw) return _NoSubstitutionProxy(subject) # Local Variables: diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index aa80952..7d3d33e 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import copy import os -import string import StringIO import sys import TestCmd @@ -44,14 +43,14 @@ def diff_env(env1, env2): keys = d.keys() keys.sort() for k in keys: - if env1.has_key(k): - if env2.has_key(k): + if k in env1: + if k in env2: if env1[k] != env2[k]: s1 = s1 + " " + repr(k) + " : " + repr(env1[k]) + "\n" s2 = s2 + " " + repr(k) + " : " + repr(env2[k]) + "\n" else: s1 = s1 + " " + repr(k) + " : " + repr(env1[k]) + "\n" - elif env2.has_key(k): + elif k in env2: s2 = s2 + " " + repr(k) + " : " + repr(env2[k]) + "\n" s1 = s1 + "}\n" s2 = s2 + "}\n" @@ -66,14 +65,14 @@ def diff_dict(d1, d2): keys = d.keys() keys.sort() for k in keys: - if d1.has_key(k): - if d2.has_key(k): + if k in d1: + if k in d2: if d1[k] != d2[k]: s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n" s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n" else: s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n" - elif env2.has_key(k): + elif k in env2: s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n" s1 = s1 + "}\n" s2 = s2 + "}\n" @@ -132,7 +131,7 @@ class Scanner: class CLVar(UserList.UserList): def __init__(self, seq): if type(seq) == type(''): - seq = string.split(seq) + seq = seq.split() UserList.UserList.__init__(self, seq) def __add__(self, other): return UserList.UserList.__add__(self, CLVar(other)) @@ -158,15 +157,15 @@ def test_tool( env ): class TestEnvironmentFixture: def TestEnvironment(self, *args, **kw): - if not kw or not kw.has_key('tools'): + if not kw or 'tools' not in kw: kw['tools'] = [test_tool] default_keys = { 'CC' : 'cc', 'CCFLAGS' : '-DNDEBUG', 'ENV' : { 'TMP' : '/tmp' } } for key, value in default_keys.items(): - if not kw.has_key(key): + if key not in kw: kw[key] = value - if not kw.has_key('BUILDERS'): + if 'BUILDERS' not in kw: static_obj = SCons.Builder.Builder(action = {}, emitter = {}, suffix = '.o', @@ -174,7 +173,7 @@ class TestEnvironmentFixture: kw['BUILDERS'] = {'Object' : static_obj} static_obj.add_action('.cpp', 'fake action') - env = apply(Environment, args, kw) + env = Environment(*args, **kw) return env class SubstitutionTestCase(unittest.TestCase): @@ -183,7 +182,7 @@ class SubstitutionTestCase(unittest.TestCase): """Test initializing a SubstitutionEnvironment """ env = SubstitutionEnvironment() - assert not env.has_key('__env__') + assert '__env__' not in env def test___cmp__(self): """Test comparing SubstitutionEnvironments @@ -231,8 +230,8 @@ class SubstitutionTestCase(unittest.TestCase): """Test the SubstitutionEnvironment has_key() method """ env = SubstitutionEnvironment(XXX = 'x') - assert env.has_key('XXX') - assert not env.has_key('YYY') + assert 'XXX' in env + assert 'YYY' not in env def test_contains(self): """Test the SubstitutionEnvironment __contains__() method @@ -264,7 +263,7 @@ class SubstitutionTestCase(unittest.TestCase): class X(SCons.Node.Node): pass def Factory(name, directory = None, create = 1, dict=dict, X=X): - if not dict.has_key(name): + if name not in dict: dict[name] = X() dict[name].name = name return dict[name] @@ -390,7 +389,7 @@ class SubstitutionTestCase(unittest.TestCase): DummyNode, target=targets, source=sources) - names = map(lambda n: n.name, nodes) + names = [n.name for n in nodes] assert names == ['t1-a', 's1-b', 't2-c', 's2-d'], names def test_gvars(self): @@ -577,16 +576,16 @@ class SubstitutionTestCase(unittest.TestCase): assert r == ['foo', 'xxx', 'bar'], r r = env.subst_path(['$FOO', '$LIST', '$BAR']) - assert map(str, r) == ['foo', 'one two', 'bar'], r + assert list(map(str, r)) == ['foo', 'one two', 'bar'], r r = env.subst_path(['$FOO', '$TARGET', '$SOURCE', '$BAR']) assert r == ['foo', '', '', 'bar'], r r = env.subst_path(['$FOO', '$TARGET', '$BAR'], target=MyNode('ttt')) - assert map(str, r) == ['foo', 'ttt', 'bar'], r + assert list(map(str, r)) == ['foo', 'ttt', 'bar'], r r = env.subst_path(['$FOO', '$SOURCE', '$BAR'], source=MyNode('sss')) - assert map(str, r) == ['foo', 'sss', 'bar'], r + assert list(map(str, r)) == ['foo', 'sss', 'bar'], r n = MyObj() @@ -830,7 +829,7 @@ sys.exit(0) assert d['LIBPATH'] == ['/usr/fax', 'foo', 'C:\\Program Files\\ASCEND'], d['LIBPATH'] - LIBS = map(str, d['LIBS']) + LIBS = list(map(str, d['LIBS'])) assert LIBS == ['xxx', 'yyy', 'ascend'], (d['LIBS'], LIBS) assert d['LINKFLAGS'] == ['-Wl,-link', '-pthread', '-mno-cygwin', '-mwindows', @@ -845,7 +844,7 @@ sys.exit(0) """ env = SubstitutionEnvironment() env.MergeFlags('') - assert not env.has_key('CCFLAGS'), env['CCFLAGS'] + assert 'CCFLAGS' not in env, env['CCFLAGS'] env.MergeFlags('-X') assert env['CCFLAGS'] == ['-X'], env['CCFLAGS'] env.MergeFlags('-X') @@ -909,8 +908,8 @@ class BaseTestCase(unittest.TestCase,TestEnvironmentFixture): env2 = self.TestEnvironment(XXX = 'x', YYY = 'y') assert env1 == env2, diff_env(env1, env2) - assert not env1.has_key('__env__') - assert not env2.has_key('__env__') + assert '__env__' not in env1 + assert '__env__' not in env2 def test_variables(self): """Test that variables only get applied once.""" @@ -1088,69 +1087,69 @@ env4.builder1.env, env3) env = Environment() try: del env['SCANNERS'] except KeyError: pass - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [None, None, None, None, None], s env = self.TestEnvironment(SCANNERS = []) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [None, None, None, None, None], s env.Replace(SCANNERS = [s1]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, None, None], s env.Append(SCANNERS = [s2]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, s2, None], s env.AppendUnique(SCANNERS = [s3]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, s2, s3], s env = env.Clone(SCANNERS = [s2]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [None, None, None, s2, None], s env['SCANNERS'] = [s1] - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, None, None], s env.PrependUnique(SCANNERS = [s2, s1]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, s2, None], s env.Prepend(SCANNERS = [s3]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, s3, s3], s # Verify behavior of case-insensitive suffix matches on Windows. - uc_suffixes = map(string.upper, suffixes) + uc_suffixes = [_.upper() for _ in suffixes] env = Environment(SCANNERS = [s1, s2, s3], PLATFORM = 'linux') - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [s1, s1, None, s2, s3], s - s = map(env.get_scanner, uc_suffixes) + s = list(map(env.get_scanner, uc_suffixes)) assert s == [None, None, None, None, None], s env['PLATFORM'] = 'win32' - s = map(env.get_scanner, uc_suffixes) + s = list(map(env.get_scanner, uc_suffixes)) assert s == [s1, s1, None, s2, s3], s # Verify behavior for a scanner returning None (on Windows # where we might try to perform case manipulation on None). env.Replace(SCANNERS = [s4]) - s = map(env.get_scanner, suffixes) + s = list(map(env.get_scanner, suffixes)) assert s == [None, None, None, None, None], s def test_ENV(self): """Test setting the external ENV in Environments """ env = Environment() - assert env.Dictionary().has_key('ENV') + assert 'ENV' in env.Dictionary() env = self.TestEnvironment(ENV = { 'PATH' : '/foo:/bar' }) assert env.Dictionary('ENV')['PATH'] == '/foo:/bar' @@ -1182,7 +1181,7 @@ env4.builder1.env, env3) except warning: exc_caught = 1 assert exc_caught, "Did not catch ReservedVariableWarning for `%s'" % kw - assert not env4.has_key(kw), "`%s' variable was incorrectly set" % kw + assert kw not in env4, "`%s' variable was incorrectly set" % kw finally: SCons.Warnings.warningAsException(old) @@ -1204,7 +1203,7 @@ env4.builder1.env, env3) except warning: exc_caught = 1 assert exc_caught, "Did not catch FutureReservedVariableWarning for `%s'" % kw - assert env4.has_key(kw), "`%s' variable was not set" % kw + assert kw in env4, "`%s' variable was not set" % kw finally: SCons.Warnings.warningAsException(old) @@ -1233,7 +1232,7 @@ env4.builder1.env, env3) path = drive + path path = os.path.normpath(path) drive, path = os.path.splitdrive(path) - return string.lower(drive) + path + return drive.lower() + path env = dict.TestEnvironment(LIBS = [ 'foo', 'bar', 'baz' ], LIBLINKPREFIX = 'foo', @@ -1310,7 +1309,7 @@ env4.builder1.env, env3) if arg not in ('$(','$)','-I'): return np(str(arg)) return arg - flags = map(normalize_if_path, flags) + flags = list(map(normalize_if_path, flags)) assert flags == expect, flags def test_platform(self): @@ -1776,8 +1775,8 @@ def exists(env): assert env1.Dictionary('XXX') is env2.Dictionary('XXX') assert 4 in env2.Dictionary('YYY') assert not 4 in env1.Dictionary('YYY') - assert env2.Dictionary('ZZZ').has_key(5) - assert not env1.Dictionary('ZZZ').has_key(5) + assert 5 in env2.Dictionary('ZZZ') + assert 5 not in env1.Dictionary('ZZZ') # env1 = self.TestEnvironment(BUILDERS = {'b1' : Builder()}) @@ -1953,16 +1952,16 @@ def generate(env): xxx, zzz = env.Dictionary('XXX', 'ZZZ') assert xxx == 'x' assert zzz == 'z' - assert env.Dictionary().has_key('BUILDERS') - assert env.Dictionary().has_key('CC') - assert env.Dictionary().has_key('CCFLAGS') - assert env.Dictionary().has_key('ENV') + assert 'BUILDERS' in env.Dictionary() + assert 'CC' in env.Dictionary() + assert 'CCFLAGS' in env.Dictionary() + assert 'ENV' in env.Dictionary() assert env['XXX'] == 'x' env['XXX'] = 'foo' assert env.Dictionary('XXX') == 'foo' del env['XXX'] - assert not env.Dictionary().has_key('XXX') + assert 'XXX' not in env.Dictionary() def test_FindIxes(self): "Test FindIxes()" @@ -2105,8 +2104,8 @@ f5: \ del dlist[:] env.ParseDepends('$SINGLE', only_one=1) - t = map(str, tlist) - d = map(str, dlist) + t = list(map(str, tlist)) + d = list(map(str, dlist)) assert t == ['f0'], t assert d == ['d1', 'd2', 'd3'], d @@ -2114,8 +2113,8 @@ f5: \ del dlist[:] env.ParseDepends(test.workpath('multiple')) - t = map(str, tlist) - d = map(str, dlist) + t = list(map(str, tlist)) + d = list(map(str, dlist)) assert t == ['f1', 'f2', 'f3', 'f4', 'f5'], t assert d == ['foo', 'bar', 'abc', 'def', 'ghi', 'jkl', 'mno'], d @@ -2519,21 +2518,21 @@ def generate(env): test.workpath('sub2'), test.workpath('sub3'), test.workpath('sub4'), - ] + string.split(env_path, os.pathsep) + ] + env_path.split(os.pathsep) pathdirs_1243 = [ test.workpath('sub1'), test.workpath('sub2'), test.workpath('sub4'), test.workpath('sub3'), - ] + string.split(env_path, os.pathsep) + ] + env_path.split(os.pathsep) - path = string.join(pathdirs_1234, os.pathsep) + path = os.pathsep.join(pathdirs_1234) env = self.TestEnvironment(ENV = {'PATH' : path}) wi = env.WhereIs('xxx.exe') assert wi == test.workpath(sub3_xxx_exe), wi wi = env.WhereIs('xxx.exe', pathdirs_1243) assert wi == test.workpath(sub4_xxx_exe), wi - wi = env.WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep)) + wi = env.WhereIs('xxx.exe', os.pathsep.join(pathdirs_1243)) assert wi == test.workpath(sub4_xxx_exe), wi wi = env.WhereIs('xxx.exe', reject = sub3_xxx_exe) @@ -2541,13 +2540,13 @@ def generate(env): wi = env.WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe) assert wi == test.workpath(sub4_xxx_exe), wi - path = string.join(pathdirs_1243, os.pathsep) + path = os.pathsep.join(pathdirs_1243) env = self.TestEnvironment(ENV = {'PATH' : path}) wi = env.WhereIs('xxx.exe') assert wi == test.workpath(sub4_xxx_exe), wi wi = env.WhereIs('xxx.exe', pathdirs_1234) assert wi == test.workpath(sub3_xxx_exe), wi - wi = env.WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep)) + wi = env.WhereIs('xxx.exe', os.pathsep.join(pathdirs_1234)) assert wi == test.workpath(sub3_xxx_exe), wi if sys.platform == 'win32': @@ -2558,13 +2557,13 @@ def generate(env): assert wi == test.workpath(sub4_xxx_exe), wi wi = env.WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE') - assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi # Test that we return a normalized path even when # the path contains forward slashes. forward_slash = test.workpath('') + '/sub3' wi = env.WhereIs('xxx', path = forward_slash, pathext = '.EXE') - assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi + assert wi.lower() == test.workpath(sub3_xxx_exe).lower(), wi @@ -2637,37 +2636,37 @@ def generate(env): tgt = env.Alias('export_alias', [ 'asrc1', '$FOO' ])[0] assert str(tgt) == 'export_alias', tgt - assert len(tgt.sources) == 2, map(str, tgt.sources) - assert str(tgt.sources[0]) == 'asrc1', map(str, tgt.sources) - assert str(tgt.sources[1]) == 'kkk', map(str, tgt.sources) + assert len(tgt.sources) == 2, list(map(str, tgt.sources)) + assert str(tgt.sources[0]) == 'asrc1', list(map(str, tgt.sources)) + assert str(tgt.sources[1]) == 'kkk', list(map(str, tgt.sources)) n = env.Alias(tgt, source = ['$BAR', 'asrc4'])[0] assert n is tgt, n - assert len(tgt.sources) == 4, map(str, tgt.sources) - assert str(tgt.sources[2]) == 'lll', map(str, tgt.sources) - assert str(tgt.sources[3]) == 'asrc4', map(str, tgt.sources) + assert len(tgt.sources) == 4, list(map(str, tgt.sources)) + assert str(tgt.sources[2]) == 'lll', list(map(str, tgt.sources)) + assert str(tgt.sources[3]) == 'asrc4', list(map(str, tgt.sources)) n = env.Alias('$EA', 'asrc5')[0] assert n is tgt, n - assert len(tgt.sources) == 5, map(str, tgt.sources) - assert str(tgt.sources[4]) == 'asrc5', map(str, tgt.sources) + assert len(tgt.sources) == 5, list(map(str, tgt.sources)) + assert str(tgt.sources[4]) == 'asrc5', list(map(str, tgt.sources)) t1, t2 = env.Alias(['t1', 't2'], ['asrc6', 'asrc7']) assert str(t1) == 't1', t1 assert str(t2) == 't2', t2 - assert len(t1.sources) == 2, map(str, t1.sources) - assert str(t1.sources[0]) == 'asrc6', map(str, t1.sources) - assert str(t1.sources[1]) == 'asrc7', map(str, t1.sources) - assert len(t2.sources) == 2, map(str, t2.sources) - assert str(t2.sources[0]) == 'asrc6', map(str, t2.sources) - assert str(t2.sources[1]) == 'asrc7', map(str, t2.sources) + assert len(t1.sources) == 2, list(map(str, t1.sources)) + assert str(t1.sources[0]) == 'asrc6', list(map(str, t1.sources)) + assert str(t1.sources[1]) == 'asrc7', list(map(str, t1.sources)) + assert len(t2.sources) == 2, list(map(str, t2.sources)) + assert str(t2.sources[0]) == 'asrc6', list(map(str, t2.sources)) + assert str(t2.sources[1]) == 'asrc7', list(map(str, t2.sources)) tgt = env.Alias('add', 's1') tgt = env.Alias('add', 's2')[0] - s = map(str, tgt.sources) + s = list(map(str, tgt.sources)) assert s == ['s1', 's2'], s tgt = env.Alias(tgt, 's3')[0] - s = map(str, tgt.sources) + s = list(map(str, tgt.sources)) assert s == ['s1', 's2', 's3'], s tgt = env.Alias('act', None, "action1")[0] @@ -2770,20 +2769,20 @@ def generate(env): fff = env.arg2nodes('fff')[0] t = env.Clean('foo', 'aaa') - l = map(str, CT[foo]) + l = list(map(str, CT[foo])) assert l == ['aaa'], l t = env.Clean(foo, ['$BAR', 'ccc']) - l = map(str, CT[foo]) + l = list(map(str, CT[foo])) assert l == ['aaa', 'bbb', 'ccc'], l eee = env.arg2nodes('eee')[0] t = env.Clean('$FOO', 'ddd') - l = map(str, CT[fff]) + l = list(map(str, CT[fff])) assert l == ['ddd'], l t = env.Clean(fff, [eee, 'fff']) - l = map(str, CT[fff]) + l = list(map(str, CT[fff])) assert l == ['ddd', 'eee', 'fff'], l def test_Command(self): @@ -2794,25 +2793,25 @@ def generate(env): assert t.builder is not None assert t.builder.action.__class__.__name__ == 'CommandAction' assert t.builder.action.cmd_list == 'buildfoo $target $source' - assert 'foo1.in' in map(lambda x: x.path, t.sources) - assert 'foo2.in' in map(lambda x: x.path, t.sources) + assert 'foo1.in' in [x.path for x in t.sources] + assert 'foo2.in' in [x.path for x in t.sources] sub = env.fs.Dir('sub') t = env.Command(target='bar.out', source='sub', action='buildbar $target $source')[0] - assert 'sub' in map(lambda x: x.path, t.sources) + assert 'sub' in [x.path for x in t.sources] def testFunc(env, target, source): assert str(target[0]) == 'foo.out' - assert 'foo1.in' in map(str, source) and 'foo2.in' in map(str, source), map(str, source) + assert 'foo1.in' in list(map(str, source)) and 'foo2.in' in list(map(str, source)), list(map(str, source)) return 0 t = env.Command(target='foo.out', source=['foo1.in','foo2.in'], action=testFunc)[0] assert t.builder is not None assert t.builder.action.__class__.__name__ == 'FunctionAction' t.build() - assert 'foo1.in' in map(lambda x: x.path, t.sources) - assert 'foo2.in' in map(lambda x: x.path, t.sources) + assert 'foo1.in' in [x.path for x in t.sources] + assert 'foo2.in' in [x.path for x in t.sources] x = [] def test2(baz, x=x): @@ -2829,7 +2828,7 @@ def generate(env): action = 'foo', X = 'xxx')[0] assert str(t) == 'xxx.out', str(t) - assert 'xxx.in' in map(lambda x: x.path, t.sources) + assert 'xxx.in' in [x.path for x in t.sources] env = self.TestEnvironment(source_scanner = 'should_not_find_this') t = env.Command(target='file.out', source='file.in', @@ -3422,9 +3421,9 @@ def generate(env): bad_msg = '%s is not reserved, but got omitted; see Environment.construction_var_name_ok' added.append('INIT') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x env.Append(TARGETS = 'targets', SOURCES = 'sources', @@ -3437,9 +3436,9 @@ def generate(env): APPEND = 'append') added.append('APPEND') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x env.AppendUnique(TARGETS = 'targets', SOURCES = 'sources', @@ -3452,9 +3451,9 @@ def generate(env): APPENDUNIQUE = 'appendunique') added.append('APPENDUNIQUE') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x env.Prepend(TARGETS = 'targets', SOURCES = 'sources', @@ -3467,9 +3466,9 @@ def generate(env): PREPEND = 'prepend') added.append('PREPEND') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x env.Prepend(TARGETS = 'targets', SOURCES = 'sources', @@ -3482,9 +3481,9 @@ def generate(env): PREPENDUNIQUE = 'prependunique') added.append('PREPENDUNIQUE') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x env.Replace(TARGETS = 'targets', SOURCES = 'sources', @@ -3497,9 +3496,9 @@ def generate(env): REPLACE = 'replace') added.append('REPLACE') for x in self.reserved_variables: - assert not env.has_key(x), env[x] + assert x not in env, env[x] for x in added: - assert env.has_key(x), bad_msg % x + assert x in env, bad_msg % x copy = env.Clone(TARGETS = 'targets', SOURCES = 'sources', @@ -3511,9 +3510,9 @@ def generate(env): UNCHANGED_TARGETS = 'unchanged_targets', COPY = 'copy') for x in self.reserved_variables: - assert not copy.has_key(x), env[x] + assert x not in copy, env[x] for x in added + ['COPY']: - assert copy.has_key(x), bad_msg % x + assert x in copy, bad_msg % x over = env.Override({'TARGETS' : 'targets', 'SOURCES' : 'sources', @@ -3525,9 +3524,9 @@ def generate(env): 'UNCHANGED_TARGETS' : 'unchanged_targets', 'OVERRIDE' : 'override'}) for x in self.reserved_variables: - assert not over.has_key(x), over[x] + assert x not in over, over[x] for x in added + ['OVERRIDE']: - assert over.has_key(x), bad_msg % x + assert x in over, bad_msg % x def test_parse_flags(self): '''Test the Base class parse_flags argument''' @@ -3548,7 +3547,7 @@ def generate(env): # all we have to show is that it gets to MergeFlags internally env = Environment(tools = []) env2 = env.Clone(parse_flags = '-X') - assert not env.has_key('CCFLAGS') + assert 'CCFLAGS' not in env assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS'] env = Environment(tools = [], CCFLAGS=None) @@ -3558,9 +3557,9 @@ def generate(env): env = Environment(tools = [], CPPDEFINES = 'FOO') env2 = env.Clone(parse_flags = '-std=c99 -X -DBAR') - assert not env.has_key('CFLAGS') + assert 'CFLAGS' not in env assert env2['CFLAGS'] == ['-std=c99'], env2['CFLAGS'] - assert not env.has_key('CCFLAGS') + assert 'CCFLAGS' not in env assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS'] assert env['CPPDEFINES'] == 'FOO', env['CPPDEFINES'] assert env2['CPPDEFINES'] == ['FOO','BAR'], env2['CPPDEFINES'] @@ -3594,19 +3593,19 @@ class OverrideEnvironmentTestCase(unittest.TestCase,TestEnvironmentFixture): env, env2, env3 = self.envs del env3['XXX'] - assert not env.has_key('XXX'), "env has XXX?" - assert not env2.has_key('XXX'), "env2 has XXX?" - assert not env3.has_key('XXX'), "env3 has XXX?" + assert 'XXX' not in env, "env has XXX?" + assert 'XXX' not in env2, "env2 has XXX?" + assert 'XXX' not in env3, "env3 has XXX?" del env3['YYY'] - assert not env.has_key('YYY'), "env has YYY?" - assert not env2.has_key('YYY'), "env2 has YYY?" - assert not env3.has_key('YYY'), "env3 has YYY?" + assert 'YYY' not in env, "env has YYY?" + assert 'YYY' not in env2, "env2 has YYY?" + assert 'YYY' not in env3, "env3 has YYY?" del env3['ZZZ'] - assert not env.has_key('ZZZ'), "env has ZZZ?" - assert not env2.has_key('ZZZ'), "env2 has ZZZ?" - assert not env3.has_key('ZZZ'), "env3 has ZZZ?" + assert 'ZZZ' not in env, "env has ZZZ?" + assert 'ZZZ' not in env2, "env2 has ZZZ?" + assert 'ZZZ' not in env3, "env3 has ZZZ?" def test_get(self): """Test the OverrideEnvironment get() method""" @@ -3624,15 +3623,15 @@ class OverrideEnvironmentTestCase(unittest.TestCase,TestEnvironmentFixture): def test_has_key(self): """Test the OverrideEnvironment has_key() method""" env, env2, env3 = self.envs - assert env.has_key('XXX'), env.has_key('XXX') - assert env2.has_key('XXX'), env2.has_key('XXX') - assert env3.has_key('XXX'), env3.has_key('XXX') - assert env.has_key('YYY'), env.has_key('YYY') - assert env2.has_key('YYY'), env2.has_key('YYY') - assert env3.has_key('YYY'), env3.has_key('YYY') - assert not env.has_key('ZZZ'), env.has_key('ZZZ') - assert not env2.has_key('ZZZ'), env2.has_key('ZZZ') - assert env3.has_key('ZZZ'), env3.has_key('ZZZ') + assert 'XXX' in env, 'XXX' in env + assert 'XXX' in env2, 'XXX' in env2 + assert 'XXX' in env3, 'XXX' in env3 + assert 'YYY' in env, 'YYY' in env + assert 'YYY' in env2, 'YYY' in env2 + assert 'YYY' in env3, 'YYY' in env3 + assert 'ZZZ' not in env, 'ZZZ' in env + assert 'ZZZ' not in env2, 'ZZZ' in env2 + assert 'ZZZ' in env3, 'ZZZ' in env3 def test_contains(self): """Test the OverrideEnvironment __contains__() method""" @@ -3819,7 +3818,7 @@ class OverrideEnvironmentTestCase(unittest.TestCase,TestEnvironmentFixture): # all we have to show is that it gets to MergeFlags internally env = SubstitutionEnvironment() env2 = env.Override({'parse_flags' : '-X'}) - assert not env.has_key('CCFLAGS') + assert 'CCFLAGS' not in env assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS'] env = SubstitutionEnvironment(CCFLAGS=None) @@ -3829,9 +3828,9 @@ class OverrideEnvironmentTestCase(unittest.TestCase,TestEnvironmentFixture): env = SubstitutionEnvironment(CPPDEFINES = 'FOO') env2 = env.Override({'parse_flags' : '-std=c99 -X -DBAR'}) - assert not env.has_key('CFLAGS') + assert 'CFLAGS' not in env assert env2['CFLAGS'] == ['-std=c99'], env2['CFLAGS'] - assert not env.has_key('CCFLAGS') + assert 'CCFLAGS' not in env assert env2['CCFLAGS'] == ['-X'], env2['CCFLAGS'] assert env['CPPDEFINES'] == 'FOO', env['CPPDEFINES'] assert env2['CPPDEFINES'] == ['FOO','BAR'], env2['CPPDEFINES'] @@ -3933,9 +3932,9 @@ class NoSubstitutionProxyTestCase(unittest.TestCase,TestEnvironmentFixture): args = ('$XXX $TARGET $SOURCE $YYY',) kw = {'target' : DummyNode('ttt'), 'source' : DummyNode('sss')} - x = apply(env.subst_target_source, args, kw) + x = env.subst_target_source(*args, **kw) assert x == 'x ttt sss y', x - x = apply(proxy.subst_target_source, args, kw) + x = proxy.subst_target_source(*args, **kw) assert x == ' ttt sss ', x class EnvironmentVariableTestCase(unittest.TestCase): @@ -3982,7 +3981,7 @@ if __name__ == "__main__": EnvironmentVariableTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Errors.py b/src/engine/SCons/Errors.py index 562cbcf..813e08c 100644 --- a/src/engine/SCons/Errors.py +++ b/src/engine/SCons/Errors.py @@ -133,7 +133,7 @@ class ExplicitExit(Exception): self.node = node self.status = status self.exitstatus = status - apply(Exception.__init__, (self,) + args) + Exception.__init__(self, *args) def convert_to_BuildError(status, exc_info=None): """ diff --git a/src/engine/SCons/Executor.py b/src/engine/SCons/Executor.py index 4da42d5..aaf71b8 100644 --- a/src/engine/SCons/Executor.py +++ b/src/engine/SCons/Executor.py @@ -27,10 +27,10 @@ Nodes. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string import UserList from SCons.Debug import logInstanceCreation @@ -161,10 +161,10 @@ class Executor: ut = [] for b in self.batches: if b.targets[0].is_up_to_date(): - us.extend(map(rfile, b.sources)) + us.extend(list(map(rfile, b.sources))) ut.extend(b.targets) else: - cs.extend(map(rfile, b.sources)) + cs.extend(list(map(rfile, b.sources))) ct.extend(b.targets) self._changed_sources_list = SCons.Util.NodeList(cs) self._changed_targets_list = SCons.Util.NodeList(ct) @@ -190,14 +190,14 @@ class Executor: return rfile(self.batches[0].sources[0]).get_subst_proxy() def _get_sources(self, *args, **kw): - return SCons.Util.NodeList(map(lambda n: rfile(n).get_subst_proxy(), self.get_all_sources())) + return SCons.Util.NodeList([rfile(n).get_subst_proxy() for n in self.get_all_sources()]) def _get_target(self, *args, **kw): #return SCons.Util.NodeList([self.batches[0].targets[0].get_subst_proxy()]) return self.batches[0].targets[0].get_subst_proxy() def _get_targets(self, *args, **kw): - return SCons.Util.NodeList(map(lambda n: n.get_subst_proxy(), self.get_all_targets())) + return SCons.Util.NodeList([n.get_subst_proxy() for n in self.get_all_targets()]) def _get_unchanged_sources(self, *args, **kw): try: @@ -342,7 +342,7 @@ class Executor: for act in self.get_action_list(): #args = (self.get_all_targets(), self.get_all_sources(), env) args = ([], [], env) - status = apply(act, args, kw) + status = act(*args, **kw) if isinstance(status, SCons.Errors.BuildError): status.executor = self raise status @@ -372,7 +372,7 @@ class Executor: # TODO(batch): extend to multiple batches assert (len(self.batches) == 1) # TODO(batch): remove duplicates? - sources = filter(lambda x, s=self.batches[0].sources: x not in s, sources) + sources = [x for x in sources if x not in self.batches[0].sources] self.batches[0].sources.extend(sources) def get_sources(self): @@ -406,9 +406,10 @@ class Executor: def my_str(self): env = self.get_build_env() - get = lambda action, t=self.get_all_targets(), s=self.get_all_sources(), e=env: \ - action.genstring(t, s, e) - return string.join(map(get, self.get_action_list()), "\n") + return "\n".join([action.genstring(self.get_all_targets(), + self.get_all_sources(), + env) + for action in self.get_action_list()]) def __str__(self): @@ -417,7 +418,7 @@ class Executor: def nullify(self): self.cleanup() self.do_execute = self.do_nothing - self.my_str = lambda S=self: '' + self.my_str = lambda: '' memoizer_counters.append(SCons.Memoize.CountValue('get_contents')) @@ -431,9 +432,10 @@ class Executor: except KeyError: pass env = self.get_build_env() - get = lambda action, t=self.get_all_targets(), s=self.get_all_sources(), e=env: \ - action.get_contents(t, s, e) - result = string.join(map(get, self.get_action_list()), "") + result = "".join([action.get_contents(self.get_all_targets(), + self.get_all_sources(), + env) + for action in self.get_action_list()]) self._memo['get_contents'] = result return result @@ -521,7 +523,7 @@ class Executor: idict = {} for i in ignore: idict[i] = 1 - sourcelist = filter(lambda s, i=idict: not i.has_key(s), sourcelist) + sourcelist = [s for s in sourcelist if s not in idict] memo_dict[key] = sourcelist @@ -547,7 +549,7 @@ def GetBatchExecutor(key): return _batch_executors[key] def AddBatchExecutor(key, executor): - assert not _batch_executors.has_key(key) + assert key not in _batch_executors _batch_executors[key] = executor nullenv = None diff --git a/src/engine/SCons/ExecutorTests.py b/src/engine/SCons/ExecutorTests.py index 205553a..aaafa07 100644 --- a/src/engine/SCons/ExecutorTests.py +++ b/src/engine/SCons/ExecutorTests.py @@ -23,7 +23,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string import sys import unittest @@ -39,7 +38,7 @@ class MyEnvironment: def Override(self, overrides): d = self._dict.copy() d.update(overrides) - return apply(MyEnvironment, (), d) + return MyEnvironment(**d) def _update(self, dict): self._dict.update(dict) @@ -48,11 +47,11 @@ class MyAction: self.actions = actions def __call__(self, target, source, env, **kw): for action in self.actions: - apply(action, (target, source, env), kw) + action(target, source, env, **kw) def genstring(self, target, source, env): - return string.join(['GENSTRING'] + map(str, self.actions) + target + source) + return ' '.join(['GENSTRING'] + list(map(str, self.actions)) + target + source) def get_contents(self, target, source, env): - return string.join(self.actions + target + source) + return ' '.join(self.actions + target + source) def get_implicit_deps(self, target, source, env): return [] @@ -79,7 +78,7 @@ class MyNode: [], [self], ['s1', 's2']) - apply(executor, (self), {}) + executor(self) def get_env_scanner(self, env, kw): return MyScanner('dep-') def get_implicit_deps(self, env, scanner, path): @@ -184,8 +183,8 @@ class ExecutorTestCase(unittest.TestCase): class LocalScanner: def path(self, env, dir, target, source): - target = map(str, target) - source = map(str, source) + target = list(map(str, target)) + source = list(map(str, source)) return "scanner: %s, %s, %s, %s" % (env['SCANNERVAL'], dir, target, source) s = LocalScanner() @@ -440,13 +439,13 @@ class ExecutorTestCase(unittest.TestCase): x = SCons.Executor.Executor('b', env, [{}], [], [s1, s2, s3]) r = x.get_unignored_sources(None, []) - assert r == [s1, s2, s3], map(str, r) + assert r == [s1, s2, s3], list(map(str, r)) r = x.get_unignored_sources(None, [s2]) - assert r == [s1, s3], map(str, r) + assert r == [s1, s3], list(map(str, r)) r = x.get_unignored_sources(None, [s1, s3]) - assert r == [s2], map(str, r) + assert r == [s2], list(map(str, r)) @@ -455,7 +454,7 @@ if __name__ == "__main__": tclasses = [ ExecutorTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Job.py b/src/engine/SCons/Job.py index e2375f8..5d6befe 100644 --- a/src/engine/SCons/Job.py +++ b/src/engine/SCons/Job.py @@ -31,6 +31,8 @@ stop, and wait on jobs. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import os import signal @@ -127,7 +129,7 @@ class Jobs: turns out that it very difficult to stop the build process by throwing asynchronously an exception such as KeyboardInterrupt. For example, the python Condition - variables (threading.Condition) and Queue's do not seem to + variables (threading.Condition) and queue's do not seem to asynchronous-exception-safe. It would require adding a whole bunch of try/finally block and except KeyboardInterrupt all over the place. @@ -221,7 +223,7 @@ class Serial: # Parallel class (and its dependent classes) will work if the interpreter # doesn't support threads. try: - import Queue + import queue import threading except ImportError: pass @@ -271,8 +273,8 @@ else: One must specify the stack size of the worker threads. The stack size is specified in kilobytes. """ - self.requestQueue = Queue.Queue(0) - self.resultsQueue = Queue.Queue(0) + self.requestQueue = queue.Queue(0) + self.resultsQueue = queue.Queue(0) try: prev_size = threading.stack_size(stack_size*1024) diff --git a/src/engine/SCons/JobTests.py b/src/engine/SCons/JobTests.py index 793a8b7..afa00fb 100644 --- a/src/engine/SCons/JobTests.py +++ b/src/engine/SCons/JobTests.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -491,7 +492,7 @@ class _SConsTaskTest(unittest.TestCase): self.failUnless(state in [SCons.Node.no_state, N.expect_to_be], "Node %s got unexpected result: %s" % (N, state)) - self.failUnless(filter(lambda N: N.get_state(), testnodes), + self.failUnless([N for N in testnodes if N.get_state()], "no nodes ran at all.") diff --git a/src/engine/SCons/Memoize.py b/src/engine/SCons/Memoize.py index 966a618..4566d31 100644 --- a/src/engine/SCons/Memoize.py +++ b/src/engine/SCons/Memoize.py @@ -165,11 +165,11 @@ class CountValue(Counter): """ def __call__(self, *args, **kw): obj = args[0] - if obj._memo.has_key(self.method_name): + if self.method_name in obj._memo: self.hit = self.hit + 1 else: self.miss = self.miss + 1 - return apply(self.underlying_method, args, kw) + return self.underlying_method(*args, **kw) class CountDict(Counter): """ @@ -199,12 +199,12 @@ class CountDict(Counter): except KeyError: self.miss = self.miss + 1 else: - key = apply(self.keymaker, args, kw) - if memo_dict.has_key(key): + key = self.keymaker(*args, **kw) + if key in memo_dict: self.hit = self.hit + 1 else: self.miss = self.miss + 1 - return apply(self.underlying_method, args, kw) + return self.underlying_method(*args, **kw) class Memoizer: """Object which performs caching of method calls for its 'primary' diff --git a/src/engine/SCons/MemoizeTests.py b/src/engine/SCons/MemoizeTests.py index 1452052..b3edf01 100644 --- a/src/engine/SCons/MemoizeTests.py +++ b/src/engine/SCons/MemoizeTests.py @@ -187,7 +187,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Node/Alias.py b/src/engine/SCons/Node/Alias.py index d599335..521488e 100644 --- a/src/engine/SCons/Node/Alias.py +++ b/src/engine/SCons/Node/Alias.py @@ -32,7 +32,6 @@ This creates a hash of global Aliases (dummy targets). __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string import UserDict import SCons.Errors @@ -46,7 +45,7 @@ class AliasNameSpace(UserDict.UserDict): try: a = self[name] except KeyError: - a = apply(SCons.Node.Alias.Alias, (name,), kw) + a = SCons.Node.Alias.Alias(name, **kw) self[name] = a return a @@ -95,8 +94,8 @@ class Alias(SCons.Node.Node): def get_contents(self): """The contents of an alias is the concatenation of the content signatures of all its sources.""" - childsigs = map(lambda n: n.get_csig(), self.children()) - return string.join(childsigs, '') + childsigs = [n.get_csig() for n in self.children()] + return ''.join(childsigs) def sconsign(self): """An Alias is not recorded in .sconsign files""" diff --git a/src/engine/SCons/Node/AliasTests.py b/src/engine/SCons/Node/AliasTests.py index 82322e3..6931072 100644 --- a/src/engine/SCons/Node/AliasTests.py +++ b/src/engine/SCons/Node/AliasTests.py @@ -119,7 +119,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index 88248d7..705e0bc 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -32,6 +32,7 @@ that can be used by scripts or modules looking for the canonical default. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -43,7 +44,6 @@ import os.path import re import shutil import stat -import string import sys import time @@ -260,7 +260,7 @@ def set_duplicate(duplicate): "should be in Valid_Duplicates") global Link_Funcs Link_Funcs = [] - for func in string.split(duplicate,'-'): + for func in duplicate.split('-'): if link_dict[func]: Link_Funcs.append(link_dict[func]) @@ -373,7 +373,7 @@ if os.path.normcase("TeSt") == os.path.normpath("TeSt") and not _is_cygwin: return x else: def _my_normcase(x): - return string.upper(x) + return x.upper() @@ -459,7 +459,7 @@ def set_diskcheck(list): dc.set(list) def diskcheck_types(): - return map(lambda dc: dc.type, diskcheckers) + return [dc.type for dc in diskcheckers] @@ -497,7 +497,7 @@ class EntryProxy(SCons.Util.Proxy): return self else: entry = self.get() - r = string.replace(entry.get_path(), os.sep, '/') + r = entry.get_path().replace(os.sep, '/') return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_posix") def __get_windows_path(self): @@ -507,7 +507,7 @@ class EntryProxy(SCons.Util.Proxy): return self else: entry = self.get() - r = string.replace(entry.get_path(), os.sep, '\\') + r = entry.get_path().replace(os.sep, '\\') return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_windows") def __get_srcnode(self): @@ -753,8 +753,8 @@ class Base(SCons.Node.Node): try: i = path_elems.index(dir) except ValueError: pass else: path_elems = path_elems[i+1:] - path_elems = map(lambda n: n.name, path_elems) - return string.join(path_elems, os.sep) + path_elems = [n.name for n in path_elems] + return os.sep.join(path_elems) def set_src_builder(self, builder): """Set the source code builder for this node.""" @@ -1249,7 +1249,7 @@ class FS(LocalFS): root = directory.root if os.sep != '/': - p = string.replace(p, os.sep, '/') + p = p.replace(os.sep, '/') return root._lookup_abs(p, fsclass, create) def Entry(self, name, directory = None, create = 1): @@ -1327,12 +1327,12 @@ class FS(LocalFS): if start_dir.is_under(bd): # If already in the build-dir location, don't reflect return [orig], fmt % str(orig) - p = apply(os.path.join, [bd.path] + tail) + p = os.path.join(bd.path, *tail) targets.append(self.Entry(p)) tail = [dir.name] + tail dir = dir.up() if targets: - message = fmt % string.join(map(str, targets)) + message = fmt % ' '.join(map(str, targets)) return targets, message def Glob(self, pathname, ondisk=True, source=True, strings=False, cwd=None): @@ -1574,9 +1574,9 @@ class Dir(Base): i = self.path_elements.index(other) + 1 path_elems = ['..'] * (len(self.path_elements) - i) \ - + map(lambda n: n.name, other.path_elements[i:]) + + [n.name for n in other.path_elements[i:]] - result = string.join(path_elems, os.sep) + result = os.sep.join(path_elems) memo_dict[other] = result @@ -1622,7 +1622,7 @@ class Dir(Base): """A null "builder" for directories.""" global MkdirBuilder if self.builder is not MkdirBuilder: - apply(SCons.Node.Node.build, [self,], kw) + SCons.Node.Node.build(self, **kw) # # @@ -1687,7 +1687,7 @@ class Dir(Base): sorted_children.sort(name_cmp) for node in sorted_children: contents.append('%s %s\n' % (node.get_csig(), node.name)) - return string.join(contents, '') + return ''.join(contents) def get_csig(self): """Compute the content signature for Directory nodes. In @@ -1783,7 +1783,7 @@ class Dir(Base): d[name] = result return result else: - return d.has_key(name) + return name in d memoizer_counters.append(SCons.Memoize.CountValue('srcdir_list')) @@ -1915,8 +1915,7 @@ class Dir(Base): names.remove('.') names.remove('..') func(arg, self, names) - select_dirs = lambda n, e=entries: isinstance(e[n], Dir) - for dirname in filter(select_dirs, names): + for dirname in [n for n in names if isinstance(entries[n], Dir)]: entries[dirname].walk(func, arg) def glob(self, pathname, ondisk=True, source=False, strings=False): @@ -1964,7 +1963,7 @@ class Dir(Base): for dir in list: r = dir._glob1(basename, ondisk, source, strings) if strings: - r = map(lambda x, d=str(dir): os.path.join(d, x), r) + r = [os.path.join(str(dir), x) for x in r] result.extend(r) result.sort(lambda a, b: cmp(str(a), str(b))) return result @@ -1990,9 +1989,8 @@ class Dir(Base): # We use the .name attribute from the Node because the keys of # the dir.entries dictionary are normalized (that is, all upper # case) on case-insensitive systems like Windows. - #node_names = [ v.name for k, v in dir.entries.items() if k not in ('.', '..') ] - entry_names = filter(lambda n: n not in ('.', '..'), dir.entries.keys()) - node_names = map(lambda n, e=dir.entries: e[n].name, entry_names) + node_names = [ v.name for k, v in dir.entries.items() + if k not in ('.', '..') ] names.extend(node_names) if not strings: # Make sure the working directory (self) actually has @@ -2015,7 +2013,7 @@ class Dir(Base): # after we exit this loop. if pattern[0] != '.': #disk_names = [ d for d in disk_names if d[0] != '.' ] - disk_names = filter(lambda x: x[0] != '.', disk_names) + disk_names = [x for x in disk_names if x[0] != '.'] disk_names = fnmatch.filter(disk_names, pattern) dirEntry = dir.Entry for name in disk_names: @@ -2031,14 +2029,14 @@ class Dir(Base): names = set(names) if pattern[0] != '.': #names = [ n for n in names if n[0] != '.' ] - names = filter(lambda x: x[0] != '.', names) + names = [x for x in names if x[0] != '.'] names = fnmatch.filter(names, pattern) if strings: return names #return [ self.entries[_my_normcase(n)] for n in names ] - return map(lambda n, e=self.entries: e[_my_normcase(n)], names) + return [self.entries[_my_normcase(n)] for n in names] class RootDir(Dir): """A class for the root directory of a file system. @@ -2200,7 +2198,7 @@ class FileBuildInfo(SCons.Node.BuildInfoBase): except AttributeError: s = str(n) else: - s = string.replace(s, os.sep, '/') + s = s.replace(os.sep, '/') return s for attr in ['bsources', 'bdepends', 'bimplicit']: try: @@ -2208,7 +2206,7 @@ class FileBuildInfo(SCons.Node.BuildInfoBase): except AttributeError: pass else: - setattr(self, attr, map(node_to_str, val)) + setattr(self, attr, list(map(node_to_str, val))) def convert_from_sconsign(self, dir, name): """ Converts a newly-read FileBuildInfo object for in-SCons use @@ -2249,9 +2247,9 @@ class FileBuildInfo(SCons.Node.BuildInfoBase): bkidsigs = self.bsourcesigs + self.bdependsigs + self.bimplicitsigs for bkid, bkidsig in izip(bkids, bkidsigs): result.append(str(bkid) + ': ' + - string.join(bkidsig.format(names=names), ' ')) + ' '.join(bkidsig.format(names=names))) result.append('%s [%s]' % (self.bactsig, self.bact)) - return string.join(result, '\n') + return '\n'.join(result) class File(Base): """A class for files in a file system. @@ -2288,7 +2286,7 @@ class File(Base): directory of this file.""" # TODO(1.5) # return [self.Dir(p) for p in pathlist] - return map(lambda p, s=self: s.Dir(p), pathlist) + return [self.Dir(p) for p in pathlist] def File(self, name): """Create a file node named 'name' relative to @@ -2603,7 +2601,7 @@ class File(Base): if scanner: # result = [n.disambiguate() for n in scanner(self, env, path)] result = scanner(self, env, path) - result = map(lambda N: N.disambiguate(), result) + result = [N.disambiguate() for N in result] else: result = [] @@ -3019,7 +3017,7 @@ class File(Base): children = self.children() executor = self.get_executor() # sigs = [n.get_cachedir_csig() for n in children] - sigs = map(lambda n: n.get_cachedir_csig(), children) + sigs = [n.get_cachedir_csig() for n in children] sigs.append(SCons.Util.MD5signature(executor.get_contents())) sigs.append(self.path) result = self.cachesig = SCons.Util.MD5collect(sigs) @@ -3117,8 +3115,8 @@ class FileFinder: if verbose and not callable(verbose): if not SCons.Util.is_String(verbose): verbose = "find_file" - verbose = ' %s: ' % verbose - verbose = lambda s, v=verbose: sys.stdout.write(v + s) + _verbose = ' %s: ' % verbose + verbose = lambda s: sys.stdout.write(_verbose + s) filedir, filename = os.path.split(filename) if filedir: @@ -3153,7 +3151,7 @@ class FileFinder: #paths = filter(None, map(filedir_lookup, paths)) self.default_filedir = filedir - paths = filter(None, map(self.filedir_lookup, paths)) + paths = [_f for _f in map(self.filedir_lookup, paths) if _f] result = None for dir in paths: diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 9582a97..af7638d 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import sys import time import unittest @@ -40,13 +39,6 @@ import SCons.Warnings built_it = None -# This will be built-in in 2.3. For now fake it. -try : - True , False -except NameError : - True = 1 ; False = 0 - - scanner_count = 0 class Scanner: @@ -341,7 +333,7 @@ class VariantDirTestCase(unittest.TestCase): f11 = fs.File('src/file11') t, m = f11.alter_targets() - bdt = map(lambda n: n.path, t) + bdt = [n.path for n in t] var1_file11 = os.path.normpath('build/var1/file11') var2_file11 = os.path.normpath('build/var2/file11') assert bdt == [var1_file11, var2_file11], bdt @@ -349,11 +341,11 @@ class VariantDirTestCase(unittest.TestCase): f12 = fs.File('src/file12') f12.builder = 1 bdt, m = f12.alter_targets() - assert bdt == [], map(lambda n: n.path, bdt) + assert bdt == [], [n.path for n in bdt] d13 = fs.Dir('src/new_dir') t, m = d13.alter_targets() - bdt = map(lambda n: n.path, t) + bdt = [n.path for n in t] var1_new_dir = os.path.normpath('build/var1/new_dir') var2_new_dir = os.path.normpath('build/var2/new_dir') assert bdt == [var1_new_dir, var2_new_dir], bdt @@ -445,7 +437,7 @@ class VariantDirTestCase(unittest.TestCase): self.have['copy'] = copy self.links_to_be_called = [] - for link in string.split(self.duplicate, '-'): + for link in self.duplicate.split('-'): if self.have[link]: self.links_to_be_called.append(link) @@ -817,7 +809,7 @@ class FileBuildInfoTestCase(_tempdirTestCase): 'actionsig [action]', ] - expect = string.join(expect_lines, '\n') + expect = '\n'.join(expect_lines) format = bi1.format() assert format == expect, (repr(expect), repr(format)) @@ -921,12 +913,12 @@ class FSTestCase(_tempdirTestCase): drive, path = os.path.splitdrive(os.getcwd()) def _do_Dir_test(lpath, path_, abspath_, up_path_, sep, fileSys=fs, drive=drive): - dir = fileSys.Dir(string.replace(lpath, '/', sep)) + dir = fileSys.Dir(lpath.replace('/', sep)) if os.sep != '/': - path_ = string.replace(path_, '/', os.sep) - abspath_ = string.replace(abspath_, '/', os.sep) - up_path_ = string.replace(up_path_, '/', os.sep) + path_ = path_.replace('/', os.sep) + abspath_ = abspath_.replace('/', os.sep) + up_path_ = up_path_.replace('/', os.sep) def strip_slash(p, drive=drive): if p[-1] == os.sep and len(p) > 1: @@ -937,7 +929,7 @@ class FSTestCase(_tempdirTestCase): path = strip_slash(path_) abspath = strip_slash(abspath_) up_path = strip_slash(up_path_) - name = string.split(abspath, os.sep)[-1] + name = abspath.split(os.sep)[-1] assert dir.name == name, \ "dir.name %s != expected name %s" % \ @@ -978,7 +970,7 @@ class FSTestCase(_tempdirTestCase): Dir_test('#', './', sub_dir, sub) try: - f2 = fs.File(string.join(['f1', 'f2'], sep), directory = d1) + f2 = fs.File(sep.join(['f1', 'f2']), directory = d1) except TypeError, x: assert str(x) == ("Tried to lookup File '%s' as a Dir." % d1_f1), x @@ -986,7 +978,7 @@ class FSTestCase(_tempdirTestCase): raise try: - dir = fs.Dir(string.join(['d1', 'f1'], sep)) + dir = fs.Dir(sep.join(['d1', 'f1'])) except TypeError, x: assert str(x) == ("Tried to lookup File '%s' as a Dir." % d1_f1), x @@ -1051,7 +1043,7 @@ class FSTestCase(_tempdirTestCase): assert built_it def match(path, expect): - expect = string.replace(expect, '/', os.sep) + expect = expect.replace('/', os.sep) assert path == expect, "path %s != expected %s" % (path, expect) e1 = fs.Entry("d1") @@ -1434,7 +1426,7 @@ class FSTestCase(_tempdirTestCase): test.subdir('sub', ['sub', 'dir']) def drive_workpath(drive, dirs, test=test): - x = apply(test.workpath, dirs) + x = test.workpath(*dirs) drive, path = os.path.splitdrive(x) return 'X:' + path @@ -1466,11 +1458,11 @@ class FSTestCase(_tempdirTestCase): seps = seps + ['/'] def _do_Dir_test(lpath, path_, up_path_, sep, fileSys=fs): - dir = fileSys.Dir(string.replace(lpath, '/', sep)) + dir = fileSys.Dir(lpath.replace('/', sep)) if os.sep != '/': - path_ = string.replace(path_, '/', os.sep) - up_path_ = string.replace(up_path_, '/', os.sep) + path_ = path_.replace('/', os.sep) + up_path_ = up_path_.replace('/', os.sep) def strip_slash(p): if p[-1] == os.sep and len(p) > 3: @@ -1478,7 +1470,7 @@ class FSTestCase(_tempdirTestCase): return p path = strip_slash(path_) up_path = strip_slash(up_path_) - name = string.split(path, os.sep)[-1] + name = path.split(os.sep)[-1] assert dir.name == name, \ "dir.name %s != expected name %s" % \ @@ -1577,8 +1569,8 @@ class FSTestCase(_tempdirTestCase): d1 = fs.Dir('d1') d2 = d1.Dir('d2') - dirs = string.split(os.path.normpath(d2.abspath), os.sep) - above_path = apply(os.path.join, ['..']*len(dirs) + ['above']) + dirs = os.path.normpath(d2.abspath).split(os.sep) + above_path = os.path.join(*['..']*len(dirs) + ['above']) above = d2.Dir(above_path) def test_rel_path(self): @@ -1730,7 +1722,7 @@ class DirTestCase(_tempdirTestCase): fs.Dir(os.path.join('ddd', 'd1', 'f4')) fs.Dir(os.path.join('ddd', 'd1', 'f5')) dir.scan() - kids = map(lambda x: x.path, dir.children(None)) + kids = [x.path for x in dir.children(None)] kids.sort() assert kids == [os.path.join('ddd', 'd1'), os.path.join('ddd', 'f1'), @@ -1757,7 +1749,7 @@ class DirTestCase(_tempdirTestCase): s = self.fs.Dir(os.path.join('d', 'sub')) #TODO(1.5) files = d.get_contents().split('\n') - files = string.split(d.get_contents(), '\n') + files = d.get_contents().split('\n') assert e.get_contents() == '', e.get_contents() assert e.get_text_contents() == '', e.get_text_contents() @@ -1776,13 +1768,13 @@ class DirTestCase(_tempdirTestCase): fs.File(os.path.join('ddd', 'f1')) dir.scan() - kids = map(lambda x: x.path, dir.children()) + kids = [x.path for x in dir.children()] kids.sort() assert kids == [os.path.join('ddd', 'f1')], kids fs.File(os.path.join('ddd', 'f2')) dir.scan() - kids = map(lambda x: x.path, dir.children()) + kids = [x.path for x in dir.children()] kids.sort() assert kids == [os.path.join('ddd', 'f1'), os.path.join('ddd', 'f2')], kids @@ -1818,8 +1810,8 @@ class DirTestCase(_tempdirTestCase): self.fs.VariantDir(sub2, src, duplicate=0) def check(result, expect): - result = map(str, result) - expect = map(os.path.normpath, expect) + result = list(map(str, result)) + expect = list(map(os.path.normpath, expect)) assert result == expect, result s = src.srcdir_list() @@ -1922,8 +1914,8 @@ class DirTestCase(_tempdirTestCase): exists_e.exists = return_true def check(result, expect): - result = map(str, result) - expect = map(os.path.normpath, expect) + result = list(map(str, result)) + expect = list(map(os.path.normpath, expect)) assert result == expect, result # First check from the source directory. @@ -2135,7 +2127,7 @@ class FileTestCase(_tempdirTestCase): d1 = self.fs.Dir('subdir/d1') d2 = self.fs.Dir('subdir/d2') dirs = fff.Dirs(['d1', 'd2']) - assert dirs == [d1, d2], map(str, dirs) + assert dirs == [d1, d2], list(map(str, dirs)) def test_exists(self): """Test the File.exists() method""" @@ -2248,7 +2240,7 @@ class GlobTestCase(_tempdirTestCase): strings_kwargs = copy.copy(kwargs) strings_kwargs['strings'] = True for input, string_expect, node_expect in cases: - r = apply(self.fs.Glob, (input,), strings_kwargs) + r = self.fs.Glob(input, **strings_kwargs) r.sort() assert r == string_expect, "Glob(%s, strings=True) expected %s, got %s" % (input, string_expect, r) @@ -2259,7 +2251,7 @@ class GlobTestCase(_tempdirTestCase): # Verify those by running the list through str() before comparing # them with the expected list of strings. for input, string_expect, node_expect in cases: - r = apply(self.fs.Glob, (input,), kwargs) + r = self.fs.Glob(input, **kwargs) if node_expect: r.sort(lambda a,b: cmp(a.path, b.path)) result = [] @@ -2269,16 +2261,16 @@ class GlobTestCase(_tempdirTestCase): result.append(n) fmt = lambda n: "%s %s" % (repr(n), repr(str(n))) else: - r = map(str, r) + r = list(map(str, r)) r.sort() result = string_expect fmt = lambda n: n if r != result: import pprint print "Glob(%s) expected:" % repr(input) - pprint.pprint(map(fmt, result)) + pprint.pprint(list(map(fmt, result))) print "Glob(%s) got:" % repr(input) - pprint.pprint(map(fmt, r)) + pprint.pprint(list(map(fmt, r))) self.fail() def test_exact_match(self): @@ -2538,7 +2530,7 @@ class RepositoryTestCase(_tempdirTestCase): ] rep = self.fs.Dir('#').getRepositories() - r = map(lambda x, np=os.path.normpath: np(str(x)), rep) + r = [os.path.normpath(str(x)) for x in rep] assert r == expect, r def test_get_all_rdirs(self): @@ -2560,7 +2552,7 @@ class RepositoryTestCase(_tempdirTestCase): ] rep = self.fs.Dir('#').get_all_rdirs() - r = map(lambda x, np=os.path.normpath: np(str(x)), rep) + r = [os.path.normpath(str(x)) for x in rep] assert r == expect, r def test_rentry(self): @@ -2742,25 +2734,25 @@ class RepositoryTestCase(_tempdirTestCase): rep3_sub_d1 = fs.Dir(test.workpath('rep3', 'sub', 'd1')) r = fs.Top.Rfindalldirs((d1,)) - assert r == [d1], map(str, r) + assert r == [d1], list(map(str, r)) r = fs.Top.Rfindalldirs((d1, d2)) - assert r == [d1, d2], map(str, r) + assert r == [d1, d2], list(map(str, r)) r = fs.Top.Rfindalldirs(('d1',)) - assert r == [d1, rep1_d1, rep2_d1, rep3_d1], map(str, r) + assert r == [d1, rep1_d1, rep2_d1, rep3_d1], list(map(str, r)) r = fs.Top.Rfindalldirs(('#d1',)) - assert r == [d1, rep1_d1, rep2_d1, rep3_d1], map(str, r) + assert r == [d1, rep1_d1, rep2_d1, rep3_d1], list(map(str, r)) r = sub.Rfindalldirs(('d1',)) - assert r == [sub_d1, rep1_sub_d1, rep2_sub_d1, rep3_sub_d1], map(str, r) + assert r == [sub_d1, rep1_sub_d1, rep2_sub_d1, rep3_sub_d1], list(map(str, r)) r = sub.Rfindalldirs(('#d1',)) - assert r == [d1, rep1_d1, rep2_d1, rep3_d1], map(str, r) + assert r == [d1, rep1_d1, rep2_d1, rep3_d1], list(map(str, r)) r = fs.Top.Rfindalldirs(('d1', d2)) - assert r == [d1, rep1_d1, rep2_d1, rep3_d1, d2], map(str, r) + assert r == [d1, rep1_d1, rep2_d1, rep3_d1, d2], list(map(str, r)) def test_rexists(self): """Test the Entry.rexists() method""" @@ -2892,10 +2884,10 @@ class find_fileTestCase(unittest.TestCase): nodes.append(SCons.Node.FS.find_file('pseudo', paths)) nodes.append(SCons.Node.FS.find_file('same', paths)) - file_names = map(str, nodes) - file_names = map(os.path.normpath, file_names) + file_names = list(map(str, nodes)) + file_names = list(map(os.path.normpath, file_names)) expect = ['./foo', './bar/baz', './pseudo', './bar/same'] - expect = map(os.path.normpath, expect) + expect = list(map(os.path.normpath, expect)) assert file_names == expect, file_names # Make sure we don't blow up if there's already a File in place @@ -3433,14 +3425,14 @@ class SaveStringsTestCase(unittest.TestCase): fs1.VariantDir('d0', 'src', duplicate=0) fs1.VariantDir('d1', 'src', duplicate=1) - s = map(str, nodes) - expect = map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b']) + s = list(map(str, nodes)) + expect = list(map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b'])) assert s == expect, s modify(nodes) - s = map(str, nodes) - expect = map(os.path.normpath, ['src/f', 'src/f', 'd0/b', 'd1/b']) + s = list(map(str, nodes)) + expect = list(map(os.path.normpath, ['src/f', 'src/f', 'd0/b', 'd1/b'])) assert s == expect, s SCons.Node.FS.save_strings(1) @@ -3449,14 +3441,14 @@ class SaveStringsTestCase(unittest.TestCase): fs2.VariantDir('d0', 'src', duplicate=0) fs2.VariantDir('d1', 'src', duplicate=1) - s = map(str, nodes) - expect = map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b']) + s = list(map(str, nodes)) + expect = list(map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b'])) assert s == expect, s modify(nodes) - s = map(str, nodes) - expect = map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b']) + s = list(map(str, nodes)) + expect = list(map(os.path.normpath, ['src/f', 'd1/f', 'd0/b', 'd1/b'])) assert s == expect, 'node str() not cached: %s'%s @@ -3509,7 +3501,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 643e218..0784237 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -20,12 +20,12 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import re -import string import sys import types import unittest @@ -125,7 +125,7 @@ class Environment: def Override(self, overrides): d = self._dict.copy() d.update(overrides) - return apply(Environment, (), d) + return Environment(**d) def _update(self, dict): self._dict.update(dict) def get_factory(self, factory): @@ -889,24 +889,24 @@ class NodeTestCase(unittest.TestCase): d2.found_includes = [e, f] f.found_includes = [g] deps = node.get_implicit_deps(env, s, target) - assert deps == [d1, d2, e, f, g], map(str, deps) + assert deps == [d1, d2, e, f, g], list(map(str, deps)) # Recursive scanning eliminates duplicates e.found_includes = [f] deps = node.get_implicit_deps(env, s, target) - assert deps == [d1, d2, e, f, g], map(str, deps) + assert deps == [d1, d2, e, f, g], list(map(str, deps)) # Scanner method can select specific nodes to recurse def no_fff(nodes): - return filter(lambda n: str(n)[0] != 'f', nodes) + return [n for n in nodes if str(n)[0] != 'f'] s.recurse_nodes = no_fff deps = node.get_implicit_deps(env, s, target) - assert deps == [d1, d2, e, f], map(str, deps) + assert deps == [d1, d2, e, f], list(map(str, deps)) # Scanner method can short-circuit recursing entirely s.recurse_nodes = lambda nodes: [] deps = node.get_implicit_deps(env, s, target) - assert deps == [d1, d2], map(str, deps) + assert deps == [d1, d2], list(map(str, deps)) def test_get_env_scanner(self): """Test fetching the environment scanner for a Node @@ -1130,13 +1130,13 @@ class NodeTestCase(unittest.TestCase): nw = SCons.Node.Walker(n1) assert nw.next().name == "n4" assert nw.next().name == "n5" - assert nw.history.has_key(n2) + assert n2 in nw.history assert nw.next().name == "n2" assert nw.next().name == "n6" assert nw.next().name == "n7" - assert nw.history.has_key(n3) + assert n3 in nw.history assert nw.next().name == "n3" - assert nw.history.has_key(n1) + assert n1 in nw.history assert nw.next().name == "n1" assert nw.next() is None @@ -1293,7 +1293,7 @@ class NodeListTestCase(unittest.TestCase): # New-style classes report as "object"; classic classes report # as "instance"... r = re.sub("object", "instance", r) - l = string.join([""]*3, ", ") + l = ", ".join([""]*3) assert r == '[%s]' % l, r @@ -1306,7 +1306,7 @@ if __name__ == "__main__": NodeListTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Node/Python.py b/src/engine/SCons/Node/Python.py index eba008b..3d8bdaa 100644 --- a/src/engine/SCons/Node/Python.py +++ b/src/engine/SCons/Node/Python.py @@ -67,7 +67,7 @@ class Value(SCons.Node.Node): def build(self, **kw): if not hasattr(self, 'built_value'): - apply (SCons.Node.Node.build, (self,), kw) + SCons.Node.Node.build(self, **kw) is_up_to_date = SCons.Node.Node.children_are_up_to_date diff --git a/src/engine/SCons/Node/PythonTests.py b/src/engine/SCons/Node/PythonTests.py index 1dc2bb7..74a9c99 100644 --- a/src/engine/SCons/Node/PythonTests.py +++ b/src/engine/SCons/Node/PythonTests.py @@ -119,7 +119,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index c4f36cc..c25c955 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -41,12 +41,12 @@ be able to depend on any other type of "thing." # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import copy from itertools import chain, izip -import string import UserList from SCons.Debug import logInstanceCreation @@ -57,7 +57,7 @@ import SCons.Util from SCons.Debug import Trace def classname(obj): - return string.split(str(obj.__class__), '.')[-1] + return str(obj.__class__).split('.')[-1] # Node states # @@ -372,7 +372,7 @@ class Node: """ try: - apply(self.get_executor(), (self,), kw) + self.get_executor()(self, **kw) except SCons.Errors.BuildError, e: e.node = self raise @@ -548,8 +548,7 @@ class Node: deps = [] while nodes: n = nodes.pop(0) - d = filter(lambda x, seen=seen: not seen.has_key(x), - n.get_found_includes(env, scanner, path)) + d = [x for x in n.get_found_includes(env, scanner, path) if x not in seen] if d: deps.extend(d) for n in d: @@ -832,7 +831,7 @@ class Node: except TypeError, e: e = e.args[0] if SCons.Util.is_List(e): - s = map(str, e) + s = list(map(str, e)) else: s = str(e) raise SCons.Errors.UserError("attempted to add a non-Node dependency to %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e))) @@ -849,7 +848,7 @@ class Node: except TypeError, e: e = e.args[0] if SCons.Util.is_List(e): - s = map(str, e) + s = list(map(str, e)) else: s = str(e) raise SCons.Errors.UserError("attempted to ignore a non-Node dependency of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e))) @@ -863,7 +862,7 @@ class Node: except TypeError, e: e = e.args[0] if SCons.Util.is_List(e): - s = map(str, e) + s = list(map(str, e)) else: s = str(e) raise SCons.Errors.UserError("attempted to add a non-Node as source of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e))) @@ -1215,11 +1214,11 @@ class Node: lines = [] - removed = filter(lambda x, nk=new_bkids: not x in nk, old_bkids) + removed = [x for x in old_bkids if not x in new_bkids] if removed: - removed = map(stringify, removed) + removed = list(map(stringify, removed)) fmt = "`%s' is no longer a dependency\n" - lines.extend(map(lambda s, fmt=fmt: fmt % s, removed)) + lines.extend([fmt % s for s in removed]) for k in new_bkids: if not k in old_bkids: @@ -1229,14 +1228,14 @@ class Node: if len(lines) == 0 and old_bkids != new_bkids: lines.append("the dependency order changed:\n" + - "%sold: %s\n" % (' '*15, map(stringify, old_bkids)) + - "%snew: %s\n" % (' '*15, map(stringify, new_bkids))) + "%sold: %s\n" % (' '*15, list(map(stringify, old_bkids))) + + "%snew: %s\n" % (' '*15, list(map(stringify, new_bkids)))) if len(lines) == 0: def fmt_with_title(title, strlines): - lines = string.split(strlines, '\n') + lines = strlines.split('\n') sep = '\n' + ' '*(15 + len(title)) - return ' '*15 + title + string.join(lines, sep) + '\n' + return ' '*15 + title + sep.join(lines) + '\n' if old.bactsig != new.bactsig: if old.bact == new.bact: lines.append("the contents of the build action changed\n" + @@ -1254,7 +1253,7 @@ class Node: return "%s %s" % (preamble, lines[0]) else: lines = ["%s:\n" % preamble] + lines - return string.join(lines, ' '*11) + return ( ' '*11).join(lines) try: [].extend(UserList.UserList([])) @@ -1267,7 +1266,7 @@ except TypeError: else: class NodeList(UserList.UserList): def __str__(self): - return str(map(str, self.data)) + return str(list(map(str, self.data))) def get_children(node, parent): return node.children() def ignore_cycle(node, stack): pass @@ -1310,7 +1309,7 @@ class Walker: node = self.stack[-1].wkids.pop(0) if not self.stack[-1].wkids: self.stack[-1].wkids = None - if self.history.has_key(node): + if node in self.history: self.cycle_func(node, self.stack) else: node.wkids = copy.copy(self.kids_func(node, self.stack[-1])) diff --git a/src/engine/SCons/Options/BoolOption.py b/src/engine/SCons/Options/BoolOption.py index 652cf5e..452fdd3 100644 --- a/src/engine/SCons/Options/BoolOption.py +++ b/src/engine/SCons/Options/BoolOption.py @@ -41,7 +41,7 @@ def BoolOption(*args, **kw): msg = "The BoolOption() function is deprecated; use the BoolVariable() function instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg) warned = True - return apply(SCons.Variables.BoolVariable, args, kw) + return SCons.Variables.BoolVariable(*args, **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Options/EnumOption.py b/src/engine/SCons/Options/EnumOption.py index e89b5b9..2db158d 100644 --- a/src/engine/SCons/Options/EnumOption.py +++ b/src/engine/SCons/Options/EnumOption.py @@ -41,7 +41,7 @@ def EnumOption(*args, **kw): msg = "The EnumOption() function is deprecated; use the EnumVariable() function instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg) warned = True - return apply(SCons.Variables.EnumVariable, args, kw) + return SCons.Variables.EnumVariable(*args, **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Options/ListOption.py b/src/engine/SCons/Options/ListOption.py index a660924..4167d8e 100644 --- a/src/engine/SCons/Options/ListOption.py +++ b/src/engine/SCons/Options/ListOption.py @@ -41,7 +41,7 @@ def ListOption(*args, **kw): msg = "The ListOption() function is deprecated; use the ListVariable() function instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg) warned = True - return apply(SCons.Variables.ListVariable, args, kw) + return SCons.Variables.ListVariable(*args, **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Options/PackageOption.py b/src/engine/SCons/Options/PackageOption.py index 51f9f9b..ba0608a 100644 --- a/src/engine/SCons/Options/PackageOption.py +++ b/src/engine/SCons/Options/PackageOption.py @@ -41,7 +41,7 @@ def PackageOption(*args, **kw): msg = "The PackageOption() function is deprecated; use the PackageVariable() function instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg) warned = True - return apply(SCons.Variables.PackageVariable, args, kw) + return SCons.Variables.PackageVariable(*args, **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Options/PathOption.py b/src/engine/SCons/Options/PathOption.py index fd1130b..5d460a0 100644 --- a/src/engine/SCons/Options/PathOption.py +++ b/src/engine/SCons/Options/PathOption.py @@ -45,27 +45,27 @@ class _PathOptionClass: def __call__(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable, args, kw) + return SCons.Variables.PathVariable(*args, **kw) def PathAccept(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable.PathAccept, args, kw) + return SCons.Variables.PathVariable.PathAccept(*args, **kw) def PathIsDir(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable.PathIsDir, args, kw) + return SCons.Variables.PathVariable.PathIsDir(*args, **kw) def PathIsDirCreate(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable.PathIsDirCreate, args, kw) + return SCons.Variables.PathVariable.PathIsDirCreate(*args, **kw) def PathIsFile(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable.PathIsFile, args, kw) + return SCons.Variables.PathVariable.PathIsFile(*args, **kw) def PathExists(self, *args, **kw): self.warn() - return apply(SCons.Variables.PathVariable.PathExists, args, kw) + return SCons.Variables.PathVariable.PathExists(*args, **kw) PathOption = _PathOptionClass() diff --git a/src/engine/SCons/Options/__init__.py b/src/engine/SCons/Options/__init__.py index 104aa82..f6c8483 100644 --- a/src/engine/SCons/Options/__init__.py +++ b/src/engine/SCons/Options/__init__.py @@ -48,24 +48,17 @@ class Options(SCons.Variables.Variables): msg = "The Options class is deprecated; use the Variables class instead." SCons.Warnings.warn(SCons.Warnings.DeprecatedOptionsWarning, msg) warned = True - apply(SCons.Variables.Variables.__init__, - (self,) + args, - kw) + SCons.Variables.Variables.__init__(self, *args, **kw) def AddOptions(self, *args, **kw): - return apply(SCons.Variables.Variables.AddVariables, - (self,) + args, - kw) + return SCons.Variables.Variables.AddVariables(self, *args, **kw) def UnknownOptions(self, *args, **kw): - return apply(SCons.Variables.Variables.UnknownVariables, - (self,) + args, - kw) + return SCons.Variables.Variables.UnknownVariables(self, *args, **kw) def FormatOptionHelpText(self, *args, **kw): - return apply(SCons.Variables.Variables.FormatVariableHelpText, - (self,) + args, - kw) + return SCons.Variables.Variables.FormatVariableHelpText(self, *args, + **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/PathList.py b/src/engine/SCons/PathList.py index 9da0f31..7b12865 100644 --- a/src/engine/SCons/PathList.py +++ b/src/engine/SCons/PathList.py @@ -33,7 +33,6 @@ Do the Right Thing (almost) regardless of how the variable is specified. """ import os -import string import SCons.Memoize import SCons.Node @@ -98,14 +97,14 @@ class _PathList: over and over for each target. """ if SCons.Util.is_String(pathlist): - pathlist = string.split(pathlist, os.pathsep) + pathlist = pathlist.split(os.pathsep) elif not SCons.Util.is_Sequence(pathlist): pathlist = [pathlist] pl = [] for p in pathlist: try: - index = string.find(p, '$') + index = p.find('$') except (AttributeError, TypeError): type = TYPE_OBJECT else: diff --git a/src/engine/SCons/PathListTests.py b/src/engine/SCons/PathListTests.py index faecc4d..31a9ec6 100644 --- a/src/engine/SCons/PathListTests.py +++ b/src/engine/SCons/PathListTests.py @@ -159,7 +159,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Platform/__init__.py b/src/engine/SCons/Platform/__init__.py index 5bcd91c..2ae1e97 100644 --- a/src/engine/SCons/Platform/__init__.py +++ b/src/engine/SCons/Platform/__init__.py @@ -48,7 +48,6 @@ import SCons.compat import imp import os -import string import sys import tempfile @@ -69,15 +68,15 @@ def platform_default(): if osname == 'posix': if sys.platform == 'cygwin': return 'cygwin' - elif string.find(sys.platform, 'irix') != -1: + elif sys.platform.find('irix') != -1: return 'irix' - elif string.find(sys.platform, 'sunos') != -1: + elif sys.platform.find('sunos') != -1: return 'sunos' - elif string.find(sys.platform, 'hp-ux') != -1: + elif sys.platform.find('hp-ux') != -1: return 'hpux' - elif string.find(sys.platform, 'aix') != -1: + elif sys.platform.find('aix') != -1: return 'aix' - elif string.find(sys.platform, 'darwin') != -1: + elif sys.platform.find('darwin') != -1: return 'darwin' else: return 'posix' @@ -94,7 +93,7 @@ def platform_module(name = platform_default()): our execution environment. """ full_name = 'SCons.Platform.' + name - if not sys.modules.has_key(full_name): + if full_name not in sys.modules: if os.name == 'java': eval(full_name) else: @@ -184,7 +183,7 @@ class TempFileMunge: if env['SHELL'] and env['SHELL'] == 'sh': # The sh shell will try to escape the backslashes in the # path, so unescape them. - native_tmp = string.replace(native_tmp, '\\', r'\\\\') + native_tmp = native_tmp.replace('\\', r'\\\\') # In Cygwin, we want to use rm to delete the temporary # file, because del does not exist in the sh shell. rm = env.Detect('rm') or 'del' @@ -198,8 +197,8 @@ class TempFileMunge: if not prefix: prefix = '@' - args = map(SCons.Subst.quote_spaces, cmd[1:]) - os.write(fd, string.join(args, " ") + "\n") + args = list(map(SCons.Subst.quote_spaces, cmd[1:])) + os.write(fd, " ".join(args) + "\n") os.close(fd) # XXX Using the SCons.Action.print_actions value directly # like this is bogus, but expedient. This class should @@ -218,7 +217,7 @@ class TempFileMunge: # reach into SCons.Action directly. if SCons.Action.print_actions: print("Using tempfile "+native_tmp+" for command line:\n"+ - str(cmd[0]) + " " + string.join(args," ")) + str(cmd[0]) + " " + " ".join(args)) return [ cmd[0], prefix + native_tmp + '\n' + rm, native_tmp ] def Platform(name = platform_default()): diff --git a/src/engine/SCons/Platform/aix.py b/src/engine/SCons/Platform/aix.py index a5f9573..0229112 100644 --- a/src/engine/SCons/Platform/aix.py +++ b/src/engine/SCons/Platform/aix.py @@ -33,7 +33,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os -import string import posix @@ -51,9 +50,9 @@ def get_xlc(env, xlc=None, xlc_r=None, packages=[]): cmd = "lslpp -fc " + package + " 2>/dev/null | egrep '" + xlc + "([^-_a-zA-Z0-9].*)?$'" line = os.popen(cmd).readline() if line: - v, p = string.split(line, ':')[1:3] - xlcVersion = string.split(v)[1] - xlcPath = string.split(p)[0] + v, p = line.split(':')[1:3] + xlcVersion = v.split()[1] + xlcPath = p.split()[0] xlcPath = xlcPath[:xlcPath.rindex('/')] break return (xlcPath, xlc, xlc_r, xlcVersion) diff --git a/src/engine/SCons/Platform/os2.py b/src/engine/SCons/Platform/os2.py index aa348d4..0fa4553 100644 --- a/src/engine/SCons/Platform/os2.py +++ b/src/engine/SCons/Platform/os2.py @@ -34,7 +34,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import win32 def generate(env): - if not env.has_key('ENV'): + if 'ENV' not in env: env['ENV'] = {} env['OBJPREFIX'] = '' env['OBJSUFFIX'] = '.obj' diff --git a/src/engine/SCons/Platform/posix.py b/src/engine/SCons/Platform/posix.py index d1102b3..ece48d7 100644 --- a/src/engine/SCons/Platform/posix.py +++ b/src/engine/SCons/Platform/posix.py @@ -35,7 +35,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import errno import os import os.path -import string import subprocess import sys import select @@ -53,14 +52,14 @@ def escape(arg): slash = '\\' special = '"$()' - arg = string.replace(arg, slash, slash+slash) + arg = arg.replace(slash, slash+slash) for c in special: - arg = string.replace(arg, c, slash+c) + arg = arg.replace(c, slash+c) return '"' + arg + '"' def exec_system(l, env): - stat = os.system(string.join(l)) + stat = os.system(' '.join(l)) if stat & 0xff: return stat | 0x80 return stat >> 8 @@ -90,22 +89,22 @@ def exec_fork(l, env): return stat >> 8 def _get_env_command(sh, escape, cmd, args, env): - s = string.join(args) + s = ' '.join(args) if env: l = ['env', '-'] + \ - map(lambda t, e=escape: e(t[0])+'='+e(t[1]), env.items()) + \ + [escape(t[0])+'='+escape(t[1]) for t in env.items()] + \ [sh, '-c', escape(s)] - s = string.join(l) + s = ' '.join(l) return s def env_spawn(sh, escape, cmd, args, env): return exec_system([_get_env_command( sh, escape, cmd, args, env)], env) def spawnvpe_spawn(sh, escape, cmd, args, env): - return exec_spawnvpe([sh, '-c', string.join(args)], env) + return exec_spawnvpe([sh, '-c', ' '.join(args)], env) def fork_spawn(sh, escape, cmd, args, env): - return exec_fork([sh, '-c', string.join(args)], env) + return exec_fork([sh, '-c', ' '.join(args)], env) def process_cmd_output(cmd_stdout, cmd_stderr, stdout, stderr): stdout_eof = stderr_eof = 0 @@ -131,7 +130,7 @@ def process_cmd_output(cmd_stdout, cmd_stderr, stdout, stderr): raise def exec_popen3(l, env, stdout, stderr): - proc = subprocess.Popen(string.join(l), + proc = subprocess.Popen(' '.join(l), stdout=stdout, stderr=stderr, shell=True) @@ -198,7 +197,7 @@ def piped_env_spawn(sh, escape, cmd, args, env, stdout, stderr): def piped_fork_spawn(sh, escape, cmd, args, env, stdout, stderr): # spawn using fork / exec and providing a pipe for the command's # stdout / stderr stream - return exec_piped_fork([sh, '-c', string.join(args)], + return exec_piped_fork([sh, '-c', ' '.join(args)], env, stdout, stderr) @@ -217,7 +216,7 @@ def generate(env): # os.fork()/os.exec() works better than os.system(). There may just # not be a default that works best for all users. - if os.__dict__.has_key('spawnvpe'): + if 'spawnvpe' in os.__dict__: spawn = spawnvpe_spawn elif env.Detect('env'): spawn = env_spawn @@ -229,7 +228,7 @@ def generate(env): else: pspawn = piped_fork_spawn - if not env.has_key('ENV'): + if 'ENV' not in env: env['ENV'] = {} env['ENV']['PATH'] = '/usr/local/bin:/opt/bin:/bin:/usr/bin' env['OBJPREFIX'] = '' diff --git a/src/engine/SCons/Platform/win32.py b/src/engine/SCons/Platform/win32.py index a50a6ae..52255ba 100644 --- a/src/engine/SCons/Platform/win32.py +++ b/src/engine/SCons/Platform/win32.py @@ -34,7 +34,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import sys import tempfile @@ -67,14 +66,14 @@ else: _builtin_open = __builtin__.open def _scons_file(*args, **kw): - fp = apply(_builtin_file, args, kw) + fp = _builtin_file(*args, **kw) win32api.SetHandleInformation(msvcrt.get_osfhandle(fp.fileno()), win32con.HANDLE_FLAG_INHERIT, 0) return fp def _scons_open(*args, **kw): - fp = apply(_builtin_open, args, kw) + fp = _builtin_open(*args, **kw) win32api.SetHandleInformation(msvcrt.get_osfhandle(fp.fileno()), win32con.HANDLE_FLAG_INHERIT, 0) @@ -109,11 +108,11 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): stderrRedirected = 0 for arg in args: # are there more possibilities to redirect stdout ? - if (string.find( arg, ">", 0, 1 ) != -1 or - string.find( arg, "1>", 0, 2 ) != -1): + if (arg.find( ">", 0, 1 ) != -1 or + arg.find( "1>", 0, 2 ) != -1): stdoutRedirected = 1 # are there more possibilities to redirect stderr ? - if string.find( arg, "2>", 0, 2 ) != -1: + if arg.find( "2>", 0, 2 ) != -1: stderrRedirected = 1 # redirect output of non-redirected streams to our tempfiles @@ -124,7 +123,7 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr): # actually do the spawn try: - args = [sh, '/C', escape(string.join(args)) ] + args = [sh, '/C', escape(' '.join(args)) ] ret = os.spawnve(os.P_WAIT, sh, args, env) except OSError, e: # catch any error @@ -162,7 +161,7 @@ def exec_spawn(l, env): result = 127 if len(l) > 2: if len(l[2]) < 1000: - command = string.join(l[0:3]) + command = ' '.join(l[0:3]) else: command = l[0] else: @@ -174,7 +173,7 @@ def spawn(sh, escape, cmd, args, env): if not sh: sys.stderr.write("scons: Could not find command interpreter, is it in your PATH?\n") return 127 - return exec_spawn([sh, '/C', escape(string.join(args))], env) + return exec_spawn([sh, '/C', escape(' '.join(args))], env) # Windows does not allow special characters in file names anyway, so no # need for a complex escape function, we will just quote the arg, except @@ -318,7 +317,7 @@ def generate(env): tmp_path = systemroot + os.pathsep + \ os.path.join(systemroot,'System32') tmp_pathext = '.com;.exe;.bat;.cmd' - if os.environ.has_key('PATHEXT'): + if 'PATHEXT' in os.environ: tmp_pathext = os.environ['PATHEXT'] cmd_interp = SCons.Util.WhereIs('cmd', tmp_path, tmp_pathext) if not cmd_interp: @@ -330,7 +329,7 @@ def generate(env): cmd_interp = env.Detect('command') - if not env.has_key('ENV'): + if 'ENV' not in env: env['ENV'] = {} # Import things from the external environment to the construction @@ -347,7 +346,7 @@ def generate(env): if v: env['ENV'][var] = v - if not env['ENV'].has_key('COMSPEC'): + if 'COMSPEC' not in env['ENV']: v = os.environ.get("COMSPEC") if v: env['ENV']['COMSPEC'] = v diff --git a/src/engine/SCons/SConf.py b/src/engine/SCons/SConf.py index 133dab5..bd67ab2 100644 --- a/src/engine/SCons/SConf.py +++ b/src/engine/SCons/SConf.py @@ -30,7 +30,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import re -import string import StringIO import sys import traceback @@ -96,7 +95,7 @@ sconf_global = None # current sconf object def _createConfigH(target, source, env): t = open(str(target[0]), "w") - defname = re.sub('[^A-Za-z0-9_]', '_', string.upper(str(target[0]))) + defname = re.sub('[^A-Za-z0-9_]', '_', str(target[0]).upper()) t.write("""#ifndef %(DEFNAME)s_SEEN #define %(DEFNAME)s_SEEN @@ -153,8 +152,7 @@ def _createSource( target, source, env ): fd.close() def _stringSource( target, source, env ): return (str(target[0]) + ' <-\n |' + - string.replace( source[0].get_contents(), - '\n', "\n |" ) ) + source[0].get_contents().replace( '\n', "\n |" ) ) # python 2.2 introduces types.BooleanType BooleanTypes = [types.IntType] @@ -222,8 +220,7 @@ class SConfBuildTask(SCons.Taskmaster.AlwaysTask): "The stored build information has an unexpected class: %s" % bi.__class__) else: self.display("The original builder output was:\n" + - string.replace(" |" + str(bi.string), - "\n", "\n |")) + (" |" + str(bi.string)).replace("\n", "\n |")) def failed(self): # check, if the reason was a ConfigureDryRunError or a @@ -246,7 +243,7 @@ class SConfBuildTask(SCons.Taskmaster.AlwaysTask): def excepthook(type, value, tb): traceback.print_tb(tb) print type, value - apply(excepthook, self.exc_info()) + excepthook(*self.exc_info()) return SCons.Taskmaster.Task.failed(self) def collect_node_states(self): @@ -465,7 +462,7 @@ class SConfBase: lines.append(define_str) lines.append('') - self.config_h_text = self.config_h_text + string.join(lines, '\n') + self.config_h_text = self.config_h_text + '\n'.join(lines) def BuildNodes(self, nodes): """ @@ -645,7 +642,7 @@ class SConfBase: raise (SCons.Errors.UserError, "Test called after sconf.Finish()") context = CheckContext(self.sconf) - ret = apply(self.test, (context,) + args, kw) + ret = self.test(context, *args, **kw) if self.sconf.config_h is not None: self.sconf.config_h_text = self.sconf.config_h_text + context.config_h context.Result("error: no result") @@ -689,7 +686,7 @@ class SConfBase: if self.logfile is not None and not dryrun: # truncate logfile, if SConf.Configure is called for the first time # in a build - if _ac_config_logs.has_key(self.logfile): + if self.logfile in _ac_config_logs: log_mode = "a" else: _ac_config_logs[self.logfile] = None @@ -804,19 +801,19 @@ class CheckContext: self.did_show_result = 1 def TryBuild(self, *args, **kw): - return apply(self.sconf.TryBuild, args, kw) + return self.sconf.TryBuild(*args, **kw) def TryAction(self, *args, **kw): - return apply(self.sconf.TryAction, args, kw) + return self.sconf.TryAction(*args, **kw) def TryCompile(self, *args, **kw): - return apply(self.sconf.TryCompile, args, kw) + return self.sconf.TryCompile(*args, **kw) def TryLink(self, *args, **kw): - return apply(self.sconf.TryLink, args, kw) + return self.sconf.TryLink(*args, **kw) def TryRun(self, *args, **kw): - return apply(self.sconf.TryRun, args, kw) + return self.sconf.TryRun(*args, **kw) def __getattr__( self, attr ): if( attr == 'env' ): @@ -889,7 +886,7 @@ def SConf(*args, **kw): del kw[bt] except KeyError: pass - return apply(SConfBase, args, kw) + return SConfBase(*args, **kw) else: return SCons.Util.Null() @@ -901,7 +898,7 @@ def CheckFunc(context, function_name, header = None, language = None): def CheckType(context, type_name, includes = "", language = None): res = SCons.Conftest.CheckType(context, type_name, - header = includes, language = language) + header = includes, language = language) context.did_show_result = 1 return not res @@ -933,7 +930,7 @@ def createIncludesFromHeaders(headers, leaveLast, include_quotes = '""'): for s in headers: l.append("#include %s%s%s\n" % (include_quotes[0], s, include_quotes[1])) - return string.join(l, ''), lastHeader + return ''.join(l), lastHeader def CheckHeader(context, header, include_quotes = '<>', language = None): """ diff --git a/src/engine/SCons/SConfTests.py b/src/engine/SCons/SConfTests.py index 45b6eef..d0da84a 100644 --- a/src/engine/SCons/SConfTests.py +++ b/src/engine/SCons/SConfTests.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import re -import string import StringIO import sys from types import * @@ -60,7 +59,7 @@ class SConfTestCase(unittest.TestCase): import SCons.SConsign SCons.SConsign.write() # simulate normal scons-finish for n in sys.modules.keys(): - if string.split(n, '.')[0] == 'SCons' and n[:12] != 'SCons.compat': + if n.split('.')[0] == 'SCons' and n[:12] != 'SCons.compat': m = sys.modules[n] if type(m) is ModuleType: # if this is really a scons module, clear its namespace diff --git a/src/engine/SCons/SConsignTests.py b/src/engine/SCons/SConsignTests.py index 9a02044..7ae584a 100644 --- a/src/engine/SCons/SConsignTests.py +++ b/src/engine/SCons/SConsignTests.py @@ -386,7 +386,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 622ac67..fd8d2f2 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -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]) diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index a62f4c1..e92af24 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -192,7 +192,7 @@ class DummyEnvironment(UserDict.UserDict): def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_calculator(self): return None @@ -213,8 +213,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 +310,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) diff --git a/src/engine/SCons/Scanner/D.py b/src/engine/SCons/Scanner/D.py index 4134337..9402ed1 100644 --- a/src/engine/SCons/Scanner/D.py +++ b/src/engine/SCons/Scanner/D.py @@ -33,7 +33,6 @@ Coded by Andy Friesen __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" 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 a623c99..6b7f05b 100644 --- a/src/engine/SCons/Scanner/Dir.py +++ b/src/engine/SCons/Scanner/Dir.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -28,21 +29,21 @@ 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 +68,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 +101,9 @@ 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 = list(filter(do_not_scan, entries.keys())) entry_list.sort() - return map(lambda n, e=entries: e[n], entry_list) + 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 5d59bd5..0ad1cfe 100644 --- a/src/engine/SCons/Scanner/DirTests.py +++ b/src/engine/SCons/Scanner/DirTests.py @@ -24,7 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import sys import types import unittest @@ -91,7 +90,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 +98,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 +108,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 2aed653..fd6a014 100644 --- a/src/engine/SCons/Scanner/Fortran.py +++ b/src/engine/SCons/Scanner/Fortran.py @@ -26,11 +26,11 @@ This module implements the dependency scanner for Fortran code. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import re -import string import SCons.Node import SCons.Node.FS @@ -75,7 +75,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 +94,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 @@ -124,7 +124,7 @@ class F90Scanner(SCons.Scanner.Classic): nodes.append((sortkey, n)) nodes.sort() - nodes = map(lambda pair: pair[1], nodes) + nodes = [pair[1] for pair in nodes] return nodes def FortranScan(path_variable="FORTRANPATH"): diff --git a/src/engine/SCons/Scanner/FortranTests.py b/src/engine/SCons/Scanner/FortranTests.py index 570b565..0380e87 100644 --- a/src/engine/SCons/Scanner/FortranTests.py +++ b/src/engine/SCons/Scanner/FortranTests.py @@ -221,7 +221,7 @@ class DummyEnvironment: 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] @@ -240,7 +240,7 @@ class DummyEnvironment: def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): 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) diff --git a/src/engine/SCons/Scanner/IDLTests.py b/src/engine/SCons/Scanner/IDLTests.py index a454b31..26b3956 100644 --- a/src/engine/SCons/Scanner/IDLTests.py +++ b/src/engine/SCons/Scanner/IDLTests.py @@ -205,10 +205,10 @@ class DummyEnvironment: def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): 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) diff --git a/src/engine/SCons/Scanner/LaTeX.py b/src/engine/SCons/Scanner/LaTeX.py index 17000a2..f3085d1 100644 --- a/src/engine/SCons/Scanner/LaTeX.py +++ b/src/engine/SCons/Scanner/LaTeX.py @@ -30,7 +30,6 @@ This module implements the dependency scanner for LaTeX code. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import re import SCons.Scanner @@ -60,11 +59,11 @@ def modify_env_var(env, var, abspath): 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 @@ -75,7 +74,7 @@ def modify_env_var(env, var, abspath): 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 @@ -231,7 +230,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] @@ -253,10 +252,10 @@ class LaTeX(SCons.Scanner.Base): 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) + #return map(lambda e: filename+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] return [filename] def sort_key(self, include): @@ -303,7 +302,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]) ) # @@ -368,7 +367,7 @@ class LaTeX(SCons.Scanner.Base): # nodes.sort() - nodes = map(lambda pair: pair[1], nodes) + nodes = [pair[1] for pair in nodes] return nodes # Local Variables: diff --git a/src/engine/SCons/Scanner/LaTeXTests.py b/src/engine/SCons/Scanner/LaTeXTests.py index e87a1aa..ac978cf 100644 --- a/src/engine/SCons/Scanner/LaTeXTests.py +++ b/src/engine/SCons/Scanner/LaTeXTests.py @@ -24,7 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import sys import types import unittest @@ -88,7 +87,7 @@ class DummyEnvironment(UserDict.UserDict): def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_calculator(self): return None @@ -109,8 +108,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 bd7bffe..49e93a5 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -23,8 +23,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string - import SCons.Node import SCons.Node.FS import SCons.Scanner @@ -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 7eaafcc..ee62ca7 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -24,7 +24,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import sys import types import unittest @@ -57,10 +56,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] @@ -82,7 +81,7 @@ class DummyEnvironment: def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_factory(self, factory): return factory or self.fs.File @@ -102,10 +101,10 @@ class DummyNode: return self.name def deps_match(deps, libs): - deps=map(str, deps) + deps=list(map(str, deps)) deps.sort() 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 +115,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 +143,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 +170,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 +185,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 +198,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): @@ -239,7 +238,7 @@ def suite(): 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/RCTests.py b/src/engine/SCons/Scanner/RCTests.py index bf1048d..a20c919 100644 --- a/src/engine/SCons/Scanner/RCTests.py +++ b/src/engine/SCons/Scanner/RCTests.py @@ -88,10 +88,10 @@ class DummyEnvironment(UserDict.UserDict): def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): 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,8 +112,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)) scanned.sort() expect.sort() self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 518e0ed..d89fb14 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -49,7 +50,7 @@ class DummyEnvironment(UserDict.UserDict): def subst_path(self, path, target=None, source=None, conv=None): if type(path) != type([]): path = [path] - return map(self.subst, path) + return list(map(self.subst, path)) def get_factory(self, factory): return factory or self.fs.File @@ -127,7 +128,7 @@ 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") @@ -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], @@ -595,7 +596,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 da82060..be08256 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -30,7 +30,6 @@ The Scanner package for the SCons software construction utility. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import re -import string import SCons.Node.FS import SCons.Util @@ -56,9 +55,9 @@ 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) @@ -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,7 +279,7 @@ 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() @@ -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 @@ -383,7 +382,7 @@ class Classic(Current): nodes.append((sortkey, n)) nodes.sort() - nodes = map(lambda pair: pair[1], nodes) + nodes = [pair[1] for pair in nodes] return nodes class ClassicCPP(Classic): @@ -408,7 +407,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 diff --git a/src/engine/SCons/Script/Interactive.py b/src/engine/SCons/Script/Interactive.py index 206f941..c546fc9 100644 --- a/src/engine/SCons/Script/Interactive.py +++ b/src/engine/SCons/Script/Interactive.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -90,7 +91,6 @@ import copy import os import re import shlex -import string import sys try: @@ -134,7 +134,7 @@ class SConsInteractiveCmd(cmd.Cmd): print "*** Unknown command: %s" % argv[0] def onecmd(self, line): - line = string.strip(line) + line = line.strip() if not line: print self.lastcmd return self.emptyline() @@ -144,7 +144,7 @@ class SConsInteractiveCmd(cmd.Cmd): elif line[0] == '?': line = 'help ' + line[1:] if os.sep == '\\': - line = string.replace(line, '\\', '\\\\') + line = line.replace('\\', '\\\\') argv = shlex.split(line) argv[0] = self.synonyms.get(argv[0], argv[0]) if not argv[0]: @@ -222,8 +222,8 @@ class SConsInteractiveCmd(cmd.Cmd): def get_unseen_children(node, parent, seen_nodes=seen_nodes): def is_unseen(node, seen_nodes=seen_nodes): - return not seen_nodes.has_key(node) - return filter(is_unseen, node.children(scan=1)) + return node not in seen_nodes + return list(filter(is_unseen, node.children(scan=1))) def add_to_seen_nodes(node, parent, seen_nodes=seen_nodes): seen_nodes[node] = 1 @@ -307,7 +307,7 @@ class SConsInteractiveCmd(cmd.Cmd): def _strip_initial_spaces(self, s): #lines = s.split('\n') - lines = string.split(s, '\n') + lines = s.split('\n') spaces = re.match(' *', lines[0]).group(0) #def strip_spaces(l): # if l.startswith(spaces): @@ -318,8 +318,8 @@ class SConsInteractiveCmd(cmd.Cmd): if l[:len(spaces)] == spaces: l = l[len(spaces):] return l - lines = map(strip_spaces, lines) - return string.join(lines, '\n') + lines = list(map(strip_spaces, lines)) + return '\n'.join(lines) def do_exit(self, argv): """\ diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 082de34..7173f1b 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -33,12 +33,12 @@ it goes here. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import sys import time import traceback @@ -107,7 +107,7 @@ class Progressor: self.func = obj elif SCons.Util.is_List(obj): self.func = self.spinner - elif string.find(obj, self.target_string) != -1: + elif obj.find(self.target_string) != -1: self.func = self.replace_string else: self.func = self.string @@ -132,7 +132,7 @@ class Progressor: self.write(self.obj) def replace_string(self, node): - self.write(string.replace(self.obj, self.target_string, str(node))) + self.write(self.obj.replace(self.target_string, str(node))) def __call__(self, node): self.count = self.count + 1 @@ -145,7 +145,7 @@ ProgressObject = SCons.Util.Null() def Progress(*args, **kw): global ProgressObject - ProgressObject = apply(Progressor, args, kw) + ProgressObject = Progressor(*args, **kw) # Task control. # @@ -208,7 +208,7 @@ class BuildTask(SCons.Taskmaster.OutOfDateTask): if self.top and not t.has_builder() and not t.side_effect: if not t.exists(): def classname(obj): - return string.split(str(obj.__class__), '.')[-1] + return str(obj.__class__).split('.')[-1] if classname(t) in ('File', 'Dir', 'Entry'): errstr="Do not know how to make %s target `%s' (%s)." % (classname(t), t, t.abspath) else: # Alias or Python or ... @@ -262,7 +262,7 @@ class BuildTask(SCons.Taskmaster.OutOfDateTask): node = buildError.node if not SCons.Util.is_List(node): node = [ node ] - nodename = string.join(map(str, node), ', ') + nodename = ', '.join(map(str, node)) errfmt = "scons: *** [%s] %s\n" sys.stderr.write(errfmt % (nodename, buildError)) @@ -345,7 +345,7 @@ class CleanTask(SCons.Taskmaster.AlwaysTask): for t in self.targets: if not t.isdir(): display("Removed " + str(t)) - if SCons.Environment.CleanTargets.has_key(target): + if target in SCons.Environment.CleanTargets: files = SCons.Environment.CleanTargets[target] for f in files: self.fs_delete(f.abspath, str(f), 0) @@ -366,7 +366,7 @@ class CleanTask(SCons.Taskmaster.AlwaysTask): else: if removed: display("Removed " + str(t)) - if SCons.Environment.CleanTargets.has_key(target): + if target in SCons.Environment.CleanTargets: files = SCons.Environment.CleanTargets[target] for f in files: self.fs_delete(f.abspath, str(f)) @@ -414,7 +414,7 @@ class TreePrinter: return node.all_children() def get_derived_children(self, node): children = node.all_children(None) - return filter(lambda x: x.has_builder(), children) + return [x for x in children if x.has_builder()] def display(self, t): if self.derived: func = self.get_derived_children @@ -425,7 +425,7 @@ class TreePrinter: def python_version_string(): - return string.split(sys.version)[0] + return sys.version.split()[0] def python_version_unsupported(version=sys.version_info): return version < (1, 5, 2) @@ -469,9 +469,9 @@ class FakeOptionParser: OptionsParser = FakeOptionParser() def AddOption(*args, **kw): - if not kw.has_key('default'): + if 'default' not in kw: kw['default'] = None - result = apply(OptionsParser.add_local_option, args, kw) + result = OptionsParser.add_local_option(*args, **kw) return result def GetOption(name): @@ -501,7 +501,7 @@ class CountStats(Stats): def do_print(self): stats_table = {} for s in self.stats: - for n in map(lambda t: t[0], s): + for n in [t[0] for t in s]: stats_table[n] = [0, 0, 0, 0] i = 0 for s in self.stats: @@ -514,12 +514,12 @@ class CountStats(Stats): pre = [" "] post = [" %s\n"] l = len(self.stats) - fmt1 = string.join(pre + [' %7s']*l + post, '') - fmt2 = string.join(pre + [' %7d']*l + post, '') + fmt1 = ''.join(pre + [' %7s']*l + post) + fmt2 = ''.join(pre + [' %7d']*l + post) labels = self.labels[:l] labels.append(("", "Class")) - self.outfp.write(fmt1 % tuple(map(lambda x: x[0], labels))) - self.outfp.write(fmt1 % tuple(map(lambda x: x[1], labels))) + self.outfp.write(fmt1 % tuple([x[0] for x in labels])) + self.outfp.write(fmt1 % tuple([x[1] for x in labels])) for k in keys: r = stats_table[k][:l] + [k] self.outfp.write(fmt2 % tuple(r)) @@ -563,7 +563,7 @@ def find_deepest_user_frame(tb): # of SCons: for frame in tb: filename = frame[0] - if string.find(filename, os.sep+'SCons'+os.sep) == -1: + if filename.find(os.sep+'SCons'+os.sep) == -1: return frame return tb[0] @@ -1087,7 +1087,7 @@ def _build_targets(fs, options, targets, target_top): # or not a file, so go ahead and keep it as a default # target and let the engine sort it out: return 1 - d = filter(check_dir, SCons.Script.DEFAULT_TARGETS) + d = list(filter(check_dir, SCons.Script.DEFAULT_TARGETS)) SCons.Script.DEFAULT_TARGETS[:] = d target_top = None lookup_top = None @@ -1122,7 +1122,7 @@ def _build_targets(fs, options, targets, target_top): node = None return node - nodes = filter(None, map(Entry, targets)) + nodes = [_f for _f in map(Entry, targets) if _f] task_class = BuildTask # default action is to build targets opening_message = "Building targets ..." @@ -1224,7 +1224,7 @@ def _build_targets(fs, options, targets, target_top): def _exec_main(parser, values): sconsflags = os.environ.get('SCONSFLAGS', '') - all_args = string.split(sconsflags) + sys.argv[1:] + all_args = sconsflags.split() + sys.argv[1:] options, args = parser.parse_args(all_args, values) @@ -1285,7 +1285,7 @@ def main(): pass parts.append(version_string("engine", SCons)) parts.append("__COPYRIGHT__") - version = string.join(parts, '') + version = ''.join(parts) import SConsOptions parser = SConsOptions.Parser(version) diff --git a/src/engine/SCons/Script/MainTests.py b/src/engine/SCons/Script/MainTests.py index 4fe760c..c44c426 100644 --- a/src/engine/SCons/Script/MainTests.py +++ b/src/engine/SCons/Script/MainTests.py @@ -42,7 +42,7 @@ if __name__ == "__main__": tclasses = [] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py index 1ffcc83..0f364d6 100644 --- a/src/engine/SCons/Script/SConsOptions.py +++ b/src/engine/SCons/Script/SConsOptions.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import optparse import re -import string import sys import textwrap @@ -55,9 +54,10 @@ def diskcheck_convert(value): if value is None: return [] if not SCons.Util.is_List(value): - value = string.split(value, ',') + value = value.split(',') result = [] - for v in map(string.lower, value): + for v in value: + v = v.lower() if v == 'all': result = diskcheck_all elif v == 'none': @@ -168,7 +168,7 @@ class SConsValues(optparse.Values): value = diskcheck_convert(value) except ValueError, v: raise SCons.Errors.UserError, "Not a valid diskcheck value: %s"%v - if not self.__dict__.has_key('diskcheck'): + if 'diskcheck' not in self.__dict__: # No --diskcheck= option was specified on the command line. # Set this right away so it can affect the rest of the # file/Node lookups while processing the SConscript files. @@ -197,7 +197,7 @@ class SConsOption(optparse.Option): if self.nargs in (1, '?'): return self.check_value(opt, value) else: - return tuple(map(lambda v, o=opt, s=self: s.check_value(o, v), value)) + return tuple([self.check_value(opt, v) for v in value]) def process(self, opt, value, values, parser): @@ -292,7 +292,7 @@ class SConsOptionParser(optparse.OptionParser): # Value explicitly attached to arg? Pretend it's the next # argument. if "=" in arg: - (opt, next_arg) = string.split(arg, "=", 1) + (opt, next_arg) = arg.split("=", 1) rargs.insert(0, next_arg) had_explicit_value = True else: @@ -356,7 +356,7 @@ class SConsOptionParser(optparse.OptionParser): group = self.add_option_group(group) self.local_option_group = group - result = apply(group.add_option, args, kw) + result = group.add_option(*args, **kw) if result: # The option was added succesfully. We now have to add the @@ -461,7 +461,7 @@ class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter): result.append("%*s%s\n" % (self.help_position, "", line)) elif opts[-1] != "\n": result.append("\n") - return string.join(result, "") + return "".join(result) # For consistent help output across Python versions, we provide a # subclass copy of format_option_strings() and these two variables. @@ -473,7 +473,7 @@ class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter): def format_option_strings(self, option): """Return a comma-separated list of option strings & metavariables.""" if option.takes_value(): - metavar = option.metavar or string.upper(option.dest) + metavar = option.metavar or option.dest.upper() short_opts = [] for sopt in option._short_opts: short_opts.append(self._short_opt_fmt % (sopt, metavar)) @@ -489,7 +489,7 @@ class SConsIndentedHelpFormatter(optparse.IndentedHelpFormatter): else: opts = long_opts + short_opts - return string.join(opts, ", ") + return ", ".join(opts) def Parser(version): """ @@ -580,7 +580,7 @@ def Parser(version): raise OptionValueError("Warning: %s is not a valid config type" % value) setattr(parser.values, option.dest, value) opt_config_help = "Controls Configure subsystem: %s." \ - % string.join(config_options, ", ") + % ", ".join(config_options) op.add_option('--config', nargs=1, type="string", dest="config", default="auto", @@ -623,7 +623,7 @@ def Parser(version): else: raise OptionValueError("Warning: %s is not a valid debug type" % value) opt_debug_help = "Print various types of debugging information: %s." \ - % string.join(debug_options, ", ") + % ", ".join(debug_options) op.add_option('--debug', nargs=1, type="string", dest="debug", default=[], @@ -654,7 +654,7 @@ def Parser(version): SCons.Node.FS.set_duplicate(value) opt_duplicate_help = "Set the preferred duplication methods. Must be one of " \ - + string.join(SCons.Node.FS.Valid_Duplicates, ", ") + + ", ".join(SCons.Node.FS.Valid_Duplicates) op.add_option('--duplicate', nargs=1, type="string", @@ -802,7 +802,7 @@ def Parser(version): def opt_tree(option, opt, value, parser, tree_options=tree_options): import Main tp = Main.TreePrinter() - for o in string.split(value, ','): + for o in value.split(','): if o == 'all': tp.derived = False elif o == 'derived': @@ -816,7 +816,7 @@ def Parser(version): parser.values.tree_printers.append(tp) opt_tree_help = "Print a dependency tree in various formats: %s." \ - % string.join(tree_options, ", ") + % ", ".join(tree_options) op.add_option('--tree', nargs=1, type="string", @@ -846,7 +846,7 @@ def Parser(version): def opt_warn(option, opt, value, parser, tree_options=tree_options): if SCons.Util.is_String(value): - value = string.split(value, ',') + value = value.split(',') parser.values.warn.extend(value) op.add_option('--warn', '--warning', diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index a34278a..1021921 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -27,6 +27,7 @@ files. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -48,7 +49,6 @@ import SCons.Util import os import os.path import re -import string import sys import traceback import types @@ -145,7 +145,7 @@ def Return(*vars, **kw): try: fvars = SCons.Util.flatten(vars) for var in fvars: - for v in string.split(var): + for v in var.split(): retval.append(call_stack[-1].globals[v]) except KeyError, x: raise SCons.Errors.UserError, "Return of non-existent variable '%s'"%x @@ -312,7 +312,7 @@ def SConscript_exception(file=sys.stderr): up to where we exec the SConscript.""" exc_type, exc_value, exc_tb = sys.exc_info() tb = exc_tb - while tb and not tb.tb_frame.f_locals.has_key(stack_bottom): + while tb and stack_bottom not in tb.tb_frame.f_locals: tb = tb.tb_next if not tb: # We did not find our exec statement, so this was actually a bug @@ -334,7 +334,7 @@ def annotate(node): """Annotate a node with the stack frame describing the SConscript file and line number that created it.""" tb = sys.exc_info()[2] - while tb and not tb.tb_frame.f_locals.has_key(stack_bottom): + while tb and stack_bottom not in tb.tb_frame.f_locals: tb = tb.tb_next if not tb: # We did not find any exec of an SConscript file: what?! @@ -369,7 +369,7 @@ class SConsEnvironment(SCons.Environment.Base): This is complicated by the fact that a version string can be something like 3.2b1.""" - version = string.split(string.split(version_string, ' ')[0], '.') + version = version_string.split(' ')[0].split('.') v_major = int(version[0]) v_minor = int(re.match('\d+', version[1]).group()) if len(version) >= 3: @@ -396,11 +396,11 @@ class SConsEnvironment(SCons.Environment.Base): if not SCons.Util.is_List(dirs): dirs = [ dirs ] - dirs = map(str, dirs) + dirs = list(map(str, dirs)) name = kw.get('name', 'SConscript') - files = map(lambda n, name = name: os.path.join(n, name), dirs) + files = [os.path.join(n, name) for n in dirs] elif len(ls) == 1: @@ -459,7 +459,7 @@ class SConsEnvironment(SCons.Environment.Base): if not SCons.Script.sconscript_reading: raise SCons.Errors.UserError, "Calling Configure from Builders is not supported." kw['_depth'] = kw.get('_depth', 0) + 1 - return apply(SCons.Environment.Base.Configure, (self,)+args, kw) + return SCons.Environment.Base.Configure(self, *args, **kw) def Default(self, *targets): SCons.Script._Set_Default_Targets(self, targets) @@ -484,7 +484,7 @@ class SConsEnvironment(SCons.Environment.Base): except AttributeError: python_ver = self._get_major_minor_revision(sys.version)[:2] if python_ver < (major, minor): - v = string.split(sys.version, " ", 1)[0] + v = sys.version.split(" ", 1)[0] print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v) sys.exit(2) @@ -520,7 +520,7 @@ class SConsEnvironment(SCons.Environment.Base): globals.update(global_exports) globals.update(exports) else: - if exports.has_key(v): + if v in exports: globals[v] = exports[v] else: globals[v] = global_exports[v] @@ -530,11 +530,11 @@ class SConsEnvironment(SCons.Environment.Base): def SConscript(self, *ls, **kw): def subst_element(x, subst=self.subst): if SCons.Util.is_List(x): - x = map(subst, x) + x = list(map(subst, x)) else: x = subst(x) return x - ls = map(subst_element, ls) + ls = list(map(subst_element, ls)) subst_kw = {} for key, val in kw.items(): if SCons.Util.is_String(val): @@ -550,7 +550,7 @@ class SConsEnvironment(SCons.Environment.Base): files, exports = self._get_SConscript_filenames(ls, subst_kw) subst_kw['exports'] = exports - return apply(_SConscript, [self.fs,] + files, subst_kw) + return _SConscript(self.fs, *files, **subst_kw) def SConscriptChdir(self, flag): global sconscript_chdir @@ -569,7 +569,7 @@ def Configure(*args, **kw): if not SCons.Script.sconscript_reading: raise SCons.Errors.UserError, "Calling Configure from Builders is not supported." kw['_depth'] = 1 - return apply(SCons.SConf.SConf, args, kw) + return SCons.SConf.SConf(*args, **kw) # It's very important that the DefaultEnvironmentCall() class stay in this # file, with the get_calling_namespaces() function, the compute_exports() @@ -613,7 +613,7 @@ class DefaultEnvironmentCall: def __call__(self, *args, **kw): env = self.factory() method = getattr(env, self.method_name) - return apply(method, args, kw) + return method(*args, **kw) def BuildDefaultGlobals(): diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 18ef114..7763210 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -40,7 +40,6 @@ import time start_time = time.time() import os -import string import sys import UserList @@ -58,7 +57,7 @@ import UserList # the "--debug=memoizer" flag and enable Memoizer before we import any # of the other modules that use it. -_args = sys.argv + string.split(os.environ.get('SCONSFLAGS', '')) +_args = sys.argv + os.environ.get('SCONSFLAGS', '').split() if "--debug=memoizer" in _args: import SCons.Memoize import SCons.Warnings @@ -211,7 +210,7 @@ _build_plus_default = TargetList() def _Add_Arguments(alist): for arg in alist: - a, b = string.split(arg, '=', 1) + a, b = arg.split('=', 1) ARGUMENTS[a] = b ARGLIST.append((a, b)) diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py index f3b4168..936348a 100644 --- a/src/engine/SCons/Subst.py +++ b/src/engine/SCons/Subst.py @@ -26,11 +26,11 @@ SCons string substitution. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import re -import string import types import UserList import UserString @@ -50,7 +50,7 @@ AllowableExceptions = (IndexError, NameError) def SetAllowableExceptions(*excepts): global AllowableExceptions - AllowableExceptions = filter(None, excepts) + AllowableExceptions = [_f for _f in excepts if _f] def raise_exception(exception, target, s): name = exception.__class__.__name__ @@ -152,7 +152,7 @@ class CmdStringHolder(UserString.UserString): else: return self.data -def escape_list(list, escape_func): +def escape_list(mylist, escape_func): """Escape a list of arguments by running the specified escape_func on every object in the list that has an escape() method.""" def escape(obj, escape_func=escape_func): @@ -162,7 +162,7 @@ def escape_list(list, escape_func): return obj else: return e(escape_func) - return map(escape, list) + return list(map(escape, mylist)) class NLWrapper: """A wrapper class that delays turning a list of sources or targets @@ -183,14 +183,14 @@ class NLWrapper: def _return_nodelist(self): return self.nodelist def _gen_nodelist(self): - list = self.list - if list is None: - list = [] - elif not is_Sequence(list): - list = [list] + mylist = self.list + if mylist is None: + mylist = [] + elif not is_Sequence(mylist): + mylist = [mylist] # The map(self.func) call is what actually turns # a list into appropriate proxies. - self.nodelist = SCons.Util.NodeList(map(self.func, list)) + self.nodelist = SCons.Util.NodeList(list(map(self.func, mylist))) self._create_nodelist = self._return_nodelist return self.nodelist _create_nodelist = _gen_nodelist @@ -344,7 +344,7 @@ _regex_remove = [ _rm, None, _remove ] def _rm_list(list): #return [ l for l in list if not l in ('$(', '$)') ] - return filter(lambda l: not l in ('$(', '$)'), list) + return [l for l in list if not l in ('$(', '$)')] def _remove_list(list): result = [] @@ -399,7 +399,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ handles separating command lines into lists of arguments, so see that function if that's what you're looking for. """ - if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0: + if type(strSubst) == types.StringType and strSubst.find('$') < 0: return strSubst class StringSubber: @@ -438,7 +438,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ return s else: key = s[1:] - if key[0] == '{' or string.find(key, '.') >= 0: + if key[0] == '{' or key.find('.') >= 0: if key[0] == '{': key = key[1:-1] try: @@ -450,9 +450,9 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ return '' raise_exception(e, lvars['TARGETS'], s) else: - if lvars.has_key(key): + if key in lvars: s = lvars[key] - elif self.gvars.has_key(key): + elif key in self.gvars: s = self.gvars[key] elif not NameError in AllowableExceptions: raise_exception(NameError(key), lvars['TARGETS'], s) @@ -472,13 +472,13 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ # are probably more the exception than the norm, # so it should be tolerable for now. lv = lvars.copy() - var = string.split(key, '.')[0] + var = key.split('.')[0] lv[var] = '' return self.substitute(s, lv) elif is_Sequence(s): def func(l, conv=self.conv, substitute=self.substitute, lvars=lvars): return conv(substitute(l, lvars)) - return map(func, s) + return list(map(func, s)) elif callable(s): try: s = s(target=lvars['TARGETS'], @@ -523,7 +523,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ if len(result) == 1: result = result[0] else: - result = string.join(map(str, result), '') + result = ''.join(map(str, result)) return result else: return self.expand(args, lvars) @@ -540,7 +540,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ # If we dropped that behavior (or found another way to cover it), # we could get rid of this call completely and just rely on the # Executor setting the variables. - if not lvars.has_key('TARGET'): + if 'TARGET' not in lvars: d = subst_dict(target, source) if d: lvars = lvars.copy() @@ -571,7 +571,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ if mode != SUBST_RAW: # Compress strings of white space characters into # a single space. - result = string.strip(_space_sep.sub(' ', result)) + result = _space_sep.sub(' ', result).strip() elif is_Sequence(result): remove = _list_remove[mode] if remove: @@ -619,9 +619,9 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv self.gvars = gvars if self.mode == SUBST_RAW: - self.add_strip = lambda x, s=self: s.append(x) + self.add_strip = lambda x: self.append(x) else: - self.add_strip = lambda x, s=self: None + self.add_strip = lambda x: None self.in_strip = None self.next_line() @@ -653,7 +653,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv self.close_strip('$)') else: key = s[1:] - if key[0] == '{' or string.find(key, '.') >= 0: + if key[0] == '{' or key.find('.') >= 0: if key[0] == '{': key = key[1:-1] try: @@ -665,9 +665,9 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv return raise_exception(e, lvars['TARGETS'], s) else: - if lvars.has_key(key): + if key in lvars: s = lvars[key] - elif self.gvars.has_key(key): + elif key in self.gvars: s = self.gvars[key] elif not NameError in AllowableExceptions: raise_exception(NameError(), lvars['TARGETS'], s) @@ -680,7 +680,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv # string for the value of the variable name # we just expanded. lv = lvars.copy() - var = string.split(key, '.')[0] + var = key.split('.')[0] lv[var] = '' self.substitute(s, lv, 0) self.this_word() @@ -834,7 +834,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv # If we dropped that behavior (or found another way to cover it), # we could get rid of this call completely and just rely on the # Executor setting the variables. - if not lvars.has_key('TARGET'): + if 'TARGET' not in lvars: d = subst_dict(target, source) if d: lvars = lvars.copy() @@ -870,7 +870,7 @@ def scons_subst_once(strSubst, env, key): We do this with some straightforward, brute-force code here... """ - if type(strSubst) == types.StringType and string.find(strSubst, '$') < 0: + if type(strSubst) == types.StringType and strSubst.find('$') < 0: return strSubst matchlist = ['$' + key, '${' + key + '}'] @@ -880,7 +880,7 @@ def scons_subst_once(strSubst, env, key): if a in matchlist: a = val if is_Sequence(a): - return string.join(map(str, a)) + return ' '.join(map(str, a)) else: return str(a) diff --git a/src/engine/SCons/SubstTests.py b/src/engine/SCons/SubstTests.py index 0dda3a2..6ef15cf 100644 --- a/src/engine/SCons/SubstTests.py +++ b/src/engine/SCons/SubstTests.py @@ -25,7 +25,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import StringIO import sys import types @@ -101,7 +100,7 @@ if os.sep == '/': return str else: def cvt(str): - return string.replace(str, '/', os.sep) + return str.replace('/', os.sep) class SubstTestCase(unittest.TestCase): class MyNode(DummyNode): @@ -242,7 +241,7 @@ class SubstTestCase(unittest.TestCase): input, expect = cases[:2] expect = convert(expect) try: - result = apply(function, (input, env), kwargs) + result = function(input, env, **kwargs) except Exception, e: fmt = " input %s generated %s (%s)" print fmt % (repr(input), e.__class__.__name__, repr(e)) @@ -798,7 +797,7 @@ class scons_subst_list_TestCase(SubstTestCase): def test_scons_subst_list(self): """Test scons_subst_list(): basic substitution""" def convert_lists(expect): - return map(lambda l: map(cvt, l), expect) + return [list(map(cvt, l)) for l in expect] return self.basic_comparisons(scons_subst_list, convert_lists) subst_list_cases = [ @@ -1181,11 +1180,11 @@ class subst_dict_TestCase(unittest.TestCase): s1 = DummyNode('s1') s2 = DummyNode('s2') d = subst_dict(target=[t1, t2], source=[s1, s2]) - TARGETS = map(lambda x: str(x), d['TARGETS']) + TARGETS = [str(x) for x in d['TARGETS']] TARGETS.sort() assert TARGETS == ['t1', 't2'], d['TARGETS'] assert str(d['TARGET']) == 't1', d['TARGET'] - SOURCES = map(lambda x: str(x), d['SOURCES']) + SOURCES = [str(x) for x in d['SOURCES']] SOURCES.sort() assert SOURCES == ['s1', 's2'], d['SOURCES'] assert str(d['SOURCE']) == 's1', d['SOURCE'] @@ -1210,10 +1209,10 @@ class subst_dict_TestCase(unittest.TestCase): s4 = N('s4') s5 = V('s5') d = subst_dict(target=[t3, t4, t5], source=[s3, s4, s5]) - TARGETS = map(lambda x: str(x), d['TARGETS']) + TARGETS = [str(x) for x in d['TARGETS']] TARGETS.sort() assert TARGETS == ['t4', 'v-t3', 'v-t5'], TARGETS - SOURCES = map(lambda x: str(x), d['SOURCES']) + SOURCES = [str(x) for x in d['SOURCES']] SOURCES.sort() assert SOURCES == ['s3', 'v-rstr-s4', 'v-s5'], SOURCES @@ -1231,7 +1230,7 @@ if __name__ == "__main__": ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Taskmaster.py b/src/engine/SCons/Taskmaster.py index c123ca5..66bcdfa 100644 --- a/src/engine/SCons/Taskmaster.py +++ b/src/engine/SCons/Taskmaster.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __doc__ = """ Generic Taskmaster module for the SCons build engine. @@ -52,7 +53,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" from itertools import chain import operator -import string import sys import traceback @@ -1001,14 +1001,14 @@ class Taskmaster: # TODO(1.5) #nclist = [ (n, find_cycle([n], set())) for n in self.pending_children ] - nclist = map(lambda n: (n, find_cycle([n], set())), self.pending_children) + nclist = [(n, find_cycle([n], set())) for n in self.pending_children] # TODO(1.5) #genuine_cycles = [ # node for node, cycle in nclist # if cycle or node.get_state() != NODE_EXECUTED #] - genuine_cycles = filter(lambda t: t[1] or t[0].get_state() != NODE_EXECUTED, nclist) + genuine_cycles = [t for t in nclist if t[1] or t[0].get_state() != NODE_EXECUTED] if not genuine_cycles: # All of the "cycles" found were single nodes in EXECUTED state, # which is to say, they really weren't cycles. Just return. @@ -1017,7 +1017,7 @@ class Taskmaster: desc = 'Found dependency cycle(s):\n' for node, cycle in nclist: if cycle: - desc = desc + " " + string.join(map(str, cycle), " -> ") + "\n" + desc = desc + " " + " -> ".join(map(str, cycle)) + "\n" else: desc = desc + \ " Internal Error: no cycle found for node %s (%s) in state %s\n" % \ diff --git a/src/engine/SCons/TaskmasterTests.py b/src/engine/SCons/TaskmasterTests.py index 7137967..4a0e13a 100644 --- a/src/engine/SCons/TaskmasterTests.py +++ b/src/engine/SCons/TaskmasterTests.py @@ -660,7 +660,7 @@ class TaskmasterTestCase(unittest.TestCase): t = tm.next_task() assert t.targets == [n1], t.targets t.fail_stop() - assert t.targets == [n3], map(str, t.targets) + assert t.targets == [n3], list(map(str, t.targets)) assert t.top == 1, t.top def test_stop(self): diff --git a/src/engine/SCons/Tool/FortranCommon.py b/src/engine/SCons/Tool/FortranCommon.py index 2863f18..f2c828c 100644 --- a/src/engine/SCons/Tool/FortranCommon.py +++ b/src/engine/SCons/Tool/FortranCommon.py @@ -30,7 +30,6 @@ Stuff for processing Fortran, common to all fortran dialects. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import re -import string import os.path import SCons.Action @@ -73,7 +72,7 @@ def _fortranEmitter(target, source, env): # Convert module name to a .mod filename suffix = env.subst('$FORTRANMODSUFFIX', target=target, source=source) moddir = env.subst('$FORTRANMODDIR', target=target, source=source) - modules = map(lambda x, s=suffix: string.lower(x) + s, modules) + modules = [x.lower() + suffix for x in modules] for m in modules: target.append(env.fs.File(m, moddir)) return (target, source) @@ -91,8 +90,8 @@ def ComputeFortranSuffixes(suffixes, ppsuffixes): pre-processed. Both should be sequences, not strings.""" assert len(suffixes) > 0 s = suffixes[0] - sup = string.upper(s) - upper_suffixes = map(string.upper, suffixes) + sup = s.upper() + upper_suffixes = [_.upper() for _ in suffixes] if SCons.Util.case_sensitive_suffixes(s, sup): ppsuffixes.extend(upper_suffixes) else: @@ -135,17 +134,17 @@ def DialectAddToEnv(env, dialect, suffixes, ppsuffixes, support_module = 0): static_obj.add_emitter(suffix, FortranEmitter) shared_obj.add_emitter(suffix, ShFortranEmitter) - if not env.has_key('%sFLAGS' % dialect): + if '%sFLAGS' % dialect not in env: env['%sFLAGS' % dialect] = SCons.Util.CLVar('') - if not env.has_key('SH%sFLAGS' % dialect): + if 'SH%sFLAGS' % dialect not in env: env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect) # If a tool does not define fortran prefix/suffix for include path, use C ones - if not env.has_key('INC%sPREFIX' % dialect): + if 'INC%sPREFIX' % dialect not in env: env['INC%sPREFIX' % dialect] = '$INCPREFIX' - if not env.has_key('INC%sSUFFIX' % dialect): + if 'INC%sSUFFIX' % dialect not in env: env['INC%sSUFFIX' % dialect] = '$INCSUFFIX' env['_%sINCFLAGS' % dialect] = '$( ${_concat(INC%sPREFIX, %sPATH, INC%sSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' % (dialect, dialect, dialect) diff --git a/src/engine/SCons/Tool/JavaCommon.py b/src/engine/SCons/Tool/JavaCommon.py index cc2c536..1dfeefb 100644 --- a/src/engine/SCons/Tool/JavaCommon.py +++ b/src/engine/SCons/Tool/JavaCommon.py @@ -32,7 +32,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path import re -import string java_parsing = 1 @@ -127,7 +126,7 @@ if java_parsing: self.brackets = self.brackets - 1 if len(self.stackBrackets) and \ self.brackets == self.stackBrackets[-1]: - self.listOutputs.append(string.join(self.listClasses, '$')) + self.listOutputs.append('$'.join(self.listClasses)) self.localClasses.pop() self.listClasses.pop() self.anonStacksStack.pop() @@ -179,7 +178,7 @@ if java_parsing: self.__getAnonStack()[-1] = self.__getAnonStack()[-1] + 1 for anon in self.__getAnonStack(): className.append(str(anon)) - self.listOutputs.append(string.join(className, '$')) + self.listOutputs.append('$'.join(className)) self.nextAnon = self.nextAnon + 1 self.__getAnonStack().append(0) @@ -298,7 +297,7 @@ if java_parsing: currstate = currstate.parseToken(token) if trace: trace(token, currstate) if initial.package: - package = string.replace(initial.package, '.', os.sep) + package = initial.package.replace('.', os.sep) return (package, initial.listOutputs) else: diff --git a/src/engine/SCons/Tool/JavaCommonTests.py b/src/engine/SCons/Tool/JavaCommonTests.py index 92649b2..76944c1 100644 --- a/src/engine/SCons/Tool/JavaCommonTests.py +++ b/src/engine/SCons/Tool/JavaCommonTests.py @@ -569,7 +569,7 @@ if __name__ == "__main__": tclasses = [ parse_javaTestCase ] for tclass in tclasses: names = unittest.getTestCaseNames(tclass, 'test_') - suite.addTests(map(tclass, names)) + suite.addTests(list(map(tclass, names))) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Tool/MSCommon/common.py b/src/engine/SCons/Tool/MSCommon/common.py index bb13e9b..3e9f62c 100644 --- a/src/engine/SCons/Tool/MSCommon/common.py +++ b/src/engine/SCons/Tool/MSCommon/common.py @@ -113,7 +113,7 @@ def normalize_env(env, keys): normenv[k] = copy.deepcopy(env[k]).encode('mbcs') for k in keys: - if os.environ.has_key(k): + if k in os.environ: normenv[k] = os.environ[k].encode('mbcs') return normenv @@ -149,7 +149,7 @@ def parse_output(output, keep = ("INCLUDE", "LIB", "LIBPATH", "PATH")): # TODO(1.5): replace with the following list comprehension: #dkeep = dict([(i, []) for i in keep]) - dkeep = dict(map(lambda i: (i, []), keep)) + dkeep = dict([(i, []) for i in keep]) # rdk will keep the regex to match the .bat file output line starts rdk = {} diff --git a/src/engine/SCons/Tool/MSCommon/netframework.py b/src/engine/SCons/Tool/MSCommon/netframework.py index 8fee916..c5f2880 100644 --- a/src/engine/SCons/Tool/MSCommon/netframework.py +++ b/src/engine/SCons/Tool/MSCommon/netframework.py @@ -20,6 +20,7 @@ # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -28,7 +29,6 @@ __doc__ = """ import os import re -import string from common import read_reg, debug @@ -58,14 +58,14 @@ def query_versions(): contents = os.listdir(froot) l = re.compile('v[0-9]+.*') - versions = filter(lambda e, l=l: l.match(e), contents) + versions = [e for e in contents if l.match(e)] def versrt(a,b): # since version numbers aren't really floats... aa = a[1:] bb = b[1:] - aal = string.split(aa, '.') - bbl = string.split(bb, '.') + aal = aa.split('.') + bbl = bb.split('.') # sequence comparison in python is lexicographical # which is exactly what we want. # Note we sort backwards so the highest version is first. diff --git a/src/engine/SCons/Tool/MSCommon/sdk.py b/src/engine/SCons/Tool/MSCommon/sdk.py index fcf07a0..dc07192 100644 --- a/src/engine/SCons/Tool/MSCommon/sdk.py +++ b/src/engine/SCons/Tool/MSCommon/sdk.py @@ -131,7 +131,7 @@ class WindowsSDK(SDKDefinition): """ HKEY_FMT = r'Software\Microsoft\Microsoft SDKs\Windows\v%s\InstallationFolder' def __init__(self, *args, **kw): - apply(SDKDefinition.__init__, (self,)+args, kw) + SDKDefinition.__init__(self, *args, **kw) self.hkey_data = self.version class PlatformSDK(SDKDefinition): @@ -140,7 +140,7 @@ class PlatformSDK(SDKDefinition): """ HKEY_FMT = r'Software\Microsoft\MicrosoftSDK\InstalledSDKS\%s\Install Dir' def __init__(self, *args, **kw): - apply(SDKDefinition.__init__, (self,)+args, kw) + SDKDefinition.__init__(self, *args, **kw) self.hkey_data = self.uuid # @@ -310,7 +310,7 @@ def get_cur_sdk_dir_from_reg(): return val def get_sdk_by_version(mssdk): - if not SupportedSDKMap.has_key(mssdk): + if mssdk not in SupportedSDKMap: msg = "SDK version %s is not supported" % repr(mssdk) raise SCons.Errors.UserError, msg get_installed_sdks() @@ -328,13 +328,13 @@ def get_default_sdk(): def mssdk_setup_env(env): debug('sdk.py:mssdk_setup_env()') - if env.has_key('MSSDK_DIR'): + if 'MSSDK_DIR' in env: sdk_dir = env['MSSDK_DIR'] if sdk_dir is None: return sdk_dir = env.subst(sdk_dir) debug('sdk.py:mssdk_setup_env: Using MSSDK_DIR:%s'%sdk_dir) - elif env.has_key('MSSDK_VERSION'): + elif 'MSSDK_VERSION' in env: sdk_version = env['MSSDK_VERSION'] if sdk_version is None: msg = "SDK version %s is not installed" % repr(mssdk) @@ -343,7 +343,7 @@ def mssdk_setup_env(env): mssdk = get_sdk_by_version(sdk_version) sdk_dir = mssdk.get_sdk_dir() debug('sdk.py:mssdk_setup_env: Using MSSDK_VERSION:%s'%sdk_dir) - elif env.has_key('MSVS_VERSION'): + elif 'MSVS_VERSION' in env: msvs_version = env['MSVS_VERSION'] debug('sdk.py:mssdk_setup_env:Getting MSVS_VERSION from env:%s'%msvs_version) if msvs_version is None: @@ -382,7 +382,7 @@ def mssdk_exists(version=None): sdks = get_installed_sdks() if version is None: return len(sdks) > 0 - return sdks.has_key(version) + return version in sdks # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/MSCommon/vs.py b/src/engine/SCons/Tool/MSCommon/vs.py index b113340..264166f 100644 --- a/src/engine/SCons/Tool/MSCommon/vs.py +++ b/src/engine/SCons/Tool/MSCommon/vs.py @@ -385,7 +385,7 @@ def get_vs_by_version(msvs): global SupportedVSMap debug('vs.py:get_vs_by_version()') - if not SupportedVSMap.has_key(msvs): + if msvs not in SupportedVSMap: msg = "Visual Studio version %s is not supported" % repr(msvs) raise SCons.Errors.UserError, msg get_installed_visual_studios() @@ -415,15 +415,15 @@ def get_default_version(env): version: str the default version. """ - if not env.has_key('MSVS') or not SCons.Util.is_Dict(env['MSVS']): + if 'MSVS' not in env or not SCons.Util.is_Dict(env['MSVS']): # TODO(1.5): #versions = [vs.version for vs in get_installed_visual_studios()] - versions = map(lambda vs: vs.version, get_installed_visual_studios()) + versions = [vs.version for vs in get_installed_visual_studios()] env['MSVS'] = {'VERSIONS' : versions} else: versions = env['MSVS'].get('VERSIONS', []) - if not env.has_key('MSVS_VERSION'): + if 'MSVS_VERSION' not in env: if versions: env['MSVS_VERSION'] = versions[0] #use highest version by default else: @@ -475,7 +475,7 @@ def msvs_setup_env(env): msvs_list = get_installed_visual_studios() # TODO(1.5): #vscommonvarnames = [ vs.common_tools_var for vs in msvs_list ] - vscommonvarnames = map(lambda vs: vs.common_tools_var, msvs_list) + vscommonvarnames = [vs.common_tools_var for vs in msvs_list] nenv = normalize_env(env['ENV'], vscommonvarnames + ['COMSPEC']) output = get_output(batfilename, arch, env=nenv) vars = parse_output(output, vars) @@ -489,7 +489,7 @@ def query_versions(): msvs_list = get_installed_visual_studios() # TODO(1.5) #versions = [ msvs.version for msvs in msvs_list ] - versions = map(lambda msvs: msvs.version, msvs_list) + versions = [msvs.version for msvs in msvs_list] return versions # Local Variables: diff --git a/src/engine/SCons/Tool/PharLapCommon.py b/src/engine/SCons/Tool/PharLapCommon.py index ca19b8a..dc124b5 100644 --- a/src/engine/SCons/Tool/PharLapCommon.py +++ b/src/engine/SCons/Tool/PharLapCommon.py @@ -36,7 +36,6 @@ import os.path import SCons.Errors import SCons.Util import re -import string def getPharLapPath(): """Reads the registry to find the installed path of the Phar Lap ETS @@ -97,14 +96,14 @@ def addPathIfNotExists(env_dict, key, path, sep=os.pathsep): is_list = 1 paths = env_dict[key] if not SCons.Util.is_List(env_dict[key]): - paths = string.split(paths, sep) + paths = paths.split(sep) is_list = 0 - if not os.path.normcase(path) in map(os.path.normcase, paths): + if os.path.normcase(path) not in list(map(os.path.normcase, paths)): paths = [ path ] + paths if is_list: env_dict[key] = paths else: - env_dict[key] = string.join(paths, sep) + env_dict[key] = sep.join(paths) except KeyError: env_dict[key] = path diff --git a/src/engine/SCons/Tool/ToolTests.py b/src/engine/SCons/Tool/ToolTests.py index adcd40a..723ae56 100644 --- a/src/engine/SCons/Tool/ToolTests.py +++ b/src/engine/SCons/Tool/ToolTests.py @@ -45,8 +45,10 @@ class ToolTestCase(unittest.TestCase): return self.dict[key] def __setitem__(self, key, val): self.dict[key] = val + def __contains__(self, key): + return self.dict.__contains__(key) def has_key(self, key): - return self.dict.has_key(key) + return key in self.dict env = Environment() env['BUILDERS'] = {} env['ENV'] = {} diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 910e6a1..b22fb59 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -35,6 +35,7 @@ tool definition. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -170,7 +171,7 @@ class Tool: env.Append(TOOLS = [ self.name ]) if hasattr(self, 'options'): import SCons.Variables - if not env.has_key('options'): + if 'options' not in env: from SCons.Script import ARGUMENTS env['options']=SCons.Variables.Variables(args=ARGUMENTS) opts=env['options'] @@ -178,7 +179,7 @@ class Tool: self.options(opts) opts.Update(env) - apply(self.generate, ( env, ) + args, kw) + self.generate(env, *args, **kw) def __str__(self): return self.name @@ -474,7 +475,7 @@ class ToolInitializerMethod: builder = self.get_builder(env) if builder is None: return [], [] - return apply(builder, args, kw) + return builder(*args, **kw) class ToolInitializer: """ @@ -530,9 +531,9 @@ class ToolInitializer: def Initializers(env): ToolInitializer(env, ['install'], ['_InternalInstall', '_InternalInstallAs']) def Install(self, *args, **kw): - return apply(self._InternalInstall, args, kw) + return self._InternalInstall(*args, **kw) def InstallAs(self, *args, **kw): - return apply(self._InternalInstallAs, args, kw) + return self._InternalInstallAs(*args, **kw) env.AddMethod(Install) env.AddMethod(InstallAs) @@ -546,7 +547,7 @@ def FindTool(tools, env): def FindAllTools(tools, env): def ToolExists(tool, env=env): return Tool(tool).exists(env) - return filter (ToolExists, tools) + return list(filter (ToolExists, tools)) def tool_list(platform, env): @@ -666,7 +667,7 @@ def tool_list(platform, env): fortran_compiler, assembler, ar] + other_tools) - return filter(lambda x: x, tools) + return [x for x in tools if x] # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/bcc32.py b/src/engine/SCons/Tool/bcc32.py index 023ad22..55f871b 100644 --- a/src/engine/SCons/Tool/bcc32.py +++ b/src/engine/SCons/Tool/bcc32.py @@ -31,7 +31,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import SCons.Defaults import SCons.Tool diff --git a/src/engine/SCons/Tool/cc.py b/src/engine/SCons/Tool/cc.py index da169fe..9b404b2 100644 --- a/src/engine/SCons/Tool/cc.py +++ b/src/engine/SCons/Tool/cc.py @@ -45,7 +45,7 @@ def add_common_cc_variables(env): Add underlying common "C compiler" variables that are used by multiple tools (specifically, c++). """ - if not env.has_key('_CCCOMCOM'): + if '_CCCOMCOM' not in env: env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS' # It's a hack to test for darwin here, but the alternative # of creating an applecc.py to contain this seems overkill. @@ -56,10 +56,10 @@ def add_common_cc_variables(env): if env['PLATFORM'] == 'darwin': env['_CCCOMCOM'] = env['_CCCOMCOM'] + ' $_FRAMEWORKPATH' - if not env.has_key('CCFLAGS'): + if 'CCFLAGS' not in env: env['CCFLAGS'] = SCons.Util.CLVar('') - if not env.has_key('SHCCFLAGS'): + if 'SHCCFLAGS' not in env: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') def generate(env): @@ -73,18 +73,6 @@ def generate(env): shared_obj.add_action(suffix, SCons.Defaults.ShCAction) static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter) shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter) -#<<<<<<< .working -# -# env['_CCCOMCOM'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS' -# # It's a hack to test for darwin here, but the alternative of creating -# # an applecc.py to contain this seems overkill. Maybe someday the Apple -# # platform will require more setup and this logic will be moved. -# env['FRAMEWORKS'] = SCons.Util.CLVar('') -# env['FRAMEWORKPATH'] = SCons.Util.CLVar('') -# if env['PLATFORM'] == 'darwin': -# env['_CCCOMCOM'] = env['_CCCOMCOM'] + ' $_FRAMEWORKPATH' -#======= -#>>>>>>> .merge-right.r1907 add_common_cc_variables(env) diff --git a/src/engine/SCons/Tool/dmd.py b/src/engine/SCons/Tool/dmd.py index 4429d4a..d7156dd 100644 --- a/src/engine/SCons/Tool/dmd.py +++ b/src/engine/SCons/Tool/dmd.py @@ -57,7 +57,6 @@ Lib tool variables: __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os -import string import SCons.Action import SCons.Builder @@ -112,7 +111,7 @@ def generate(env): # This is merely for the convenience of the dependency scanner. dmd_path = env.WhereIs(dc) if dmd_path: - x = string.rindex(dmd_path, dc) + x = dmd_path.rindex(dc) phobosDir = dmd_path[:x] + '/../src/phobos' if os.path.isdir(phobosDir): env.Append(DPATH = [phobosDir]) diff --git a/src/engine/SCons/Tool/dvipdf.py b/src/engine/SCons/Tool/dvipdf.py index 80a4b07..ef4d1ee 100644 --- a/src/engine/SCons/Tool/dvipdf.py +++ b/src/engine/SCons/Tool/dvipdf.py @@ -30,6 +30,7 @@ selection method. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -88,7 +89,7 @@ def PDFEmitter(target, source, env): """ def strip_suffixes(n): return not SCons.Util.splitext(str(n))[1] in ['.aux', '.log'] - source = filter(strip_suffixes, source) + source = list(filter(strip_suffixes, source)) return (target, source) def generate(env): diff --git a/src/engine/SCons/Tool/filesystem.py b/src/engine/SCons/Tool/filesystem.py index 4cecb12..31c8abc 100644 --- a/src/engine/SCons/Tool/filesystem.py +++ b/src/engine/SCons/Tool/filesystem.py @@ -44,12 +44,12 @@ def copyto_emitter(target, source, env): n_target = [] for t in target: - n_target = n_target + map( lambda s, t=t: t.File( str( s ) ), source ) + n_target = n_target + [t.File( str( s ) ) for s in source] return (n_target, source) def copy_action_func(target, source, env): - assert( len(target) == len(source) ), "\ntarget: %s\nsource: %s" %(map(str, target),map(str, source)) + assert( len(target) == len(source) ), "\ntarget: %s\nsource: %s" %(list(map(str, target)),list(map(str, source))) for t, s in zip(target, source): if copyFunc(t.get_path(), s.get_path(), env): diff --git a/src/engine/SCons/Tool/fortran.py b/src/engine/SCons/Tool/fortran.py index b944ca2..26c6ff5 100644 --- a/src/engine/SCons/Tool/fortran.py +++ b/src/engine/SCons/Tool/fortran.py @@ -34,7 +34,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import re -import string import SCons.Action import SCons.Defaults diff --git a/src/engine/SCons/Tool/gs.py b/src/engine/SCons/Tool/gs.py index 591eef0..ada169a 100644 --- a/src/engine/SCons/Tool/gs.py +++ b/src/engine/SCons/Tool/gs.py @@ -69,7 +69,7 @@ def generate(env): def exists(env): - if env.has_key('PS2PDF'): + if 'PS2PDF' in env: return env.Detect(env['PS2PDF']) else: return env.Detect(gs) or SCons.Util.WhereIs(gs) diff --git a/src/engine/SCons/Tool/hpc++.py b/src/engine/SCons/Tool/hpc++.py index e1a0040..2b8ed3f 100644 --- a/src/engine/SCons/Tool/hpc++.py +++ b/src/engine/SCons/Tool/hpc++.py @@ -34,7 +34,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import SCons.Util @@ -67,8 +66,8 @@ def generate(env): env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS +Z') # determine version of aCC line = os.popen(acc + ' -V 2>&1').readline().rstrip() - if string.find(line, 'aCC: HP ANSI C++') == 0: - env['CXXVERSION'] = string.split(line)[-1] + if line.find('aCC: HP ANSI C++') == 0: + env['CXXVERSION'] = line.split()[-1] if env['PLATFORM'] == 'cygwin': env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS') diff --git a/src/engine/SCons/Tool/icl.py b/src/engine/SCons/Tool/icl.py index 2d1636e..caa2281 100644 --- a/src/engine/SCons/Tool/icl.py +++ b/src/engine/SCons/Tool/icl.py @@ -40,10 +40,10 @@ import SCons.Tool.intelc def generate(*args, **kw): """Add Builders and construction variables for icl to an Environment.""" - return apply(SCons.Tool.intelc.generate, args, kw) + return SCons.Tool.intelc.generate(*args, **kw) def exists(*args, **kw): - return apply(SCons.Tool.intelc.exists, args, kw) + return SCons.Tool.intelc.exists(*args, **kw) # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/Tool/ifl.py b/src/engine/SCons/Tool/ifl.py index 88dcf59..30b3672 100644 --- a/src/engine/SCons/Tool/ifl.py +++ b/src/engine/SCons/Tool/ifl.py @@ -43,12 +43,12 @@ def generate(env): SCons.Tool.SourceFileScanner.add_scanner('.i', fscan) SCons.Tool.SourceFileScanner.add_scanner('.i90', fscan) - if not env.has_key('FORTRANFILESUFFIXES'): + if 'FORTRANFILESUFFIXES' not in env: env['FORTRANFILESUFFIXES'] = ['.i'] else: env['FORTRANFILESUFFIXES'].append('.i') - if not env.has_key('F90FILESUFFIXES'): + if 'F90FILESUFFIXES' not in env: env['F90FILESUFFIXES'] = ['.i90'] else: env['F90FILESUFFIXES'].append('.i90') diff --git a/src/engine/SCons/Tool/ifort.py b/src/engine/SCons/Tool/ifort.py index e4165de..4b2fd65 100644 --- a/src/engine/SCons/Tool/ifort.py +++ b/src/engine/SCons/Tool/ifort.py @@ -34,8 +34,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string - import SCons.Defaults from SCons.Scanner.Fortran import FortranScan from FortranCommon import add_all_to_env @@ -48,12 +46,12 @@ def generate(env): SCons.Tool.SourceFileScanner.add_scanner('.i', fscan) SCons.Tool.SourceFileScanner.add_scanner('.i90', fscan) - if not env.has_key('FORTRANFILESUFFIXES'): + if 'FORTRANFILESUFFIXES' not in env: env['FORTRANFILESUFFIXES'] = ['.i'] else: env['FORTRANFILESUFFIXES'].append('.i') - if not env.has_key('F90FILESUFFIXES'): + if 'F90FILESUFFIXES' not in env: env['F90FILESUFFIXES'] = ['.i90'] else: env['F90FILESUFFIXES'].append('.i90') @@ -75,7 +73,7 @@ def generate(env): for dialect in ['F77', 'F90', 'FORTRAN', 'F95']: for var in ['%sCOM' % dialect, '%sPPCOM' % dialect, 'SH%sCOM' % dialect, 'SH%sPPCOM' % dialect]: - env[var] = string.replace(env[var], '-o $TARGET', '-object:$TARGET') + env[var] = env[var].replace('-o $TARGET', '-object:$TARGET') env['FORTRANMODDIRPREFIX'] = "/module:" else: env['FORTRANMODDIRPREFIX'] = "-module " diff --git a/src/engine/SCons/Tool/install.py b/src/engine/SCons/Tool/install.py index 06bcfdd..abdd479 100644 --- a/src/engine/SCons/Tool/install.py +++ b/src/engine/SCons/Tool/install.py @@ -76,7 +76,7 @@ def installFunc(target, source, env): raise SCons.Errors.UserError('Missing INSTALL construction variable.') assert len(target)==len(source), \ - "Installing source %s into target %s: target and source lists must have same length."%(map(str, source), map(str, target)) + "Installing source %s into target %s: target and source lists must have same length."%(list(map(str, source)), list(map(str, target))) for t,s in zip(target,source): if install(t.get_path(),s.get_path(),env): return 1 @@ -159,14 +159,14 @@ def InstallBuilderWrapper(env, target=None, source=None, dir=None, **kw): # be relative to the top-level SConstruct directory. target = env.fs.Entry('.'+os.sep+src.name, dnode) #tgt.extend(BaseInstallBuilder(env, target, src, **kw)) - tgt.extend(apply(BaseInstallBuilder, (env, target, src), kw)) + tgt.extend(BaseInstallBuilder(env, target, src, **kw)) return tgt def InstallAsBuilderWrapper(env, target=None, source=None, **kw): result = [] for src, tgt in map(lambda x, y: (x, y), source, target): #result.extend(BaseInstallBuilder(env, tgt, src, **kw)) - result.extend(apply(BaseInstallBuilder, (env, tgt, src), kw)) + result.extend(BaseInstallBuilder(env, tgt, src, **kw)) return result added = None diff --git a/src/engine/SCons/Tool/intelc.py b/src/engine/SCons/Tool/intelc.py index 2cd38bb..e193695 100644 --- a/src/engine/SCons/Tool/intelc.py +++ b/src/engine/SCons/Tool/intelc.py @@ -38,7 +38,7 @@ import math, sys, os.path, glob, string, re is_windows = sys.platform == 'win32' is_win64 = is_windows and (os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64' or - (os.environ.has_key('PROCESSOR_ARCHITEW6432') and + ('PROCESSOR_ARCHITEW6432' in os.environ and os.environ['PROCESSOR_ARCHITEW6432'] == 'AMD64')) is_linux = sys.platform == 'linux2' is_mac = sys.platform == 'darwin' @@ -406,7 +406,7 @@ def generate(env, version=None, abi=None, topdir=None, verbose=0): # Couldn't get it from registry: use default subdir of topdir env.PrependENVPath(p[0], os.path.join(topdir, p[2])) else: - env.PrependENVPath(p[0], string.split(path, os.pathsep)) + env.PrependENVPath(p[0], path.split(os.pathsep)) # print "ICL %s: %s, final=%s"%(p[0], path, str(env['ENV'][p[0]])) if is_windows: @@ -445,7 +445,7 @@ def generate(env, version=None, abi=None, topdir=None, verbose=0): for ld in [envlicdir, reglicdir]: # If the string contains an '@', then assume it's a network # license (port@system) and good by definition. - if ld and (string.find(ld, '@') != -1 or os.path.exists(ld)): + if ld and (ld.find('@') != -1 or os.path.exists(ld)): licdir = ld break if not licdir: diff --git a/src/engine/SCons/Tool/ipkg.py b/src/engine/SCons/Tool/ipkg.py index 10fbc98..8e0940a 100644 --- a/src/engine/SCons/Tool/ipkg.py +++ b/src/engine/SCons/Tool/ipkg.py @@ -36,7 +36,6 @@ packages fake_root. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os -import string import SCons.Builder @@ -56,8 +55,8 @@ def generate(env): # TODO(1.5) #env['IPKGUSER'] = os.popen('id -un').read().strip() #env['IPKGGROUP'] = os.popen('id -gn').read().strip() - env['IPKGUSER'] = string.strip(os.popen('id -un').read()) - env['IPKGGROUP'] = string.strip(os.popen('id -gn').read()) + env['IPKGUSER'] = os.popen('id -un').read().strip() + env['IPKGGROUP'] = os.popen('id -gn').read().strip() env['IPKGFLAGS'] = SCons.Util.CLVar('-o $IPKGUSER -g $IPKGGROUP') env['IPKGSUFFIX'] = '.ipk' diff --git a/src/engine/SCons/Tool/javac.py b/src/engine/SCons/Tool/javac.py index 78d641a..d080af5 100644 --- a/src/engine/SCons/Tool/javac.py +++ b/src/engine/SCons/Tool/javac.py @@ -30,12 +30,12 @@ selection method. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import SCons.Action import SCons.Builder @@ -45,7 +45,7 @@ import SCons.Util def classname(path): """Turn a string (path name) into a Java class name.""" - return string.replace(os.path.normpath(path), os.sep, '.') + return os.path.normpath(path).replace(os.sep, '.') def emit_java_classes(target, source, env): """Create and return lists of source java files @@ -67,20 +67,19 @@ def emit_java_classes(target, source, env): slist = [] js = _my_normcase(java_suffix) - find_java = lambda n, js=js, ljs=len(js): _my_normcase(n[-ljs:]) == js for entry in source: entry = entry.rentry().disambiguate() if isinstance(entry, SCons.Node.FS.File): slist.append(entry) elif isinstance(entry, SCons.Node.FS.Dir): result = SCons.Util.OrderedDict() - def visit(arg, dirname, names, fj=find_java, dirnode=entry.rdir()): - java_files = filter(fj, names) + def visit(arg, dirname, names, dirnode=entry.rdir()): + java_files = [n for n in names if _my_normcase(n[-len(js):]) == js] # The on-disk entries come back in arbitrary order. Sort # them so our target and source lists are determinate. java_files.sort() mydir = dirnode.Dir(dirname) - java_paths = map(lambda f, d=mydir: d.File(f), java_files) + java_paths = [mydir.File(f) for f in java_files] for jp in java_paths: arg[jp] = True @@ -156,8 +155,8 @@ class pathopt: if self.default: path = path + [ env[self.default] ] if path: - return [self.opt, string.join(path, os.pathsep)] - #return self.opt + " " + string.join(path, os.pathsep) + return [self.opt, os.pathsep.join(path)] + #return self.opt + " " + os.pathsep.join(path) else: return [] #return "" @@ -194,7 +193,7 @@ def Java(env, target, source, *args, **kw): b = env.JavaClassFile else: b = env.JavaClassDir - result.extend(apply(b, (t, s) + args, kw)) + result.extend(b(t, s, *args, **kw)) return result diff --git a/src/engine/SCons/Tool/javah.py b/src/engine/SCons/Tool/javah.py index dda5ebb..c092273 100644 --- a/src/engine/SCons/Tool/javah.py +++ b/src/engine/SCons/Tool/javah.py @@ -34,7 +34,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string import SCons.Action import SCons.Builder @@ -93,7 +92,7 @@ def emit_java_headers(target, source, env): target[0]._morph() tlist = [] for s in source: - fname = string.replace(s.attributes.java_classname, '.', '_') + '.h' + fname = s.attributes.java_classname.replace('.', '_') + '.h' t = target[0].File(fname) t.attributes.java_lookupdir = target[0] tlist.append(t) @@ -112,7 +111,7 @@ def JavaHOutFlagGenerator(target, source, env, for_signature): def getJavaHClassPath(env,target, source, for_signature): path = "${SOURCE.attributes.java_classdir}" - if env.has_key('JAVACLASSPATH') and env['JAVACLASSPATH']: + if 'JAVACLASSPATH' in env and env['JAVACLASSPATH']: path = SCons.Util.AppendPath(path, env['JAVACLASSPATH']) return "-classpath %s" % (path) diff --git a/src/engine/SCons/Tool/lex.py b/src/engine/SCons/Tool/lex.py index dd7fe25..280c768 100644 --- a/src/engine/SCons/Tool/lex.py +++ b/src/engine/SCons/Tool/lex.py @@ -35,8 +35,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path -import string - import SCons.Action import SCons.Tool import SCons.Util @@ -62,7 +60,7 @@ def lexEmitter(target, source, env): if option[:l] == fileGenOption: # A file generating option is present, so add the # file name to the target list. - fileName = string.strip(option[l:]) + fileName = option[l:].strip() target.append(fileName) return (target, source) diff --git a/src/engine/SCons/Tool/midl.py b/src/engine/SCons/Tool/midl.py index bf1f2ac..64b927a 100644 --- a/src/engine/SCons/Tool/midl.py +++ b/src/engine/SCons/Tool/midl.py @@ -33,8 +33,6 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import string - import SCons.Action import SCons.Builder import SCons.Defaults @@ -53,10 +51,10 @@ def midl_emitter(target, source, env): midlcom = env['MIDLCOM'] - if string.find(midlcom, '/proxy') != -1: + if midlcom.find('/proxy') != -1: proxy = base + '_p.c' t.append(proxy) - if string.find(midlcom, '/dlldata') != -1: + if midlcom.find('/dlldata') != -1: dlldata = base + '_data.c' t.append(dlldata) diff --git a/src/engine/SCons/Tool/mingw.py b/src/engine/SCons/Tool/mingw.py index da8a59e..8d40a0b 100644 --- a/src/engine/SCons/Tool/mingw.py +++ b/src/engine/SCons/Tool/mingw.py @@ -35,7 +35,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import os.path -import string import SCons.Action import SCons.Builder diff --git a/src/engine/SCons/Tool/mslink.py b/src/engine/SCons/Tool/mslink.py index 5daae51..b1ba1df 100644 --- a/src/engine/SCons/Tool/mslink.py +++ b/src/engine/SCons/Tool/mslink.py @@ -123,7 +123,7 @@ def _dllEmitter(target, source, env, paramtp): '%sPREFIX' % paramtp, '%sSUFFIX' % paramtp, "WINDOWSSHLIBMANIFESTPREFIX", "WINDOWSSHLIBMANIFESTSUFFIX")) - if env.has_key('PDB') and env['PDB']: + if 'PDB' in env and env['PDB']: pdb = env.arg2nodes('$PDB', target=target, source=source)[0] extratargets.append(pdb) target[0].attributes.pdb = pdb @@ -171,7 +171,7 @@ def prog_emitter(target, source, env): "PROGPREFIX", "PROGSUFFIX", "WINDOWSPROGMANIFESTPREFIX", "WINDOWSPROGMANIFESTSUFFIX")) - if env.has_key('PDB') and env['PDB']: + if 'PDB' in env and env['PDB']: pdb = env.arg2nodes('$PDB', target=target, source=source)[0] extratargets.append(pdb) target[0].attributes.pdb = pdb @@ -179,7 +179,7 @@ def prog_emitter(target, source, env): return (target+extratargets,source) def RegServerFunc(target, source, env): - if env.has_key('register') and env['register']: + if 'register' in env and env['register']: ret = regServerAction([target[0]], [source[0]], env) if ret: raise SCons.Errors.UserError, "Unable to register %s" % target[0] diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index 920ac7c..fde93ea 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -35,7 +35,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os.path import re -import string import sys import SCons.Action @@ -55,8 +54,8 @@ CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++'] def validate_vars(env): """Validate the PCH and PCHSTOP construction variables.""" - if env.has_key('PCH') and env['PCH']: - if not env.has_key('PCHSTOP'): + if 'PCH' in env and env['PCH']: + if 'PCHSTOP' not in env: raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined." if not SCons.Util.is_String(env['PCHSTOP']): raise SCons.Errors.UserError, "The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP'] @@ -99,7 +98,7 @@ def object_emitter(target, source, env, parent_emitter): # See issue #2505 for a discussion of what to do if it turns # out this assumption causes trouble in the wild: # http://scons.tigris.org/issues/show_bug.cgi?id=2505 - if env.has_key('PCH'): + if 'PCH' in env: pch = env['PCH'] if str(target[0]) != SCons.Util.splitext(str(pch))[0] + '.obj': env.Depends(target, pch) @@ -254,9 +253,9 @@ def generate(env): env['PCHCOM'] = '$CXX /Fo${TARGETS[1]} $CXXFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS' env['BUILDERS']['PCH'] = pch_builder - if not env.has_key('ENV'): + if 'ENV' not in env: env['ENV'] = {} - if not env['ENV'].has_key('SystemRoot'): # required for dlls in the winsxs folders + if 'SystemRoot' not in env['ENV']: # required for dlls in the winsxs folders env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root() def exists(env): diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py index f43dd94..57098a8 100644 --- a/src/engine/SCons/Tool/msvs.py +++ b/src/engine/SCons/Tool/msvs.py @@ -30,6 +30,7 @@ selection method. # 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 generators ### KEEP FOR COMPATIBILITY FIXERS __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -39,7 +40,6 @@ import ntpath import os import pickle import re -import string import sys import SCons.Builder @@ -57,23 +57,10 @@ from SCons.Defaults import processDefines # DSP/DSW/SLN/VCPROJ files. ############################################################################## -def _hexdigest(s): - """Return a string as a string of hex characters. - """ - # NOTE: This routine is a method in the Python 2.0 interface - # of the native md5 module, but we want SCons to operate all - # the way back to at least Python 1.5.2, which doesn't have it. - h = string.hexdigits - r = '' - for c in s: - i = ord(c) - r = r + h[(i >> 4) & 0xF] + h[i & 0xF] - return r - def xmlify(s): - s = string.replace(s, "&", "&") # do this first - s = string.replace(s, "'", "'") - s = string.replace(s, '"', """) + s = s.replace("&", "&") # do this first + s = s.replace("'", "'") + s = s.replace('"', """) return s external_makefile_guid = '{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}' @@ -88,9 +75,7 @@ def _generateGUID(slnfile, name): # the generated file has a consistent GUID even if we generate # it on a non-Windows platform. m.update(ntpath.normpath(str(slnfile)) + str(name)) - # TODO(1.5) - #solution = m.hexdigest().upper() - solution = string.upper(_hexdigest(m.digest())) + solution = m.hexdigest().upper() # convert most of the signature to GUID form (discard the rest) solution = "{" + solution[:8] + "-" + solution[8:12] + "-" + solution[12:16] + "-" + solution[16:20] + "-" + solution[20:32] + "}" return solution @@ -116,7 +101,7 @@ def msvs_parse_version(s): # which works regardless of how we were invoked. def getExecScriptMain(env, xml=None): scons_home = env.get('SCONS_HOME') - if not scons_home and os.environ.has_key('SCONS_LIB_DIR'): + if not scons_home and 'SCONS_LIB_DIR' in os.environ: scons_home = os.environ['SCONS_LIB_DIR'] if scons_home: exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % scons_home @@ -161,7 +146,7 @@ def makeHierarchy(sources): if len(path): dict = hierarchy for part in path[:-1]: - if not dict.has_key(part): + if part not in dict: dict[part] = {} dict = dict[part] dict[path[-1]] = file @@ -188,7 +173,7 @@ class _DSPGenerator: else: self.dspabs = get_abspath() - if not env.has_key('variant'): + if 'variant' not in env: raise SCons.Errors.InternalError, \ "You must specify a 'variant' argument (i.e. 'Debug' or " +\ "'Release') to create an MSVSProject." @@ -197,7 +182,7 @@ class _DSPGenerator: elif SCons.Util.is_List(env['variant']): variants = env['variant'] - if not env.has_key('buildtarget') or env['buildtarget'] == None: + if 'buildtarget' not in env or env['buildtarget'] == None: buildtarget = [''] elif SCons.Util.is_String(env['buildtarget']): buildtarget = [env['buildtarget']] @@ -219,7 +204,7 @@ class _DSPGenerator: for _ in variants: buildtarget.append(bt) - if not env.has_key('outdir') or env['outdir'] == None: + if 'outdir' not in env or env['outdir'] == None: outdir = [''] elif SCons.Util.is_String(env['outdir']): outdir = [env['outdir']] @@ -241,7 +226,7 @@ class _DSPGenerator: for v in variants: outdir.append(s) - if not env.has_key('runfile') or env['runfile'] == None: + if 'runfile' not in env or env['runfile'] == None: runfile = buildtarget[-1:] elif SCons.Util.is_String(env['runfile']): runfile = [env['runfile']] @@ -269,7 +254,7 @@ class _DSPGenerator: self.env = env - if self.env.has_key('name'): + if 'name' in self.env: self.name = self.env['name'] else: self.name = os.path.basename(SCons.Util.splitext(self.dspfile)[0]) @@ -289,14 +274,14 @@ class _DSPGenerator: self.configs = {} self.nokeep = 0 - if env.has_key('nokeep') and env['variant'] != 0: + if 'nokeep' in env and env['variant'] != 0: self.nokeep = 1 if self.nokeep == 0 and os.path.exists(self.dspabs): self.Parse() for t in zip(sourcenames,self.srcargs): - if self.env.has_key(t[1]): + if t[1] in self.env: if SCons.Util.is_List(self.env[t[1]]): for i in self.env[t[1]]: if not i in self.sources[t[0]]: @@ -308,7 +293,7 @@ class _DSPGenerator: for n in sourcenames: # TODO(1.5): #self.sources[n].sort(lambda a, b: cmp(a.lower(), b.lower())) - self.sources[n].sort(lambda a, b: cmp(string.lower(a), string.lower(b))) + self.sources[n].sort(lambda a, b: cmp(a.lower(), b.lower())) def AddConfig(self, variant, buildtarget, outdir, runfile, cmdargs, dspfile=dspfile): config = Config() @@ -399,7 +384,7 @@ class _GenerateV6DSP(_DSPGenerator): else: self.file.write('\n!ELSEIF "$(CFG)" == "%s - Win32 %s"\n\n' % (name, kind)) - env_has_buildtarget = self.env.has_key('MSVSBUILDTARGET') + env_has_buildtarget = 'MSVSBUILDTARGET' in self.env if not env_has_buildtarget: self.env['MSVSBUILDTARGET'] = buildtarget @@ -409,7 +394,7 @@ class _GenerateV6DSP(_DSPGenerator): '# PROP %sUse_Debug_Libraries ' % (base, base)) # TODO(1.5): #if kind.lower().find('debug') < 0: - if string.find(string.lower(kind), 'debug') < 0: + if kind.lower().find('debug') < 0: self.file.write('0\n') else: self.file.write('1\n') @@ -462,7 +447,7 @@ class _GenerateV6DSP(_DSPGenerator): cats = categories.keys() # TODO(1.5): #cats.sort(lambda a, b: cmp(a.lower(), b.lower())) - cats.sort(lambda a, b: cmp(string.lower(a), string.lower(b))) + cats.sort(lambda a, b: cmp(a.lower(), b.lower())) for kind in cats: if not self.sources[kind]: continue # skip empty groups @@ -470,7 +455,7 @@ class _GenerateV6DSP(_DSPGenerator): self.file.write('# Begin Group "' + kind + '"\n\n') # TODO(1.5) #typelist = categories[kind].replace('|', ';') - typelist = string.replace(categories[kind], '|', ';') + typelist = categories[kind].replace('|', ';') self.file.write('# PROP Default_Filter "' + typelist + '"\n') for file in self.sources[kind]: @@ -495,7 +480,7 @@ class _GenerateV6DSP(_DSPGenerator): while line: # TODO(1.5): #if line.find("# End Project") > -1: - if string.find(line, "# End Project") > -1: + if line.find("# End Project") > -1: break line = dspfile.readline() @@ -674,7 +659,7 @@ class _GenerateV7DSP(_DSPGenerator): runfile = self.configs[kind].runfile cmdargs = self.configs[kind].cmdargs - env_has_buildtarget = self.env.has_key('MSVSBUILDTARGET') + env_has_buildtarget = 'MSVSBUILDTARGET' in self.env if not env_has_buildtarget: self.env['MSVSBUILDTARGET'] = buildtarget @@ -690,8 +675,8 @@ class _GenerateV7DSP(_DSPGenerator): # TODO(1.5) #preprocdefs = xmlify(';'.join(self.env.get('CPPDEFINES', []))) #includepath = xmlify(';'.join(self.env.get('CPPPATH', []))) - preprocdefs = xmlify(string.join(processDefines(self.env.get('CPPDEFINES', [])), ';')) - includepath = xmlify(string.join(self.env.get('CPPPATH', []), ';')) + preprocdefs = xmlify(';'.join(processDefines(self.env.get('CPPDEFINES', [])))) + includepath = xmlify(';'.join(self.env.get('CPPPATH', []))) if not env_has_buildtarget: del self.env['MSVSBUILDTARGET'] @@ -721,7 +706,7 @@ class _GenerateV7DSP(_DSPGenerator): sorteditems = hierarchy.items() # TODO(1.5): #sorteditems.sort(lambda a, b: cmp(a[0].lower(), b[0].lower())) - sorteditems.sort(lambda a, b: cmp(string.lower(a[0]), string.lower(b[0]))) + sorteditems.sort(lambda a, b: cmp(a[0].lower(), b[0].lower())) # First folders, then files for key, value in sorteditems: @@ -754,8 +739,8 @@ class _GenerateV7DSP(_DSPGenerator): cats = categories.keys() # TODO(1.5) #cats.sort(lambda a, b: cmp(a.lower(), b.lower())) - cats.sort(lambda a, b: cmp(string.lower(a), string.lower(b))) - cats = filter(lambda k, s=self: s.sources[k], cats) + cats.sort(lambda a, b: cmp(a.lower(), b.lower())) + cats = [k for k in cats if self.sources[k]] for kind in cats: if len(cats) > 1: self.file.write('\t\t 1: - s = map(os.path.normpath, sources) + s = list(map(os.path.normpath, sources)) # take the dirname because the prefix may include parts # of the filenames (e.g. if you have 'dir\abcd' and # 'dir\acde' then the cp will be 'dir\a' ) cp = os.path.dirname( os.path.commonprefix(s) ) if cp and s[0][len(cp)] == os.sep: # +1 because the filename starts after the separator - sources = map(lambda s, l=len(cp)+1: s[l:], sources) + sources = [s[len(cp)+1:] for s in sources] commonprefix = cp elif len(sources) == 1: commonprefix = os.path.dirname( sources[0] ) @@ -805,7 +790,7 @@ class _GenerateV7DSP(_DSPGenerator): while line: # TODO(1.5) #if line.find('