[Python-checkins] distutils2: merge upstream

tarek.ziade python-checkins at python.org
Sun Jul 4 11:48:40 CEST 2010


tarek.ziade pushed 6f98873a0fc9 to distutils2:

http://hg.python.org/distutils2/rev/6f98873a0fc9
changeset:   346:6f98873a0fc9
parent:      345:880201efc140
parent:      251:32559ebbec5c
user:        Alexis Metaireau <ametaireau at gmail.com>
date:        Sat Jul 03 17:16:42 2010 +0200
summary:     merge upstream
files:       .hgignore, docs/design/pep-0376.txt, docs/design/wiki.rst, docs/source/metadata.rst, src/CONTRIBUTORS.txt, src/distutils2/_backport/tests/test_pkgutil.py, src/distutils2/command/cmd.py, src/distutils2/dist.py, src/distutils2/tests/test_upload.py, src/distutils2/tests/test_version.py, src/setup.py

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -1,5 +1,8 @@
-.*\.pyc$
-.*\.pyo$
-^src/build
-^docs/build
-.*\.swp$
+syntax: glob
+*.py[co]
+__pycache__/
+configure.cache
+build/
+MANIFEST
+dist/
+*.swp
diff --git a/docs/design/pep-0376.txt b/docs/design/pep-0376.txt
--- a/docs/design/pep-0376.txt
+++ b/docs/design/pep-0376.txt
@@ -402,7 +402,7 @@
   ``.egg-info`` directory that contains a PKG-INFO that matches `name` 
   for the `name` metadata.
 
-  Notice that there should be at most one result. The first result founded
+  Notice that there should be at most one result. The first result found
   is returned. If the directory is not found, returns None.
 
 - ``get_file_users(path)`` -> iterator of ``Distribution`` instances.
diff --git a/docs/design/wiki.rst b/docs/design/wiki.rst
--- a/docs/design/wiki.rst
+++ b/docs/design/wiki.rst
@@ -399,7 +399,7 @@
   the folder hierarchy from the module until we find a setup.cfg? A setup.cfg is
   necessary if you use distutils2, is it not?
 
-  -> information founded in setup.cfg will be put in the *FILES* file upon
+  -> information found in setup.cfg will be put in the *FILES* file upon
   installation in the egg-info directory. 
   IOW in the unbuit-egg case, we would need to create that dir, then use 
   pkgutil APIs.
diff --git a/src/CONTRIBUTORS.txt b/src/CONTRIBUTORS.txt
--- a/src/CONTRIBUTORS.txt
+++ b/src/CONTRIBUTORS.txt
@@ -5,7 +5,7 @@
 Distutils2 is a project that was started and that is maintained by
 Tarek Ziadé, and many people are contributing to the project.
 
-If you did, please add your name below in alphabetical order !
+If you did, please add your name below in alphabetical order!
 
 Thanks to:
 
@@ -15,6 +15,8 @@
 - Nicolas Cadou
 - Josip Djolonga
 - Yannick Gringas
+- Jeremy Kloth
+- Martin von Löwis
 - Carl Meyer
 - Alexis Metaireau
 - Michael Mulich
@@ -23,5 +25,3 @@
 - Erik Rose
 - Brian Rosner
 - Alexandre Vassalotti
-- Martin von Löwis
-
diff --git a/src/DEVNOTES.txt b/src/DEVNOTES.txt
--- a/src/DEVNOTES.txt
+++ b/src/DEVNOTES.txt
@@ -3,8 +3,8 @@
 
 - Distutils2 runs from 2.4 to 3.2 (3.x not implemented yet), so
   make sure you don't use a syntax that doesn't work under
-  a specific Python version.
+  one of these Python versions.
 
 - Always run tests.sh before you push a change. This implies
-  that you have all Python versions installed.
+  that you have all Python versions installed from 2.4 to 2.6.
 
diff --git a/src/README.txt b/src/README.txt
--- a/src/README.txt
+++ b/src/README.txt
@@ -2,7 +2,7 @@
 Distutils2
 ==========
 
-Welcome to Distutils2 !
+Welcome to Distutils2!
 
 Distutils2 is the new version of Distutils. It's not backward compatible with
 Distutils but provides more features, and implement most new packaging
@@ -10,6 +10,6 @@
 
 See the documentation at http://packages.python.org/Distutils2 for more info.
 
-**Beware that Distutils2 is its in early stage and should not be used in
+**Beware that Distutils2 is in its early stage and should not be used in
 production. Its API is subject to changes**
 
diff --git a/src/distutils2/README b/src/distutils2/README
--- a/src/distutils2/README
+++ b/src/distutils2/README
@@ -1,4 +1,4 @@
-This directory contains the Distutils package.
+This directory contains the Distutils2 package.
 
 There's a full documentation available at:
 
@@ -8,6 +8,6 @@
 
     http://www.python.org/sigs/distutils-sig/
 
-WARNING: Distutils2 must remain compatible with 2.4
+WARNING: Distutils2 must remain compatible with Python 2.4
 
 $Id: README 70017 2009-02-27 12:53:34Z tarek.ziade $
diff --git a/src/distutils2/__init__.py b/src/distutils2/__init__.py
--- a/src/distutils2/__init__.py
+++ b/src/distutils2/__init__.py
@@ -1,16 +1,20 @@
 """distutils
 
-The main package for the Python Module Distribution Utilities.  Normally
-used from a setup script as
+The main package for the Python Distribution Utilities 2.  Setup
+scripts should import the setup function from distutils2.core:
 
-   from distutils.core import setup
+    from distutils2.core import setup
 
-   setup (...)
+    setup(name=..., version=..., ...)
+
+Third-party tools can use parts of Distutils2 as building blocks
+without causing the other modules to be imported:
+
+    import distutils2.version
+    import distutils2.pypi.simple
+    import distutils2.tests.pypi_server
 """
-__all__ = ['__version__', 'setup']
+__all__ = ['__version__']
 
 __revision__ = "$Id: __init__.py 78020 2010-02-06 16:37:32Z benjamin.peterson $"
 __version__ = "1.0a2"
-
-from distutils2.core import setup
-
diff --git a/src/distutils2/_backport/pkgutil.py b/src/distutils2/_backport/pkgutil.py
--- a/src/distutils2/_backport/pkgutil.py
+++ b/src/distutils2/_backport/pkgutil.py
@@ -1,4 +1,4 @@
-""" Utilities to support packages. """
+"""Utilities to support packages."""
 
 # NOTE: This module must remain compatible with Python 2.3, as it is shared
 # by setuptools for distribution with Python 2.3 and up.
@@ -179,7 +179,7 @@
 iter_importer_modules = simplegeneric(iter_importer_modules)
 
 
-class ImpImporter:
+class ImpImporter(object):
     """:pep:`302` Importer that wraps Python's "classic" import algorithm
 
     ``ImpImporter(dirname)`` produces a :pep:`302` importer that searches that
@@ -242,7 +242,7 @@
                 yield prefix + modname, ispkg
 
 
-class ImpLoader:
+class ImpLoader(object):
     """:pep:`302` Loader that wraps Python's "classic" import algorithm """
 
     code = source = None
@@ -732,6 +732,9 @@
     def __eq__(self, other):
         return isinstance(other, Distribution) and self.path == other.path
 
+    # See http://docs.python.org/reference/datamodel#object.__hash__
+    __hash__ = object.__hash__
+
 
 class EggInfoDistribution(object):
     """Created with the *path* of the ``.egg-info`` directory or file provided
@@ -847,6 +850,9 @@
         return isinstance(other, EggInfoDistribution) and \
                self.path == other.path
 
+    # See http://docs.python.org/reference/datamodel#object.__hash__
+    __hash__ = object.__hash__
+
 
 def _normalize_dist_name(name):
     """Returns a normalized name from the given *name*.
@@ -918,7 +924,7 @@
     returned if one is found that has metadata that matches *name* for the
     *name* metadata field.
 
-    This function only returns the first result founded, as no more than one
+    This function only returns the first result found, as no more than one
     value is expected. If the directory is not found, ``None`` is returned.
 
     :rtype: :class:`Distribution` or :class:`EggInfoDistribution` or None"""
@@ -976,7 +982,7 @@
     then all files and directories ending with ``.egg-info`` are considered
     as well and returns an :class:`EggInfoDistribution` instance.
 
-    This function only returns the first result founded, since no more than
+    This function only returns the first result found, since no more than
     one values are expected. If the directory is not found, returns ``None``.
 
     :parameter version: a version specifier that indicates the version
diff --git a/src/distutils2/_backport/sysconfig.cfg b/src/distutils2/_backport/sysconfig.cfg
--- a/src/distutils2/_backport/sysconfig.cfg
+++ b/src/distutils2/_backport/sysconfig.cfg
@@ -1,6 +1,6 @@
 [globals]
 # These are the useful categories that are sometimes referenced at runtime,
-# using pkgutils.open():
+# using pkgutil.open():
 config             = {confdir}/{distribution.name}         # Configuration files
 appdata            = {datadir}/{distribution.name}         # Non-writable data that is independent of architecture (images, many xml/text files)
 appdata.arch       = {libdir}/{distribution.name}          # Non-writable data that is architecture-dependent (some binary data formats)
diff --git a/src/distutils2/_backport/sysconfig.py b/src/distutils2/_backport/sysconfig.py
--- a/src/distutils2/_backport/sysconfig.py
+++ b/src/distutils2/_backport/sysconfig.py
@@ -5,7 +5,7 @@
 import os
 import re
 from os.path import pardir, abspath
-from ConfigParser import ConfigParser
+from ConfigParser import RawConfigParser
 
 _PREFIX = os.path.normpath(sys.prefix)
 _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
@@ -14,7 +14,7 @@
 # XXX _CONFIG_DIR will be set by the Makefile later
 _CONFIG_DIR = os.path.normpath(os.path.dirname(__file__))
 _CONFIG_FILE = os.path.join(_CONFIG_DIR, 'sysconfig.cfg')
-_SCHEMES = ConfigParser()
+_SCHEMES = RawConfigParser()
 _SCHEMES.read(_CONFIG_FILE)
 _VAR_REPL = re.compile(r'\{([^{]*?)\}')
 
@@ -580,10 +580,11 @@
                 # behaviour.
                 pass
             else:
-                m = re.search(
-                        r'<key>ProductUserVisibleVersion</key>\s*' +
-                        r'<string>(.*?)</string>', f.read())
-                f.close()
+                try:
+                    m = re.search(r'<key>ProductUserVisibleVersion</key>\s*'
+                                  r'<string>(.*?)</string>', f.read())
+                finally:
+                    f.close()
                 if m is not None:
                     macrelease = '.'.join(m.group(1).split('.')[:2])
                 # else: fall back to the default behaviour
diff --git a/src/distutils2/_backport/tarfile.py b/src/distutils2/_backport/tarfile.py
--- a/src/distutils2/_backport/tarfile.py
+++ b/src/distutils2/_backport/tarfile.py
@@ -370,7 +370,7 @@
 #---------------------------
 # internal stream interface
 #---------------------------
-class _LowLevelFile:
+class _LowLevelFile(object):
     """Low-level file object. Supports reading and writing.
        It is used instead of a regular file object for streaming
        access.
@@ -394,7 +394,7 @@
     def write(self, s):
         os.write(self.fd, s)
 
-class _Stream:
+class _Stream(object):
     """Class that serves as an adapter between TarFile and
        a stream-like object.  The stream-like object only
        needs to have a read() or write() method and is accessed
@@ -2003,8 +2003,10 @@
         # Append the tar header and data to the archive.
         if tarinfo.isreg():
             f = bltn_open(name, "rb")
-            self.addfile(tarinfo, f)
-            f.close()
+            try:
+                self.addfile(tarinfo, f)
+            finally:
+                f.close()
 
         elif tarinfo.isdir():
             self.addfile(tarinfo)
@@ -2214,9 +2216,11 @@
         """
         source = self.extractfile(tarinfo)
         target = bltn_open(targetpath, "wb")
-        copyfileobj(source, target)
-        source.close()
-        target.close()
+        try:
+            copyfileobj(source, target)
+        finally:
+            source.close()
+            target.close()
 
     def makeunknown(self, tarinfo, targetpath):
         """Make a file from a TarInfo object with an unknown type
@@ -2423,7 +2427,7 @@
             print >> sys.stderr, msg
 # class TarFile
 
-class TarIter:
+class TarIter(object):
     """Iterator Class.
 
        for tarinfo in TarFile(...):
@@ -2460,7 +2464,7 @@
         return tarinfo
 
 # Helper classes for sparse file support
-class _section:
+class _section(object):
     """Base class for _data and _hole.
     """
     def __init__(self, offset, size):
@@ -2507,7 +2511,7 @@
 #---------------------------------------------
 TAR_PLAIN = 0           # zipfile.ZIP_STORED
 TAR_GZIPPED = 8         # zipfile.ZIP_DEFLATED
-class TarFileCompat:
+class TarFileCompat(object):
     """TarFile class compatible with standard module zipfile's
        ZipFile class.
     """
@@ -2564,8 +2568,10 @@
        are able to handle, else return False.
     """
     try:
-        t = open(name)
-        t.close()
+        try:
+            t = open(name)
+        finally:
+            t.close()
         return True
     except TarError:
         return False
diff --git a/src/distutils2/_backport/tests/test_sysconfig.py b/src/distutils2/_backport/tests/test_sysconfig.py
--- a/src/distutils2/_backport/tests/test_sysconfig.py
+++ b/src/distutils2/_backport/tests/test_sysconfig.py
@@ -8,7 +8,7 @@
 import os
 import shutil
 from copy import copy, deepcopy
-from ConfigParser import ConfigParser
+from ConfigParser import RawConfigParser
 
 from test.test_support import run_unittest, TESTFN
 
@@ -107,7 +107,7 @@
         wanted.sort()
         scheme = scheme.items()
         scheme.sort()
-        self.assertEquals(scheme, wanted)
+        self.assertEqual(scheme, wanted)
 
     def test_get_config_vars(self):
         cvars = get_config_vars()
@@ -120,21 +120,21 @@
         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
                        '[MSC v.1310 32 bit (Intel)]')
         sys.platform = 'win32'
-        self.assertEquals(get_platform(), 'win32')
+        self.assertEqual(get_platform(), 'win32')
 
         # windows XP, amd64
         os.name = 'nt'
         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
                        '[MSC v.1310 32 bit (Amd64)]')
         sys.platform = 'win32'
-        self.assertEquals(get_platform(), 'win-amd64')
+        self.assertEqual(get_platform(), 'win-amd64')
 
         # windows XP, itanium
         os.name = 'nt'
         sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
                        '[MSC v.1310 32 bit (Itanium)]')
         sys.platform = 'win32'
-        self.assertEquals(get_platform(), 'win-ia64')
+        self.assertEqual(get_platform(), 'win-ia64')
 
         # macbook
         os.name = 'posix'
@@ -153,9 +153,9 @@
         maxint = sys.maxint
         try:
             sys.maxint = 2147483647
-            self.assertEquals(get_platform(), 'macosx-10.3-ppc')
+            self.assertEqual(get_platform(), 'macosx-10.3-ppc')
             sys.maxint = 9223372036854775807
-            self.assertEquals(get_platform(), 'macosx-10.3-ppc64')
+            self.assertEqual(get_platform(), 'macosx-10.3-ppc64')
         finally:
             sys.maxint = maxint
 
@@ -173,9 +173,9 @@
         maxint = sys.maxint
         try:
             sys.maxint = 2147483647
-            self.assertEquals(get_platform(), 'macosx-10.3-i386')
+            self.assertEqual(get_platform(), 'macosx-10.3-i386')
             sys.maxint = 9223372036854775807
-            self.assertEquals(get_platform(), 'macosx-10.3-x86_64')
+            self.assertEqual(get_platform(), 'macosx-10.3-x86_64')
         finally:
             sys.maxint = maxint
 
@@ -186,33 +186,33 @@
                                        '-fno-strict-aliasing -fno-common '
                                        '-dynamic -DNDEBUG -g -O3')
 
-        self.assertEquals(get_platform(), 'macosx-10.4-fat')
+        self.assertEqual(get_platform(), 'macosx-10.4-fat')
 
         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
                                        '-fno-strict-aliasing -fno-common '
                                        '-dynamic -DNDEBUG -g -O3')
 
-        self.assertEquals(get_platform(), 'macosx-10.4-intel')
+        self.assertEqual(get_platform(), 'macosx-10.4-intel')
 
         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
                                        '-fno-strict-aliasing -fno-common '
                                        '-dynamic -DNDEBUG -g -O3')
-        self.assertEquals(get_platform(), 'macosx-10.4-fat3')
+        self.assertEqual(get_platform(), 'macosx-10.4-fat3')
 
         get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
                                        '-fno-strict-aliasing -fno-common '
                                        '-dynamic -DNDEBUG -g -O3')
-        self.assertEquals(get_platform(), 'macosx-10.4-universal')
+        self.assertEqual(get_platform(), 'macosx-10.4-universal')
 
         get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
                                        '/Developer/SDKs/MacOSX10.4u.sdk  '
                                        '-fno-strict-aliasing -fno-common '
                                        '-dynamic -DNDEBUG -g -O3')
 
-        self.assertEquals(get_platform(), 'macosx-10.4-fat64')
+        self.assertEqual(get_platform(), 'macosx-10.4-fat64')
 
         for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
             get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
@@ -220,7 +220,7 @@
                                            '-fno-strict-aliasing -fno-common '
                                            '-dynamic -DNDEBUG -g -O3'%(arch,))
 
-            self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,))
+            self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,))
 
         # linux debian sarge
         os.name = 'posix'
@@ -230,7 +230,7 @@
         self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
                     '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
 
-        self.assertEquals(get_platform(), 'linux-i686')
+        self.assertEqual(get_platform(), 'linux-i686')
 
         # XXX more platforms to tests here
 
@@ -241,11 +241,11 @@
     def test_get_scheme_names(self):
         wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'posix_home',
                   'posix_prefix', 'posix_user')
-        self.assertEquals(get_scheme_names(), wanted)
+        self.assertEqual(get_scheme_names(), wanted)
 
     def test_expand_globals(self):
 
-        config = ConfigParser()
+        config = RawConfigParser()
         config.add_section('globals')
         config.set('globals', 'foo', 'ok')
         config.add_section('posix')
@@ -254,8 +254,8 @@
 
         _expand_globals(config)
 
-        self.assertEquals(config.get('posix', 'foo'), 'ok')
-        self.assertEquals(config.get('posix', 'more'), '/etc/ok')
+        self.assertEqual(config.get('posix', 'foo'), 'ok')
+        self.assertEqual(config.get('posix', 'more'), '/etc/ok')
 
         # we might not have globals after all
         # extending again (==no more globals section)
diff --git a/src/distutils2/command/bdist.py b/src/distutils2/command/bdist.py
--- a/src/distutils2/command/bdist.py
+++ b/src/distutils2/command/bdist.py
@@ -62,7 +62,7 @@
                       'os2': 'zip'}
 
     # Establish the preferred order (for the --help-formats option).
-    format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
+    format_commands = ['gztar', 'bztar', 'ztar', 'tar',
                        'wininst', 'zip', 'msi']
 
     # And the real information.
@@ -96,7 +96,7 @@
 
         # 'bdist_base' -- parent of per-built-distribution-format
         # temporary directories (eg. we'll probably have
-        # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
+        # "build/bdist.<plat>/dumb", etc.)
         if self.bdist_base is None:
             build_base = self.get_finalized_command('build').build_base
             self.bdist_base = os.path.join(build_base,
@@ -126,7 +126,7 @@
         # Reinitialize and run each command.
         for i in range(len(self.formats)):
             cmd_name = commands[i]
-            sub_cmd = self.reinitialize_command(cmd_name)
+            sub_cmd = self.get_reinitialized_command(cmd_name)
 
             # passing the owner and group names for tar archiving
             if cmd_name == 'bdist_dumb':
diff --git a/src/distutils2/command/bdist_dumb.py b/src/distutils2/command/bdist_dumb.py
--- a/src/distutils2/command/bdist_dumb.py
+++ b/src/distutils2/command/bdist_dumb.py
@@ -85,7 +85,7 @@
         if not self.skip_build:
             self.run_command('build')
 
-        install = self.reinitialize_command('install', reinit_subcommands=1)
+        install = self.get_reinitialized_command('install', reinit_subcommands=1)
         install.root = self.bdist_dir
         install.skip_build = self.skip_build
         install.warn_dir = 0
diff --git a/src/distutils2/command/bdist_msi.py b/src/distutils2/command/bdist_msi.py
--- a/src/distutils2/command/bdist_msi.py
+++ b/src/distutils2/command/bdist_msi.py
@@ -177,12 +177,12 @@
         if not self.skip_build:
             self.run_command('build')
 
-        install = self.reinitialize_command('install', reinit_subcommands=1)
+        install = self.get_reinitialized_command('install', reinit_subcommands=1)
         install.prefix = self.bdist_dir
         install.skip_build = self.skip_build
         install.warn_dir = 0
 
-        install_lib = self.reinitialize_command('install_lib')
+        install_lib = self.get_reinitialized_command('install_lib')
         # we do not want to include pyc or pyo files
         install_lib.compile = 0
         install_lib.optimize = 0
diff --git a/src/distutils2/command/bdist_wininst.py b/src/distutils2/command/bdist_wininst.py
--- a/src/distutils2/command/bdist_wininst.py
+++ b/src/distutils2/command/bdist_wininst.py
@@ -126,13 +126,13 @@
         if not self.skip_build:
             self.run_command('build')
 
-        install = self.reinitialize_command('install', reinit_subcommands=1)
+        install = self.get_reinitialized_command('install', reinit_subcommands=1)
         install.root = self.bdist_dir
         install.skip_build = self.skip_build
         install.warn_dir = 0
         install.plat_name = self.plat_name
 
-        install_lib = self.reinitialize_command('install_lib')
+        install_lib = self.get_reinitialized_command('install_lib')
         # we do not want to include pyc or pyo files
         install_lib.compile = 0
         install_lib.optimize = 0
diff --git a/src/distutils2/command/cmd.py b/src/distutils2/command/cmd.py
--- a/src/distutils2/command/cmd.py
+++ b/src/distutils2/command/cmd.py
@@ -19,7 +19,7 @@
 except ImportError:
     from distutils2._backport.shutil import make_archive
 
-class Command:
+class Command(object):
     """Abstract base class for defining command classes, the "worker bees"
     of the Distutils.  A useful analogy for command classes is to think of
     them as subroutines with local variables called "options".  The options
@@ -188,6 +188,31 @@
         """
         log.log(level, msg)
 
+    # -- External interface --------------------------------------------
+    # (called by outsiders)
+
+    def get_source_files(self):
+        """Return the list of files that are used as inputs to this command,
+        i.e. the files used to generate the output files.  The result is used
+        by the `sdist` command in determining the set of default files.
+
+        Command classes should implement this method if they operate on files
+        from the source tree.
+        """
+        return []
+
+    def get_outputs(self):
+        """Return the list of files that would be produced if this command
+        were actually run.  Not affected by the "dry-run" flag or whether
+        any other commands have been run.
+
+        Command classes should implement this method if they produce any
+        output files that get consumed by another command.  e.g., `build_ext`
+        returns the list of built extension modules, but not any temporary
+        files used in the compilation process.
+        """
+        return []
+
     # -- Option validation methods -------------------------------------
     # (these are very handy in writing the 'finalize_options()' method)
     #
@@ -307,10 +332,8 @@
         cmd_obj.ensure_finalized()
         return cmd_obj
 
-    # XXX rename to 'get_reinitialized_command()'? (should do the
-    # same in dist.py, if so)
-    def reinitialize_command(self, command, reinit_subcommands=0):
-        return self.distribution.reinitialize_command(
+    def get_reinitialized_command(self, command, reinit_subcommands=0):
+        return self.distribution.get_reinitialized_command(
             command, reinit_subcommands)
 
     def run_command(self, command):
diff --git a/src/distutils2/command/sdist.py b/src/distutils2/command/sdist.py
--- a/src/distutils2/command/sdist.py
+++ b/src/distutils2/command/sdist.py
@@ -20,7 +20,7 @@
 from distutils2.core import Command
 from distutils2 import util
 from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError,
-                              DistutilsTemplateError)
+                               DistutilsTemplateError)
 from distutils2.manifest import Manifest
 from distutils2 import log
 from distutils2.util import convert_path, newer
diff --git a/src/distutils2/compiler/bcppcompiler.py b/src/distutils2/compiler/bcppcompiler.py
--- a/src/distutils2/compiler/bcppcompiler.py
+++ b/src/distutils2/compiler/bcppcompiler.py
@@ -16,7 +16,7 @@
 import os
 
 from distutils2.errors import (DistutilsExecError, CompileError, LibError,
-                              LinkError, UnknownFileError)
+                               LinkError, UnknownFileError)
 from distutils2.compiler.ccompiler import CCompiler, gen_preprocess_options
 from distutils2.file_util import write_file
 from distutils2.dep_util import newer
diff --git a/src/distutils2/compiler/ccompiler.py b/src/distutils2/compiler/ccompiler.py
--- a/src/distutils2/compiler/ccompiler.py
+++ b/src/distutils2/compiler/ccompiler.py
@@ -10,7 +10,7 @@
 import re
 
 from distutils2.errors import (CompileError, LinkError, UnknownFileError,
-                              DistutilsPlatformError, DistutilsModuleError)
+                               DistutilsPlatformError, DistutilsModuleError)
 from distutils2.spawn import spawn
 from distutils2.util import split_quoted, execute, newer_group
 from distutils2 import log
@@ -76,7 +76,7 @@
 
         compiler.shared_lib_extension = so_ext
 
-class CCompiler:
+class CCompiler(object):
     """Abstract base class to define the interface that must be implemented
     by real compiler classes.  Also has some utility methods used by
     several compiler classes.
@@ -800,14 +800,16 @@
             library_dirs = []
         fd, fname = tempfile.mkstemp(".c", funcname, text=True)
         f = os.fdopen(fd, "w")
-        for incl in includes:
-            f.write("""#include "%s"\n""" % incl)
-        f.write("""\
+        try:
+            for incl in includes:
+                f.write("""#include "%s"\n""" % incl)
+            f.write("""\
 main (int argc, char **argv) {
     %s();
 }
 """ % funcname)
-        f.close()
+        finally:
+            f.close()
         try:
             objects = self.compile([fname], include_dirs=include_dirs)
         except CompileError:
@@ -1048,7 +1050,7 @@
         module_name = "distutils2.compiler." + module_name
         __import__ (module_name)
         module = sys.modules[module_name]
-        klass = vars(module)[class_name]
+        cls = vars(module)[class_name]
     except ImportError:
         raise DistutilsModuleError, \
               "can't compile C/C++ code: unable to load module '%s'" % \
@@ -1061,7 +1063,7 @@
     # XXX The None is necessary to preserve backwards compatibility
     # with classes that expect verbose to be the first positional
     # argument.
-    return klass(None, dry_run, force)
+    return cls(None, dry_run, force)
 
 
 def gen_preprocess_options(macros, include_dirs):
diff --git a/src/distutils2/compiler/emxccompiler.py b/src/distutils2/compiler/emxccompiler.py
--- a/src/distutils2/compiler/emxccompiler.py
+++ b/src/distutils2/compiler/emxccompiler.py
@@ -25,9 +25,8 @@
 from warnings import warn
 
 from distutils2.compiler.unixccompiler import UnixCCompiler
-from distutils2.util import write_file
 from distutils2.errors import DistutilsExecError, CompileError, UnknownFileError
-from distutils2.util import get_compiler_versions
+from distutils2.util import get_compiler_versions, write_file
 
 class EMXCCompiler (UnixCCompiler):
 
@@ -273,8 +272,10 @@
         # It would probably better to read single lines to search.
         # But we do this only once, and it is fast enough
         f = open(fn)
-        s = f.read()
-        f.close()
+        try:
+            s = f.read()
+        finally:
+            f.close()
 
     except IOError, exc:
         # if we can't read this file, we cannot say it is wrong
diff --git a/src/distutils2/compiler/msvc9compiler.py b/src/distutils2/compiler/msvc9compiler.py
--- a/src/distutils2/compiler/msvc9compiler.py
+++ b/src/distutils2/compiler/msvc9compiler.py
@@ -20,7 +20,7 @@
 import re
 
 from distutils2.errors import (DistutilsExecError, DistutilsPlatformError,
-                              CompileError, LibError, LinkError)
+                               CompileError, LibError, LinkError)
 from distutils2.compiler.ccompiler import CCompiler, gen_lib_options
 from distutils2 import log
 from distutils2.util import get_platform
@@ -50,7 +50,7 @@
     'win-ia64' : 'ia64',
 }
 
-class Reg:
+class Reg(object):
     """Helper class to read values from the registry
     """
 
@@ -112,7 +112,7 @@
         return s
     convert_mbcs = staticmethod(convert_mbcs)
 
-class MacroExpander:
+class MacroExpander(object):
 
     def __init__(self, version):
         self.macros = {}
diff --git a/src/distutils2/compiler/msvccompiler.py b/src/distutils2/compiler/msvccompiler.py
--- a/src/distutils2/compiler/msvccompiler.py
+++ b/src/distutils2/compiler/msvccompiler.py
@@ -15,7 +15,7 @@
 import string
 
 from distutils2.errors import (DistutilsExecError, DistutilsPlatformError,
-                              CompileError, LibError, LinkError)
+                               CompileError, LibError, LinkError)
 from distutils2.compiler.ccompiler import CCompiler, gen_lib_options
 from distutils2 import log
 
@@ -104,7 +104,7 @@
             pass
     return s
 
-class MacroExpander:
+class MacroExpander(object):
 
     def __init__(self, version):
         self.macros = {}
diff --git a/src/distutils2/compiler/unixccompiler.py b/src/distutils2/compiler/unixccompiler.py
--- a/src/distutils2/compiler/unixccompiler.py
+++ b/src/distutils2/compiler/unixccompiler.py
@@ -19,10 +19,10 @@
 from types import StringType, NoneType
 
 from distutils2.util import newer
-from distutils2.compiler.ccompiler import \
-     CCompiler, gen_preprocess_options, gen_lib_options
-from distutils2.errors import \
-     DistutilsExecError, CompileError, LibError, LinkError
+from distutils2.compiler.ccompiler import (CCompiler, gen_preprocess_options,
+                                           gen_lib_options)
+from distutils2.errors import (DistutilsExecError, CompileError,
+                               LibError, LinkError)
 from distutils2 import log
 
 try:
diff --git a/src/distutils2/config.py b/src/distutils2/config.py
--- a/src/distutils2/config.py
+++ b/src/distutils2/config.py
@@ -4,7 +4,7 @@
 that uses .pypirc in the distutils.command package.
 """
 import os
-from ConfigParser import ConfigParser
+from ConfigParser import RawConfigParser
 
 from distutils2.command.cmd import Command
 
@@ -59,7 +59,7 @@
         if os.path.exists(rc):
             self.announce('Using PyPI login from %s' % rc)
             repository = self.repository or self.DEFAULT_REPOSITORY
-            config = ConfigParser()
+            config = RawConfigParser()
             config.read(rc)
             sections = config.sections()
             if 'distutils' in sections:
diff --git a/src/distutils2/core.py b/src/distutils2/core.py
--- a/src/distutils2/core.py
+++ b/src/distutils2/core.py
@@ -2,8 +2,9 @@
 
 The only module that needs to be imported to use the Distutils; provides
 the 'setup' function (which is to be called from the setup script).  Also
-indirectly provides the Distribution and Command classes, although they are
-really defined in distutils2.dist and distutils2.cmd.
+exports useful classes so that setup scripts can import them from here
+although they are really defined in other modules: Distribution, Command,
+PyPIRCommand, Extension, find_packages.
 """
 
 __revision__ = "$Id: core.py 77704 2010-01-23 09:23:15Z tarek.ziade $"
@@ -12,7 +13,7 @@
 import os
 
 from distutils2.errors import (DistutilsSetupError, DistutilsArgError,
-                              DistutilsError, CCompilerError)
+                               DistutilsError, CCompilerError)
 from distutils2.util import grok_environment_error
 
 # Mainly import these so setup scripts can "from distutils2.core import" them.
@@ -20,6 +21,7 @@
 from distutils2.command.cmd import Command
 from distutils2.config import PyPIRCCommand
 from distutils2.extension import Extension
+from distutils2.util import find_packages
 
 # This is a barebones help message generated displayed when the user
 # runs the setup script with no arguments at all.  More useful help
@@ -94,11 +96,7 @@
 
     # Determine the distribution class -- either caller-supplied or
     # our Distribution (see below).
-    klass = attrs.get('distclass')
-    if klass:
-        del attrs['distclass']
-    else:
-        klass = Distribution
+    distclass = attrs.pop('distclass', Distribution)
 
     if 'script_name' not in attrs:
         attrs['script_name'] = os.path.basename(sys.argv[0])
@@ -108,7 +106,7 @@
     # Create the Distribution instance, using the remaining arguments
     # (ie. everything except distclass) to initialize it
     try:
-        _setup_distribution = dist = klass(attrs)
+        _setup_distribution = dist = distclass(attrs)
     except DistutilsSetupError, msg:
         if 'name' in attrs:
             raise SystemExit, "error in %s setup command: %s" % \
diff --git a/src/distutils2/depgraph.py b/src/distutils2/depgraph.py
--- a/src/distutils2/depgraph.py
+++ b/src/distutils2/depgraph.py
@@ -13,7 +13,7 @@
     """
     Represents a dependency graph between distributions.
 
-    The depedency relationships are stored in an ``adjacency_list`` that maps
+    The dependency relationships are stored in an ``adjacency_list`` that maps
     distributions to a list of ``(other, label)`` tuples where  ``other``
     is a distribution and the edge is labelled with ``label`` (i.e. the version
     specifier, if such was provided). Also, for more efficient traversal, for
diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py
--- a/src/distutils2/dist.py
+++ b/src/distutils2/dist.py
@@ -13,8 +13,10 @@
 except ImportError:
     warnings = None
 
+from ConfigParser import RawConfigParser
+
 from distutils2.errors import (DistutilsOptionError, DistutilsArgError,
-                              DistutilsModuleError, DistutilsClassError)
+                               DistutilsModuleError, DistutilsClassError)
 from distutils2.fancy_getopt import FancyGetopt, translate_longopt
 from distutils2.util import check_environ, strtobool
 from distutils2 import log
@@ -248,7 +250,7 @@
                 elif hasattr(self, key):
                     setattr(self, key, val)
                 else:
-                    msg = "Unknown distribution option: %s" % repr(key)
+                    msg = "Unknown distribution option: %r" % key
                     if warnings is not None:
                         warnings.warn(msg)
                     else:
@@ -362,14 +364,12 @@
         return files
 
     def parse_config_files(self, filenames=None):
-        from ConfigParser import ConfigParser
-
         if filenames is None:
             filenames = self.find_config_files()
 
         log.debug("Distribution.parse_config_files():")
 
-        parser = ConfigParser()
+        parser = RawConfigParser()
         for filename in filenames:
             log.debug("  reading %s" % filename)
             parser.read(filename)
@@ -383,7 +383,7 @@
                         opt = opt.replace('-', '_')
                         opt_dict[opt] = (filename, val)
 
-            # Make the ConfigParser forget everything (so we retain
+            # Make the RawConfigParser forget everything (so we retain
             # the original filenames that options come from)
             parser.__init__()
 
@@ -627,16 +627,16 @@
 
         for command in self.commands:
             if isinstance(command, type) and issubclass(command, Command):
-                klass = command
+                cls = command
             else:
-                klass = self.get_command_class(command)
-            if (hasattr(klass, 'help_options') and
-                isinstance(klass.help_options, list)):
-                parser.set_option_table(klass.user_options +
-                                        fix_help_options(klass.help_options))
+                cls = self.get_command_class(command)
+            if (hasattr(cls, 'help_options') and
+                isinstance(cls.help_options, list)):
+                parser.set_option_table(cls.user_options +
+                                        fix_help_options(cls.help_options))
             else:
-                parser.set_option_table(klass.user_options)
-            parser.print_help("Options for '%s' command:" % klass.__name__)
+                parser.set_option_table(cls.user_options)
+            parser.print_help("Options for '%s' command:" % cls.__name__)
             print('')
 
         print(gen_usage(self.script_name))
@@ -688,11 +688,11 @@
         print(header + ":")
 
         for cmd in commands:
-            klass = self.cmdclass.get(cmd)
-            if not klass:
-                klass = self.get_command_class(cmd)
+            cls = self.cmdclass.get(cmd)
+            if not cls:
+                cls = self.get_command_class(cmd)
             try:
-                description = klass.description
+                description = cls.description
             except AttributeError:
                 description = "(no description available)"
 
@@ -754,11 +754,11 @@
 
         rv = []
         for cmd in (std_commands + extra_commands):
-            klass = self.cmdclass.get(cmd)
-            if not klass:
-                klass = self.get_command_class(cmd)
+            cls = self.cmdclass.get(cmd)
+            if not cls:
+                cls = self.get_command_class(cmd)
             try:
-                description = klass.description
+                description = cls.description
             except AttributeError:
                 description = "(no description available)"
             rv.append((cmd, description))
@@ -790,13 +790,13 @@
         Raises DistutilsModuleError if the expected module could not be
         found, or if that module does not define the expected class.
         """
-        klass = self.cmdclass.get(command)
-        if klass:
-            return klass
+        cls = self.cmdclass.get(command)
+        if cls:
+            return cls
 
         for pkgname in self.get_command_packages():
             module_name = "%s.%s" % (pkgname, command)
-            klass_name = command
+            class_name = command
 
             try:
                 __import__ (module_name)
@@ -805,14 +805,14 @@
                 continue
 
             try:
-                klass = getattr(module, klass_name)
+                cls = getattr(module, class_name)
             except AttributeError:
                 raise DistutilsModuleError, \
                       "invalid command '%s' (no class '%s' in module '%s')" \
-                      % (command, klass_name, module_name)
+                      % (command, class_name, module_name)
 
-            self.cmdclass[command] = klass
-            return klass
+            self.cmdclass[command] = cls
+            return cls
 
         raise DistutilsModuleError("invalid command '%s'" % command)
 
@@ -828,8 +828,8 @@
             log.debug("Distribution.get_command_obj(): " \
                       "creating '%s' command object" % command)
 
-            klass = self.get_command_class(command)
-            cmd_obj = self.command_obj[command] = klass(self)
+            cls = self.get_command_class(command)
+            cmd_obj = self.command_obj[command] = cls(self)
             self.have_run[command] = 0
 
             # Set any options that were supplied in config files
@@ -885,7 +885,7 @@
             except ValueError, msg:
                 raise DistutilsOptionError, msg
 
-    def reinitialize_command(self, command, reinit_subcommands=0):
+    def get_reinitialized_command(self, command, reinit_subcommands=0):
         """Reinitializes a command to the state it was in when first
         returned by 'get_command_obj()': ie., initialized but not yet
         finalized.  This provides the opportunity to sneak option
@@ -920,7 +920,7 @@
 
         if reinit_subcommands:
             for sub in command.get_sub_commands():
-                self.reinitialize_command(sub, reinit_subcommands)
+                self.get_reinitialized_command(sub, reinit_subcommands)
 
         return command
 
diff --git a/src/distutils2/extension.py b/src/distutils2/extension.py
--- a/src/distutils2/extension.py
+++ b/src/distutils2/extension.py
@@ -23,7 +23,7 @@
 # import that large-ish module (indirectly, through distutils.core) in
 # order to do anything.
 
-class Extension:
+class Extension(object):
     """Just a collection of attributes that describes an extension
     module and everything needed to build it (hopefully in a portable
     way, but there are hooks that let you be as unportable as you need).
diff --git a/src/distutils2/fancy_getopt.py b/src/distutils2/fancy_getopt.py
--- a/src/distutils2/fancy_getopt.py
+++ b/src/distutils2/fancy_getopt.py
@@ -30,7 +30,7 @@
 # (for use as attributes of some object).
 longopt_xlate = string.maketrans('-', '_')
 
-class FancyGetopt:
+class FancyGetopt(object):
     """Wrapper around the standard 'getopt()' module that provides some
     handy extra functionality:
       * short and long options are tied together
@@ -473,7 +473,7 @@
     return string.translate(opt, longopt_xlate)
 
 
-class OptionDummy:
+class OptionDummy(object):
     """Dummy class just used as a place to hold command-line option
     values as instance attributes."""
 
diff --git a/src/distutils2/log.py b/src/distutils2/log.py
--- a/src/distutils2/log.py
+++ b/src/distutils2/log.py
@@ -11,14 +11,14 @@
 
 import sys
 
-class Log:
+class Log(object):
 
     def __init__(self, threshold=WARN):
         self.threshold = threshold
 
     def _log(self, level, msg, args):
         if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
-            raise ValueError('%s wrong log level' % str(level))
+            raise ValueError('%s wrong log level' % level)
 
         if level >= self.threshold:
             if args:
diff --git a/src/distutils2/metadata.py b/src/distutils2/metadata.py
--- a/src/distutils2/metadata.py
+++ b/src/distutils2/metadata.py
@@ -105,7 +105,6 @@
     keys = fields.keys()
     possible_versions = ['1.0', '1.1', '1.2']
 
-
     # first let's try to see if a field is not part of one of the version
     for key in keys:
         if key not in _241_FIELDS and '1.0' in possible_versions:
@@ -128,9 +127,9 @@
         raise MetadataConflictError('You used incompatible 1.1 and 1.2 fields')
 
     # we have the choice, either 1.0, or 1.2
-    #   - 1.0 has a broken Summary field but work with all tools
+    #   - 1.0 has a broken Summary field but works with all tools
     #   - 1.1 is to avoid
-    #   - 1.2 fixes Summary but is not spreaded yet
+    #   - 1.2 fixes Summary but is not widespread yet
     if not is_1_1 and not is_1_2:
         # we couldn't find any specific marker
         if PKG_INFO_PREFERRED_VERSION in possible_versions:
@@ -185,12 +184,12 @@
 class DistributionMetadata(object):
     """Distribution meta-data class (1.0 or 1.2).
     """
-    def __init__(self, path=None, platform_dependant=False,
+    def __init__(self, path=None, platform_dependent=False,
                  execution_context=None, fileobj=None):
         self._fields = {}
         self.version = None
         self.docutils_support = _HAS_DOCUTILS
-        self.platform_dependant = platform_dependant
+        self.platform_dependent = platform_dependent
         if path is not None:
             self.read(path)
         elif fileobj is not None:
@@ -263,7 +262,7 @@
         return reporter.messages
 
     def _platform(self, value):
-        if not self.platform_dependant or ';' not in value:
+        if not self.platform_dependent or ';' not in value:
             return True, value
         value, marker = value.split(';')
         return _interpret(marker, self.execution_context), value
@@ -518,7 +517,7 @@
             raise NameError(value)
 
     def _nonsense_op(self):
-        msg = 'This operation is not supported : "%s"' % str(self)
+        msg = 'This operation is not supported : "%s"' % self
         raise SyntaxError(msg)
 
     def __call__(self):
@@ -635,4 +634,3 @@
     operations = _CHAIN(execution_context)
     tokenize(StringIO(marker).readline, operations.eat)
     return operations.result()
-
diff --git a/src/distutils2/mkpkg.py b/src/distutils2/mkpkg.py
--- a/src/distutils2/mkpkg.py
+++ b/src/distutils2/mkpkg.py
@@ -675,7 +675,7 @@
 troveDict = buildTroveDict(troveList)
 
 
-class SetupClass:
+class SetupClass(object):
     def __init__(self):
         self.config = None
         self.classifierDict = {}
@@ -717,14 +717,16 @@
 
     def inspectFile(self, path):
         fp = open(path, 'r')
-        for line in [ fp.readline() for x in range(10) ]:
-            m = re.match(r'^#!.*python((?P<major>\d)(\.\d+)?)?$', line)
-            if m:
-                if m.group('major') == '3':
-                    self.classifierDict['Programming Language :: Python :: 3'] = 1
-                else:
-                    self.classifierDict['Programming Language :: Python :: 2'] = 1
-        fp.close()
+        try:
+            for line in [ fp.readline() for x in range(10) ]:
+                m = re.match(r'^#!.*python((?P<major>\d)(\.\d+)?)?$', line)
+                if m:
+                    if m.group('major') == '3':
+                        self.classifierDict['Programming Language :: Python :: 3'] = 1
+                    else:
+                        self.classifierDict['Programming Language :: Python :: 2'] = 1
+        finally:
+            fp.close()
 
 
     def inspectDirectory(self):
@@ -885,38 +887,33 @@
         if os.path.exists('setup.py'): shutil.move('setup.py', 'setup.py.old')
 
         fp = open('setup.py', 'w')
-        fp.write('#!/usr/bin/env python\n\n')
-        fp.write('from distutils2.core import setup\n\n')
+        try:
+            fp.write('#!/usr/bin/env python\n\n')
+            fp.write('from distutils2.core import setup\n\n')
+            fp.write('setup(name=%s,\n' % repr(self.setupData['name']))
+            fp.write('      version=%s,\n' % repr(self.setupData['version']))
+            fp.write('      description=%s,\n'
+                    % repr(self.setupData['description']))
+            fp.write('      author=%s,\n' % repr(self.setupData['author']))
+            fp.write('      author_email=%s,\n'
+                    % repr(self.setupData['author_email']))
+            if self.setupData['url']:
+                fp.write('      url=%s,\n' % repr(self.setupData['url']))
+            if self.setupData['classifier']:
+                fp.write('      classifier=[\n')
+                for classifier in sorted(self.setupData['classifier'].keys()):
+                    fp.write('            %s,\n' % repr(classifier))
+                fp.write('         ],\n')
+            if self.setupData['packages']:
+                fp.write('      packages=%s,\n'
+                        % repr(self._dotted_packages(self.setupData['packages'])))
+                fp.write('      package_dir=%s,\n'
+                        % repr(self.setupData['packages']))
+            fp.write('      #scripts=[\'path/to/script\']\n')
 
-        fp.write('from sys import version\n')
-        fp.write('if version < \'2.2.3\':\n')
-        fp.write('    from distutils2.dist import DistributionMetadata\n')
-        fp.write('    DistributionMetadata.classifier = None\n')
-        fp.write('    DistributionMetadata.download_url = None\n')
-
-        fp.write('setup(name = %s,\n' % repr(self.setupData['name']))
-        fp.write('        version = %s,\n' % repr(self.setupData['version']))
-        fp.write('        description = %s,\n'
-                % repr(self.setupData['description']))
-        fp.write('        author = %s,\n' % repr(self.setupData['author']))
-        fp.write('        author_email = %s,\n'
-                % repr(self.setupData['author_email']))
-        if self.setupData['url']:
-            fp.write('        url = %s,\n' % repr(self.setupData['url']))
-        if self.setupData['classifier']:
-            fp.write('        classifier = [\n')
-            for classifier in sorted(self.setupData['classifier'].keys()):
-                fp.write('              %s,\n' % repr(classifier))
-            fp.write('           ],\n')
-        if self.setupData['packages']:
-            fp.write('        packages = %s,\n'
-                    % repr(self._dotted_packages(self.setupData['packages'])))
-            fp.write('        package_dir = %s,\n'
-                    % repr(self.setupData['packages']))
-        fp.write('        #scripts = [\'path/to/script\']\n')
-
-        fp.write('        )\n')
-        fp.close()
+            fp.write('      )\n')
+        finally:
+            fp.close()
         os.chmod('setup.py', 0755)
 
         print 'Wrote "setup.py".'
diff --git a/src/distutils2/spawn.py b/src/distutils2/spawn.py
--- a/src/distutils2/spawn.py
+++ b/src/distutils2/spawn.py
@@ -14,7 +14,7 @@
 from distutils2.errors import DistutilsPlatformError, DistutilsExecError
 from distutils2 import log
 
-def spawn(cmd, search_path=1, verbose=0, dry_run=0):
+def spawn(cmd, search_path=1, verbose=0, dry_run=0, env=None):
     """Run another program, specified as a command list 'cmd', in a new process.
 
     'cmd' is just the argument list for the new process, ie.
@@ -27,15 +27,18 @@
     must be the exact path to the executable.  If 'dry_run' is true,
     the command will not actually be run.
 
+    If 'env' is given, it's a environment dictionary used for the execution
+    environment.
+
     Raise DistutilsExecError if running the program fails in any way; just
     return on success.
     """
     if os.name == 'posix':
-        _spawn_posix(cmd, search_path, dry_run=dry_run)
+        _spawn_posix(cmd, search_path, dry_run=dry_run, env=env)
     elif os.name == 'nt':
-        _spawn_nt(cmd, search_path, dry_run=dry_run)
+        _spawn_nt(cmd, search_path, dry_run=dry_run, env=env)
     elif os.name == 'os2':
-        _spawn_os2(cmd, search_path, dry_run=dry_run)
+        _spawn_os2(cmd, search_path, dry_run=dry_run, env=env)
     else:
         raise DistutilsPlatformError, \
               "don't know how to spawn programs on platform '%s'" % os.name
@@ -56,7 +59,7 @@
             args[i] = '"%s"' % arg
     return args
 
-def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):
+def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0, env=None):
     executable = cmd[0]
     cmd = _nt_quote_args(cmd)
     if search_path:
@@ -66,7 +69,11 @@
     if not dry_run:
         # spawn for NT requires a full path to the .exe
         try:
-            rc = os.spawnv(os.P_WAIT, executable, cmd)
+            if env is None:
+                rc = os.spawnv(os.P_WAIT, executable, cmd)
+            else:
+                rc = os.spawnve(os.P_WAIT, executable, cmd, env)
+
         except OSError, exc:
             # this seems to happen when the command isn't found
             raise DistutilsExecError, \
@@ -76,7 +83,7 @@
             raise DistutilsExecError, \
                   "command '%s' failed with exit status %d" % (cmd[0], rc)
 
-def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0):
+def _spawn_os2(cmd, search_path=1, verbose=0, dry_run=0, env=None):
     executable = cmd[0]
     if search_path:
         # either we find one or it stays the same
@@ -85,7 +92,11 @@
     if not dry_run:
         # spawnv for OS/2 EMX requires a full path to the .exe
         try:
-            rc = os.spawnv(os.P_WAIT, executable, cmd)
+            if env is None:
+                rc = os.spawnv(os.P_WAIT, executable, cmd)
+            else:
+                rc = os.spawnve(os.P_WAIT, executable, cmd, env)
+
         except OSError, exc:
             # this seems to happen when the command isn't found
             raise DistutilsExecError, \
@@ -97,16 +108,24 @@
                   "command '%s' failed with exit status %d" % (cmd[0], rc)
 
 
-def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
+def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0, env=None):
     log.info(' '.join(cmd))
     if dry_run:
         return
-    exec_fn = search_path and os.execvp or os.execv
+
+    if env is None:
+        exec_fn = search_path and os.execvp or os.execv
+    else:
+        exec_fn = search_path and os.execvpe or os.execve
+
     pid = os.fork()
 
     if pid == 0:  # in the child
         try:
-            exec_fn(cmd[0], cmd)
+            if env is None:
+                exec_fn(cmd[0], cmd)
+            else:
+                exec_fn(cmd[0], cmd, env)
         except OSError, e:
             sys.stderr.write("unable to execute %s: %s\n" %
                              (cmd[0], e.strerror))
diff --git a/src/distutils2/tests/__init__.py b/src/distutils2/tests/__init__.py
--- a/src/distutils2/tests/__init__.py
+++ b/src/distutils2/tests/__init__.py
@@ -45,7 +45,7 @@
     """Test failed."""
 
 
-class BasicTestRunner:
+class BasicTestRunner(object):
     def run(self, test):
         result = unittest.TestResult()
         test(result)
diff --git a/src/distutils2/tests/support.py b/src/distutils2/tests/support.py
--- a/src/distutils2/tests/support.py
+++ b/src/distutils2/tests/support.py
@@ -14,7 +14,6 @@
 
 from distutils2 import log
 from distutils2.log import DEBUG, INFO, WARN, ERROR, FATAL
-from distutils2.core import Distribution
 
 if sys.version_info >= (2, 7):
     # improved unittest package from 2.7's standard library
@@ -42,7 +41,7 @@
 
     def _log(self, level, msg, args):
         if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
-            raise ValueError('%s wrong log level' % str(level))
+            raise ValueError('%s wrong log level' % level)
         self.logs.append((level, msg, args))
 
     def get_logs(self, *levels):
@@ -105,6 +104,7 @@
         It returns the package directory and the distribution
         instance.
         """
+        from distutils2.dist import Distribution
         tmp_dir = self.mkdtemp()
         pkg_dir = os.path.join(tmp_dir, pkg_name)
         os.mkdir(pkg_dir)
diff --git a/src/distutils2/tests/test_bdist.py b/src/distutils2/tests/test_bdist.py
--- a/src/distutils2/tests/test_bdist.py
+++ b/src/distutils2/tests/test_bdist.py
@@ -1,8 +1,6 @@
 """Tests for distutils.command.bdist."""
 import sys
 import os
-import tempfile
-import shutil
 
 from distutils2.tests import run_unittest
 
@@ -25,7 +23,7 @@
         cmd = bdist(dist)
         cmd.formats = ['msi']
         cmd.ensure_finalized()
-        self.assertEquals(cmd.formats, ['msi'])
+        self.assertEqual(cmd.formats, ['msi'])
 
         # what format bdist offers ?
         # XXX an explicit list in bdist is
@@ -33,9 +31,9 @@
         # we should add a registry
         formats = ['zip', 'gztar', 'bztar', 'ztar', 'tar', 'wininst', 'msi']
         formats.sort()
-        founded = cmd.format_command.keys()
-        founded.sort()
-        self.assertEquals(founded, formats)
+        found = cmd.format_command.keys()
+        found.sort()
+        self.assertEqual(found, formats)
 
 def test_suite():
     return unittest.makeSuite(BuildTestCase)
diff --git a/src/distutils2/tests/test_bdist_dumb.py b/src/distutils2/tests/test_bdist_dumb.py
--- a/src/distutils2/tests/test_bdist_dumb.py
+++ b/src/distutils2/tests/test_bdist_dumb.py
@@ -78,7 +78,7 @@
             base = base.replace(':', '-')
 
         wanted = ['%s.zip' % base]
-        self.assertEquals(dist_created, wanted)
+        self.assertEqual(dist_created, wanted)
 
         # now let's check what we have in the zip file
         # XXX to be done
@@ -87,16 +87,16 @@
         pkg_dir, dist = self.create_dist()
         os.chdir(pkg_dir)
         cmd = bdist_dumb(dist)
-        self.assertEquals(cmd.bdist_dir, None)
+        self.assertEqual(cmd.bdist_dir, None)
         cmd.finalize_options()
 
         # bdist_dir is initialized to bdist_base/dumb if not set
         base = cmd.get_finalized_command('bdist').bdist_base
-        self.assertEquals(cmd.bdist_dir, os.path.join(base, 'dumb'))
+        self.assertEqual(cmd.bdist_dir, os.path.join(base, 'dumb'))
 
         # the format is set to a default value depending on the os.name
         default = cmd.default_format[os.name]
-        self.assertEquals(cmd.format, default)
+        self.assertEqual(cmd.format, default)
 
 def test_suite():
     return unittest.makeSuite(BuildDumbTestCase)
diff --git a/src/distutils2/tests/test_build.py b/src/distutils2/tests/test_build.py
--- a/src/distutils2/tests/test_build.py
+++ b/src/distutils2/tests/test_build.py
@@ -20,11 +20,11 @@
         cmd.finalize_options()
 
         # if not specified, plat_name gets the current platform
-        self.assertEquals(cmd.plat_name, get_platform())
+        self.assertEqual(cmd.plat_name, get_platform())
 
         # build_purelib is build + lib
         wanted = os.path.join(cmd.build_base, 'lib')
-        self.assertEquals(cmd.build_purelib, wanted)
+        self.assertEqual(cmd.build_purelib, wanted)
 
         # build_platlib is 'build/lib.platform-x.x[-pydebug]'
         # examples:
@@ -34,21 +34,21 @@
             self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
             plat_spec += '-pydebug'
         wanted = os.path.join(cmd.build_base, 'lib' + plat_spec)
-        self.assertEquals(cmd.build_platlib, wanted)
+        self.assertEqual(cmd.build_platlib, wanted)
 
         # by default, build_lib = build_purelib
-        self.assertEquals(cmd.build_lib, cmd.build_purelib)
+        self.assertEqual(cmd.build_lib, cmd.build_purelib)
 
         # build_temp is build/temp.<plat>
         wanted = os.path.join(cmd.build_base, 'temp' + plat_spec)
-        self.assertEquals(cmd.build_temp, wanted)
+        self.assertEqual(cmd.build_temp, wanted)
 
         # build_scripts is build/scripts-x.x
         wanted = os.path.join(cmd.build_base, 'scripts-' +  sys.version[0:3])
-        self.assertEquals(cmd.build_scripts, wanted)
+        self.assertEqual(cmd.build_scripts, wanted)
 
         # executable is os.path.normpath(sys.executable)
-        self.assertEquals(cmd.executable, os.path.normpath(sys.executable))
+        self.assertEqual(cmd.executable, os.path.normpath(sys.executable))
 
 def test_suite():
     return unittest.makeSuite(BuildTestCase)
diff --git a/src/distutils2/tests/test_build_clib.py b/src/distutils2/tests/test_build_clib.py
--- a/src/distutils2/tests/test_build_clib.py
+++ b/src/distutils2/tests/test_build_clib.py
@@ -55,14 +55,14 @@
         self.assertRaises(DistutilsSetupError, cmd.get_source_files)
 
         cmd.libraries = [('name', {'sources': ['a', 'b']})]
-        self.assertEquals(cmd.get_source_files(), ['a', 'b'])
+        self.assertEqual(cmd.get_source_files(), ['a', 'b'])
 
         cmd.libraries = [('name', {'sources': ('a', 'b')})]
-        self.assertEquals(cmd.get_source_files(), ['a', 'b'])
+        self.assertEqual(cmd.get_source_files(), ['a', 'b'])
 
         cmd.libraries = [('name', {'sources': ('a', 'b')}),
                          ('name2', {'sources': ['c', 'd']})]
-        self.assertEquals(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
+        self.assertEqual(cmd.get_source_files(), ['a', 'b', 'c', 'd'])
 
     def test_build_libraries(self):
 
@@ -91,11 +91,11 @@
 
         cmd.include_dirs = 'one-dir'
         cmd.finalize_options()
-        self.assertEquals(cmd.include_dirs, ['one-dir'])
+        self.assertEqual(cmd.include_dirs, ['one-dir'])
 
         cmd.include_dirs = None
         cmd.finalize_options()
-        self.assertEquals(cmd.include_dirs, [])
+        self.assertEqual(cmd.include_dirs, [])
 
         cmd.distribution.libraries = 'WONTWORK'
         self.assertRaises(DistutilsSetupError, cmd.finalize_options)
diff --git a/src/distutils2/tests/test_build_ext.py b/src/distutils2/tests/test_build_ext.py
--- a/src/distutils2/tests/test_build_ext.py
+++ b/src/distutils2/tests/test_build_ext.py
@@ -1,6 +1,5 @@
 import sys
 import os
-import tempfile
 import shutil
 from StringIO import StringIO
 import warnings
@@ -81,11 +80,11 @@
         for attr in ('error', 'foo', 'new', 'roj'):
             self.assertTrue(hasattr(xx, attr))
 
-        self.assertEquals(xx.foo(2, 5), 7)
-        self.assertEquals(xx.foo(13,15), 28)
-        self.assertEquals(xx.new().demo(), None)
+        self.assertEqual(xx.foo(2, 5), 7)
+        self.assertEqual(xx.foo(13,15), 28)
+        self.assertEqual(xx.new().demo(), None)
         doc = 'This is a template module just for instruction.'
-        self.assertEquals(xx.__doc__, doc)
+        self.assertEqual(xx.__doc__, doc)
         self.assertTrue(isinstance(xx.Null(), xx.Null))
         self.assertTrue(isinstance(xx.Str(), xx.Str))
 
@@ -195,7 +194,7 @@
         cmd = build_ext(dist)
         cmd.libraries = 'my_lib'
         cmd.finalize_options()
-        self.assertEquals(cmd.libraries, ['my_lib'])
+        self.assertEqual(cmd.libraries, ['my_lib'])
 
         # make sure cmd.library_dirs is turned into a list
         # if it's a string
@@ -209,7 +208,7 @@
         cmd = build_ext(dist)
         cmd.rpath = os.pathsep.join(['one', 'two'])
         cmd.finalize_options()
-        self.assertEquals(cmd.rpath, ['one', 'two'])
+        self.assertEqual(cmd.rpath, ['one', 'two'])
 
         # XXX more tests to perform for win32
 
@@ -218,25 +217,25 @@
         cmd = build_ext(dist)
         cmd.define = 'one,two'
         cmd.finalize_options()
-        self.assertEquals(cmd.define, [('one', '1'), ('two', '1')])
+        self.assertEqual(cmd.define, [('one', '1'), ('two', '1')])
 
         # make sure undef is turned into a list of
         # strings if they are ','-separated strings
         cmd = build_ext(dist)
         cmd.undef = 'one,two'
         cmd.finalize_options()
-        self.assertEquals(cmd.undef, ['one', 'two'])
+        self.assertEqual(cmd.undef, ['one', 'two'])
 
         # make sure swig_opts is turned into a list
         cmd = build_ext(dist)
         cmd.swig_opts = None
         cmd.finalize_options()
-        self.assertEquals(cmd.swig_opts, [])
+        self.assertEqual(cmd.swig_opts, [])
 
         cmd = build_ext(dist)
         cmd.swig_opts = '1 2'
         cmd.finalize_options()
-        self.assertEquals(cmd.swig_opts, ['1', '2'])
+        self.assertEqual(cmd.swig_opts, ['1', '2'])
 
     def test_check_extensions_list(self):
         dist = Distribution()
@@ -272,7 +271,7 @@
         # check_extensions_list adds in ext the values passed
         # when they are in ('include_dirs', 'library_dirs', 'libraries'
         # 'extra_objects', 'extra_compile_args', 'extra_link_args')
-        self.assertEquals(ext.libraries, 'foo')
+        self.assertEqual(ext.libraries, 'foo')
         self.assertTrue(not hasattr(ext, 'some'))
 
         # 'macros' element of build info dict must be 1- or 2-tuple
@@ -282,15 +281,15 @@
 
         exts[0][1]['macros'] = [('1', '2'), ('3',)]
         cmd.check_extensions_list(exts)
-        self.assertEquals(exts[0].undef_macros, ['3'])
-        self.assertEquals(exts[0].define_macros, [('1', '2')])
+        self.assertEqual(exts[0].undef_macros, ['3'])
+        self.assertEqual(exts[0].define_macros, [('1', '2')])
 
     def test_get_source_files(self):
         modules = [Extension('foo', ['xxx'], optional=False)]
         dist = Distribution({'name': 'xx', 'ext_modules': modules})
         cmd = build_ext(dist)
         cmd.ensure_finalized()
-        self.assertEquals(cmd.get_source_files(), ['xxx'])
+        self.assertEqual(cmd.get_source_files(), ['xxx'])
 
     def test_compiler_option(self):
         # cmd.compiler is an option and
@@ -301,7 +300,7 @@
         cmd.compiler = 'unix'
         cmd.ensure_finalized()
         cmd.run()
-        self.assertEquals(cmd.compiler, 'unix')
+        self.assertEqual(cmd.compiler, 'unix')
 
     def test_get_outputs(self):
         tmp_dir = self.mkdtemp()
@@ -312,7 +311,7 @@
                              'ext_modules': [ext]})
         cmd = build_ext(dist)
         cmd.ensure_finalized()
-        self.assertEquals(len(cmd.get_outputs()), 1)
+        self.assertEqual(len(cmd.get_outputs()), 1)
 
         if os.name == "nt":
             cmd.debug = sys.executable.endswith("_d.exe")
@@ -332,19 +331,19 @@
         finally:
             os.chdir(old_wd)
         self.assertTrue(os.path.exists(so_file))
-        self.assertEquals(os.path.splitext(so_file)[-1],
+        self.assertEqual(os.path.splitext(so_file)[-1],
                           sysconfig.get_config_var('SO'))
         so_dir = os.path.dirname(so_file)
-        self.assertEquals(so_dir, other_tmp_dir)
+        self.assertEqual(so_dir, other_tmp_dir)
 
         cmd.inplace = 0
         cmd.run()
         so_file = cmd.get_outputs()[0]
         self.assertTrue(os.path.exists(so_file))
-        self.assertEquals(os.path.splitext(so_file)[-1],
+        self.assertEqual(os.path.splitext(so_file)[-1],
                           sysconfig.get_config_var('SO'))
         so_dir = os.path.dirname(so_file)
-        self.assertEquals(so_dir, cmd.build_lib)
+        self.assertEqual(so_dir, cmd.build_lib)
 
         # inplace = 0, cmd.package = 'bar'
         build_py = cmd.get_finalized_command('build_py')
@@ -352,7 +351,7 @@
         path = cmd.get_ext_fullpath('foo')
         # checking that the last directory is the build_dir
         path = os.path.split(path)[0]
-        self.assertEquals(path, cmd.build_lib)
+        self.assertEqual(path, cmd.build_lib)
 
         # inplace = 1, cmd.package = 'bar'
         cmd.inplace = 1
@@ -366,7 +365,7 @@
         # checking that the last directory is bar
         path = os.path.split(path)[0]
         lastdir = os.path.split(path)[-1]
-        self.assertEquals(lastdir, 'bar')
+        self.assertEqual(lastdir, 'bar')
 
     def test_ext_fullpath(self):
         ext = sysconfig.get_config_vars()['SO']
@@ -382,14 +381,14 @@
         curdir = os.getcwd()
         wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
         path = cmd.get_ext_fullpath('lxml.etree')
-        self.assertEquals(wanted, path)
+        self.assertEqual(wanted, path)
 
         # building lxml.etree not inplace
         cmd.inplace = 0
         cmd.build_lib = os.path.join(curdir, 'tmpdir')
         wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
         path = cmd.get_ext_fullpath('lxml.etree')
-        self.assertEquals(wanted, path)
+        self.assertEqual(wanted, path)
 
         # building twisted.runner.portmap not inplace
         build_py = cmd.get_finalized_command('build_py')
@@ -398,13 +397,13 @@
         path = cmd.get_ext_fullpath('twisted.runner.portmap')
         wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
                               'portmap' + ext)
-        self.assertEquals(wanted, path)
+        self.assertEqual(wanted, path)
 
         # building twisted.runner.portmap inplace
         cmd.inplace = 1
         path = cmd.get_ext_fullpath('twisted.runner.portmap')
         wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
-        self.assertEquals(wanted, path)
+        self.assertEqual(wanted, path)
 
 def test_suite():
     src = _get_source_filename()
diff --git a/src/distutils2/tests/test_build_py.py b/src/distutils2/tests/test_build_py.py
--- a/src/distutils2/tests/test_build_py.py
+++ b/src/distutils2/tests/test_build_py.py
@@ -19,11 +19,15 @@
     def test_package_data(self):
         sources = self.mkdtemp()
         f = open(os.path.join(sources, "__init__.py"), "w")
-        f.write("# Pretend this is a package.")
-        f.close()
+        try:
+            f.write("# Pretend this is a package.")
+        finally:
+            f.close()
         f = open(os.path.join(sources, "README.txt"), "w")
-        f.write("Info about this package")
-        f.close()
+        try:
+            f.write("Info about this package")
+        finally:
+            f.close()
 
         destination = self.mkdtemp()
 
diff --git a/src/distutils2/tests/test_build_scripts.py b/src/distutils2/tests/test_build_scripts.py
--- a/src/distutils2/tests/test_build_scripts.py
+++ b/src/distutils2/tests/test_build_scripts.py
@@ -74,8 +74,10 @@
 
     def write_script(self, dir, name, text):
         f = open(os.path.join(dir, name), "w")
-        f.write(text)
-        f.close()
+        try:
+            f.write(text)
+        finally:
+            f.close()
 
     def test_version_int(self):
         source = self.mkdtemp()
diff --git a/src/distutils2/tests/test_ccompiler.py b/src/distutils2/tests/test_ccompiler.py
--- a/src/distutils2/tests/test_ccompiler.py
+++ b/src/distutils2/tests/test_ccompiler.py
@@ -31,7 +31,7 @@
         opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
         wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',
                   '-lname2']
-        self.assertEquals(opts, wanted)
+        self.assertEqual(opts, wanted)
 
     def test_customize_compiler(self):
 
@@ -51,7 +51,7 @@
 
         comp = compiler()
         customize_compiler(comp)
-        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
+        self.assertEqual(comp.exes['archiver'], 'my_ar -arflags')
 
 def test_suite():
     return unittest.makeSuite(CCompilerTestCase)
diff --git a/src/distutils2/tests/test_check.py b/src/distutils2/tests/test_check.py
--- a/src/distutils2/tests/test_check.py
+++ b/src/distutils2/tests/test_check.py
@@ -37,7 +37,7 @@
                     'name': 'xxx', 'version': 'xxx'
                     }
         cmd = self._run(metadata)
-        self.assertEquals(len(cmd._warnings), 0)
+        self.assertEqual(len(cmd._warnings), 0)
 
         # now with the strict mode, we should
         # get an error if there are missing metadata
@@ -45,7 +45,7 @@
 
         # and of course, no error when all metadata are present
         cmd = self._run(metadata, strict=1)
-        self.assertEquals(len(cmd._warnings), 0)
+        self.assertEqual(len(cmd._warnings), 0)
 
     def test_check_restructuredtext(self):
         if not _HAS_DOCUTILS: # won't test without docutils
@@ -55,7 +55,7 @@
         pkg_info, dist = self.create_dist(description=broken_rest)
         cmd = check(dist)
         cmd.check_restructuredtext()
-        self.assertEquals(len(cmd._warnings), 1)
+        self.assertEqual(len(cmd._warnings), 1)
 
         # let's see if we have an error with strict=1
         metadata = {'home_page': 'xxx', 'author': 'xxx',
@@ -69,7 +69,7 @@
         # and non-broken rest
         metadata['description'] = 'title\n=====\n\ntest'
         cmd = self._run(metadata, strict=1, restructuredtext=1)
-        self.assertEquals(len(cmd._warnings), 0)
+        self.assertEqual(len(cmd._warnings), 0)
 
     def test_check_all(self):
 
diff --git a/src/distutils2/tests/test_cmd.py b/src/distutils2/tests/test_cmd.py
--- a/src/distutils2/tests/test_cmd.py
+++ b/src/distutils2/tests/test_cmd.py
@@ -43,7 +43,7 @@
 
         # making sure execute gets called properly
         def _execute(func, args, exec_msg, level):
-            self.assertEquals(exec_msg, 'generating out from in')
+            self.assertEqual(exec_msg, 'generating out from in')
         cmd.force = True
         cmd.execute = _execute
         cmd.make_file(infiles='in', outfile='out', func='func', args=())
@@ -62,7 +62,7 @@
 
         wanted = ["command options for 'MyCmd':", '  option1 = 1',
                   '  option2 = 1']
-        self.assertEquals(msgs, wanted)
+        self.assertEqual(msgs, wanted)
 
     def test_ensure_string(self):
         cmd = self.cmd
@@ -80,7 +80,7 @@
         cmd = self.cmd
         cmd.option1 = 'ok,dok'
         cmd.ensure_string_list('option1')
-        self.assertEquals(cmd.option1, ['ok', 'dok'])
+        self.assertEqual(cmd.option1, ['ok', 'dok'])
 
         cmd.option2 = ['xxx', 'www']
         cmd.ensure_string_list('option2')
diff --git a/src/distutils2/tests/test_config.py b/src/distutils2/tests/test_config.py
--- a/src/distutils2/tests/test_config.py
+++ b/src/distutils2/tests/test_config.py
@@ -1,7 +1,6 @@
 """Tests for distutils.pypirc.pypirc."""
 import sys
 import os
-import tempfile
 import shutil
 
 from distutils2.core import PyPIRCCommand
@@ -87,20 +86,20 @@
 
         config = config.items()
         config.sort()
-        waited = [('password', 'secret'), ('realm', 'pypi'),
-                  ('repository', 'http://pypi.python.org/pypi'),
-                  ('server', 'server1'), ('username', 'me')]
-        self.assertEquals(config, waited)
+        expected = [('password', 'secret'), ('realm', 'pypi'),
+                    ('repository', 'http://pypi.python.org/pypi'),
+                    ('server', 'server1'), ('username', 'me')]
+        self.assertEqual(config, expected)
 
         # old format
         self.write_file(self.rc, PYPIRC_OLD)
         config = cmd._read_pypirc()
         config = config.items()
         config.sort()
-        waited = [('password', 'secret'), ('realm', 'pypi'),
-                  ('repository', 'http://pypi.python.org/pypi'),
-                  ('server', 'server-login'), ('username', 'tarek')]
-        self.assertEquals(config, waited)
+        expected = [('password', 'secret'), ('realm', 'pypi'),
+                    ('repository', 'http://pypi.python.org/pypi'),
+                    ('server', 'server-login'), ('username', 'tarek')]
+        self.assertEqual(config, expected)
 
     def test_server_empty_registration(self):
         cmd = self._cmd(self.dist)
@@ -109,7 +108,7 @@
         cmd._store_pypirc('tarek', 'xxx')
         self.assertTrue(os.path.exists(rc))
         content = open(rc).read()
-        self.assertEquals(content, WANTED)
+        self.assertEqual(content, WANTED)
 
 def test_suite():
     return unittest.makeSuite(PyPIRCCommandTestCase)
diff --git a/src/distutils2/tests/test_config_cmd.py b/src/distutils2/tests/test_config_cmd.py
--- a/src/distutils2/tests/test_config_cmd.py
+++ b/src/distutils2/tests/test_config_cmd.py
@@ -34,7 +34,7 @@
             f.close()
 
         dump_file(this_file, 'I am the header')
-        self.assertEquals(len(self._logs), numlines+1)
+        self.assertEqual(len(self._logs), numlines+1)
 
     def test_search_cpp(self):
         if sys.platform == 'win32':
@@ -44,10 +44,10 @@
 
         # simple pattern searches
         match = cmd.search_cpp(pattern='xxx', body='// xxx')
-        self.assertEquals(match, 0)
+        self.assertEqual(match, 0)
 
         match = cmd.search_cpp(pattern='_configtest', body='// xxx')
-        self.assertEquals(match, 1)
+        self.assertEqual(match, 1)
 
     def test_finalize_options(self):
         # finalize_options does a bit of transformation
@@ -59,9 +59,9 @@
         cmd.library_dirs = 'three%sfour' % os.pathsep
         cmd.ensure_finalized()
 
-        self.assertEquals(cmd.include_dirs, ['one', 'two'])
-        self.assertEquals(cmd.libraries, ['one'])
-        self.assertEquals(cmd.library_dirs, ['three', 'four'])
+        self.assertEqual(cmd.include_dirs, ['one', 'two'])
+        self.assertEqual(cmd.libraries, ['one'])
+        self.assertEqual(cmd.library_dirs, ['three', 'four'])
 
     def test_clean(self):
         # _clean removes files
diff --git a/src/distutils2/tests/test_converter.py b/src/distutils2/tests/test_converter.py
--- a/src/distutils2/tests/test_converter.py
+++ b/src/distutils2/tests/test_converter.py
@@ -30,7 +30,7 @@
             wanted = file_.replace('before', 'after')
             wanted = _read_file(os.path.join(convdir, wanted))
             res = ref.refactor_string(original, 'setup.py')
-            self.assertEquals(str(res), wanted)
+            self.assertEqual(str(res), wanted)
 
 def test_suite():
     return unittest.makeSuite(ConverterTestCase)
diff --git a/src/distutils2/tests/test_cygwinccompiler.py b/src/distutils2/tests/test_cygwinccompiler.py
--- a/src/distutils2/tests/test_cygwinccompiler.py
+++ b/src/distutils2/tests/test_cygwinccompiler.py
@@ -44,48 +44,48 @@
         sys.version = ('2.6.1 (r261:67515, Dec  6 2008, 16:42:21) \n[GCC '
                        '4.0.1 (Apple Computer, Inc. build 5370)]')
 
-        self.assertEquals(check_config_h()[0], CONFIG_H_OK)
+        self.assertEqual(check_config_h()[0], CONFIG_H_OK)
 
         # then it tries to see if it can find "__GNUC__" in pyconfig.h
         sys.version = 'something without the *CC word'
 
         # if the file doesn't exist it returns  CONFIG_H_UNCERTAIN
-        self.assertEquals(check_config_h()[0], CONFIG_H_UNCERTAIN)
+        self.assertEqual(check_config_h()[0], CONFIG_H_UNCERTAIN)
 
         # if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK
         self.write_file(self.python_h, 'xxx')
-        self.assertEquals(check_config_h()[0], CONFIG_H_NOTOK)
+        self.assertEqual(check_config_h()[0], CONFIG_H_NOTOK)
 
         # and CONFIG_H_OK if __GNUC__ is found
         self.write_file(self.python_h, 'xxx __GNUC__ xxx')
-        self.assertEquals(check_config_h()[0], CONFIG_H_OK)
+        self.assertEqual(check_config_h()[0], CONFIG_H_OK)
 
     def test_get_msvcr(self):
 
         # none
         sys.version  = ('2.6.1 (r261:67515, Dec  6 2008, 16:42:21) '
                         '\n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]')
-        self.assertEquals(get_msvcr(), None)
+        self.assertEqual(get_msvcr(), None)
 
         # MSVC 7.0
         sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
                        '[MSC v.1300 32 bits (Intel)]')
-        self.assertEquals(get_msvcr(), ['msvcr70'])
+        self.assertEqual(get_msvcr(), ['msvcr70'])
 
         # MSVC 7.1
         sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
                        '[MSC v.1310 32 bits (Intel)]')
-        self.assertEquals(get_msvcr(), ['msvcr71'])
+        self.assertEqual(get_msvcr(), ['msvcr71'])
 
         # VS2005 / MSVC 8.0
         sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
                        '[MSC v.1400 32 bits (Intel)]')
-        self.assertEquals(get_msvcr(), ['msvcr80'])
+        self.assertEqual(get_msvcr(), ['msvcr80'])
 
         # VS2008 / MSVC 9.0
         sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
                        '[MSC v.1500 32 bits (Intel)]')
-        self.assertEquals(get_msvcr(), ['msvcr90'])
+        self.assertEqual(get_msvcr(), ['msvcr90'])
 
         # unknown
         sys.version = ('2.5.1 (r251:54863, Apr 18 2007, 08:51:08) '
diff --git a/src/distutils2/tests/test_depgraph.py b/src/distutils2/tests/test_depgraph.py
--- a/src/distutils2/tests/test_depgraph.py
+++ b/src/distutils2/tests/test_depgraph.py
@@ -27,7 +27,7 @@
         self.assertListEqual(sorted(l1), sorted(l2))
 
     def setUp(self):
-        super(unittest.TestCase, self).setUp()
+        super(DepGraphTestCase, self).setUp()
         path = os.path.join(os.path.dirname(__file__), '..', '_backport',
                             'tests', 'fake_dists')
         path = os.path.abspath(path)
@@ -177,7 +177,7 @@
         self.checkLists(matches, expected)
 
     def tearDown(self):
-        super(unittest.TestCase, self).tearDown()
+        super(DepGraphTestCase, self).tearDown()
         sys.path = self.sys_path
 
 def test_suite():
diff --git a/src/distutils2/tests/test_dist.py b/src/distutils2/tests/test_dist.py
--- a/src/distutils2/tests/test_dist.py
+++ b/src/distutils2/tests/test_dist.py
@@ -71,11 +71,11 @@
         sys.argv.append("build")
 
         __, stdout = captured_stdout(self.create_distribution, files)
-        self.assertEquals(stdout, '')
+        self.assertEqual(stdout, '')
         distutils2.dist.DEBUG = True
         try:
             __, stdout = captured_stdout(self.create_distribution, files)
-            self.assertEquals(stdout, '')
+            self.assertEqual(stdout, '')
         finally:
             distutils2.dist.DEBUG = False
 
@@ -129,13 +129,13 @@
         # Check DistributionMetadata handling of Unicode fields
         tmp_dir = self.mkdtemp()
         my_file = os.path.join(tmp_dir, 'f')
-        klass = Distribution
+        cls = Distribution
 
-        dist = klass(attrs={'author': u'Mister Café',
-                            'name': 'my.package',
-                            'maintainer': u'Café Junior',
-                            'summary': u'Café torréfié',
-                            'description': u'Héhéhé'})
+        dist = cls(attrs={'author': u'Mister Café',
+                          'name': 'my.package',
+                          'maintainer': u'Café Junior',
+                          'summary': u'Café torréfié',
+                          'description': u'Héhéhé'})
 
 
         # let's make sure the file can be written
@@ -144,11 +144,11 @@
         dist.metadata.write_file(open(my_file, 'w'))
 
         # regular ascii is of course always usable
-        dist = klass(attrs={'author': 'Mister Cafe',
-                            'name': 'my.package',
-                            'maintainer': 'Cafe Junior',
-                            'summary': 'Cafe torrefie',
-                            'description': 'Hehehe'})
+        dist = cls(attrs={'author': 'Mister Cafe',
+                          'name': 'my.package',
+                          'maintainer': 'Cafe Junior',
+                          'summary': 'Cafe torrefie',
+                          'description': 'Hehehe'})
 
         my_file2 = os.path.join(tmp_dir, 'f2')
         dist.metadata.write_file(open(my_file, 'w'))
@@ -156,7 +156,7 @@
     def test_empty_options(self):
         # an empty options dictionary should not stay in the
         # list of attributes
-        klass = Distribution
+        cls = Distribution
 
         # catching warnings
         warns = []
@@ -166,15 +166,15 @@
         old_warn = warnings.warn
         warnings.warn = _warn
         try:
-            dist = klass(attrs={'author': 'xxx',
-                                'name': 'xxx',
-                                'version': 'xxx',
-                                'url': 'xxxx',
-                                'options': {}})
+            dist = cls(attrs={'author': 'xxx',
+                              'name': 'xxx',
+                              'version': 'xxx',
+                              'url': 'xxxx',
+                              'options': {}})
         finally:
             warnings.warn = old_warn
 
-        self.assertEquals(len(warns), 0)
+        self.assertEqual(len(warns), 0)
 
     def test_finalize_options(self):
 
@@ -185,20 +185,20 @@
         dist.finalize_options()
 
         # finalize_option splits platforms and keywords
-        self.assertEquals(dist.metadata['platform'], ['one', 'two'])
-        self.assertEquals(dist.metadata['keywords'], ['one', 'two'])
+        self.assertEqual(dist.metadata['platform'], ['one', 'two'])
+        self.assertEqual(dist.metadata['keywords'], ['one', 'two'])
 
     def test_get_command_packages(self):
         dist = Distribution()
-        self.assertEquals(dist.command_packages, None)
+        self.assertEqual(dist.command_packages, None)
         cmds = dist.get_command_packages()
-        self.assertEquals(cmds, ['distutils2.command'])
-        self.assertEquals(dist.command_packages,
+        self.assertEqual(cmds, ['distutils2.command'])
+        self.assertEqual(dist.command_packages,
                           ['distutils2.command'])
 
         dist.command_packages = 'one,two'
         cmds = dist.get_command_packages()
-        self.assertEquals(cmds, ['distutils2.command', 'one', 'two'])
+        self.assertEqual(cmds, ['distutils2.command', 'one', 'two'])
 
 
     def test_announce(self):
@@ -238,7 +238,7 @@
             os.path.expanduser = old_expander
 
         # make sure --no-user-cfg disables the user cfg file
-        self.assertEquals(len(all_files)-1, len(files))
+        self.assertEqual(len(all_files)-1, len(files))
 
 
 class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
@@ -340,8 +340,10 @@
         temp_dir = self.mkdtemp()
         user_filename = os.path.join(temp_dir, user_filename)
         f = open(user_filename, 'w')
-        f.write('.')
-        f.close()
+        try:
+            f.write('.')
+        finally:
+            f.close()
 
         try:
             dist = Distribution()
@@ -365,8 +367,8 @@
     def test_fix_help_options(self):
         help_tuples = [('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
         fancy_options = fix_help_options(help_tuples)
-        self.assertEquals(fancy_options[0], ('a', 'b', 'c'))
-        self.assertEquals(fancy_options[1], (1, 2, 3))
+        self.assertEqual(fancy_options[0], ('a', 'b', 'c'))
+        self.assertEqual(fancy_options[1], (1, 2, 3))
 
     def test_show_help(self):
         # smoke test, just makes sure some help is displayed
@@ -412,14 +414,14 @@
         PKG_INFO.seek(0)
 
         metadata.read_file(PKG_INFO)
-        self.assertEquals(metadata['name'], "package")
-        self.assertEquals(metadata['version'], "1.0")
-        self.assertEquals(metadata['summary'], "xxx")
-        self.assertEquals(metadata['download_url'], 'http://example.com')
-        self.assertEquals(metadata['keywords'], ['one', 'two'])
-        self.assertEquals(metadata['platform'], [])
-        self.assertEquals(metadata['obsoletes'], [])
-        self.assertEquals(metadata['requires-dist'], ['foo'])
+        self.assertEqual(metadata['name'], "package")
+        self.assertEqual(metadata['version'], "1.0")
+        self.assertEqual(metadata['summary'], "xxx")
+        self.assertEqual(metadata['download_url'], 'http://example.com')
+        self.assertEqual(metadata['keywords'], ['one', 'two'])
+        self.assertEqual(metadata['platform'], [])
+        self.assertEqual(metadata['obsoletes'], [])
+        self.assertEqual(metadata['requires-dist'], ['foo'])
 
 def test_suite():
     suite = unittest.TestSuite()
diff --git a/src/distutils2/tests/test_install.py b/src/distutils2/tests/test_install.py
--- a/src/distutils2/tests/test_install.py
+++ b/src/distutils2/tests/test_install.py
@@ -139,23 +139,23 @@
 
         # two elements
         cmd.handle_extra_path()
-        self.assertEquals(cmd.extra_path, ['path', 'dirs'])
-        self.assertEquals(cmd.extra_dirs, 'dirs')
-        self.assertEquals(cmd.path_file, 'path')
+        self.assertEqual(cmd.extra_path, ['path', 'dirs'])
+        self.assertEqual(cmd.extra_dirs, 'dirs')
+        self.assertEqual(cmd.path_file, 'path')
 
         # one element
         cmd.extra_path = ['path']
         cmd.handle_extra_path()
-        self.assertEquals(cmd.extra_path, ['path'])
-        self.assertEquals(cmd.extra_dirs, 'path')
-        self.assertEquals(cmd.path_file, 'path')
+        self.assertEqual(cmd.extra_path, ['path'])
+        self.assertEqual(cmd.extra_dirs, 'path')
+        self.assertEqual(cmd.path_file, 'path')
 
         # none
         dist.extra_path = cmd.extra_path = None
         cmd.handle_extra_path()
-        self.assertEquals(cmd.extra_path, None)
-        self.assertEquals(cmd.extra_dirs, '')
-        self.assertEquals(cmd.path_file, None)
+        self.assertEqual(cmd.extra_path, None)
+        self.assertEqual(cmd.extra_dirs, '')
+        self.assertEqual(cmd.path_file, None)
 
         # three elements (no way !)
         cmd.extra_path = 'path,dirs,again'
@@ -199,7 +199,7 @@
         # line (the egg info file)
         f = open(cmd.record)
         try:
-            self.assertEquals(len(f.readlines()), 1)
+            self.assertEqual(len(f.readlines()), 1)
         finally:
             f.close()
 
diff --git a/src/distutils2/tests/test_install_data.py b/src/distutils2/tests/test_install_data.py
--- a/src/distutils2/tests/test_install_data.py
+++ b/src/distutils2/tests/test_install_data.py
@@ -27,14 +27,14 @@
         self.write_file(two, 'xxx')
 
         cmd.data_files = [one, (inst2, [two])]
-        self.assertEquals(cmd.get_inputs(), [one, (inst2, [two])])
+        self.assertEqual(cmd.get_inputs(), [one, (inst2, [two])])
 
         # let's run the command
         cmd.ensure_finalized()
         cmd.run()
 
         # let's check the result
-        self.assertEquals(len(cmd.get_outputs()), 2)
+        self.assertEqual(len(cmd.get_outputs()), 2)
         rtwo = os.path.split(two)[-1]
         self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
         rone = os.path.split(one)[-1]
@@ -47,7 +47,7 @@
         cmd.run()
 
         # let's check the result
-        self.assertEquals(len(cmd.get_outputs()), 2)
+        self.assertEqual(len(cmd.get_outputs()), 2)
         self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
         self.assertTrue(os.path.exists(os.path.join(inst, rone)))
         cmd.outfiles = []
@@ -65,7 +65,7 @@
         cmd.run()
 
         # let's check the result
-        self.assertEquals(len(cmd.get_outputs()), 4)
+        self.assertEqual(len(cmd.get_outputs()), 4)
         self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
         self.assertTrue(os.path.exists(os.path.join(inst, rone)))
 
diff --git a/src/distutils2/tests/test_install_headers.py b/src/distutils2/tests/test_install_headers.py
--- a/src/distutils2/tests/test_install_headers.py
+++ b/src/distutils2/tests/test_install_headers.py
@@ -23,7 +23,7 @@
 
         pkg_dir, dist = self.create_dist(headers=headers)
         cmd = install_headers(dist)
-        self.assertEquals(cmd.get_inputs(), headers)
+        self.assertEqual(cmd.get_inputs(), headers)
 
         # let's run the command
         cmd.install_dir = os.path.join(pkg_dir, 'inst')
@@ -31,7 +31,7 @@
         cmd.run()
 
         # let's check the results
-        self.assertEquals(len(cmd.get_outputs()), 2)
+        self.assertEqual(len(cmd.get_outputs()), 2)
 
 def test_suite():
     return unittest.makeSuite(InstallHeadersTestCase)
diff --git a/src/distutils2/tests/test_install_lib.py b/src/distutils2/tests/test_install_lib.py
--- a/src/distutils2/tests/test_install_lib.py
+++ b/src/distutils2/tests/test_install_lib.py
@@ -25,8 +25,8 @@
         cmd = install_lib(dist)
 
         cmd.finalize_options()
-        self.assertEquals(cmd.compile, 1)
-        self.assertEquals(cmd.optimize, 0)
+        self.assertEqual(cmd.compile, 1)
+        self.assertEqual(cmd.optimize, 0)
 
         # optimize must be 0, 1, or 2
         cmd.optimize = 'foo'
@@ -36,7 +36,7 @@
 
         cmd.optimize = '2'
         cmd.finalize_options()
-        self.assertEquals(cmd.optimize, 2)
+        self.assertEqual(cmd.optimize, 2)
 
     @unittest.skipIf(no_bytecode, 'byte-compile not supported')
     def test_byte_compile(self):
@@ -82,7 +82,7 @@
         cmd.distribution.script_name = 'setup.py'
 
         # get_input should return 2 elements
-        self.assertEquals(len(cmd.get_inputs()), 2)
+        self.assertEqual(len(cmd.get_inputs()), 2)
 
     @unittest.skipUnless(bytecode_support, 'sys.dont_write_bytecode not supported')
     def test_dont_write_bytecode(self):
diff --git a/src/distutils2/tests/test_install_scripts.py b/src/distutils2/tests/test_install_scripts.py
--- a/src/distutils2/tests/test_install_scripts.py
+++ b/src/distutils2/tests/test_install_scripts.py
@@ -42,8 +42,10 @@
         def write_script(name, text):
             expected.append(name)
             f = open(os.path.join(source, name), "w")
-            f.write(text)
-            f.close()
+            try:
+                f.write(text)
+            finally:
+                f.close()
 
         write_script("script1.py", ("#! /usr/bin/env python2.3\n"
                                     "# bogus script w/ Python sh-bang\n"
diff --git a/src/distutils2/tests/test_manifest.py b/src/distutils2/tests/test_manifest.py
--- a/src/distutils2/tests/test_manifest.py
+++ b/src/distutils2/tests/test_manifest.py
@@ -44,7 +44,7 @@
 
         # the manifest should have been read
         # and 3 warnings issued (we ddidn't provided the files)
-        self.assertEquals(len(warns), 3)
+        self.assertEqual(len(warns), 3)
         for warn in warns:
             self.assertIn('warning: no files found matching', warn)
 
diff --git a/src/distutils2/tests/test_metadata.py b/src/distutils2/tests/test_metadata.py
--- a/src/distutils2/tests/test_metadata.py
+++ b/src/distutils2/tests/test_metadata.py
@@ -5,9 +5,9 @@
 
 from distutils2.metadata import (DistributionMetadata, _interpret,
                                  PKG_INFO_PREFERRED_VERSION)
-from distutils2.tests.support import unittest
+from distutils2.tests.support import unittest, LoggingSilencer
 
-class DistributionMetadataTestCase(unittest.TestCase):
+class DistributionMetadataTestCase(LoggingSilencer, unittest.TestCase):
 
 
     def test_interpret(self):
@@ -15,15 +15,15 @@
         version = sys.version.split()[0]
         os_name = os.name
 
-        assert _interpret("sys.platform == '%s'" % platform)
-        assert _interpret("sys.platform == '%s' or python_version == '2.4'" \
-                % platform)
-        assert _interpret("sys.platform == '%s' and "
-                          "python_full_version == '%s'"\
-                % (platform, version))
-        assert _interpret("'%s' == sys.platform" % platform)
+        self.assertTrue(_interpret("sys.platform == '%s'" % platform))
+        self.assertTrue(_interpret(
+            "sys.platform == '%s' or python_version == '2.4'" % platform))
+        self.assertTrue(_interpret(
+            "sys.platform == '%s' and python_full_version == '%s'" %
+            (platform, version)))
+        self.assertTrue(_interpret("'%s' == sys.platform" % platform))
 
-        assert _interpret('os.name == "%s"' % os_name)
+        self.assertTrue(_interpret('os.name == "%s"' % os_name))
 
         # stuff that need to raise a syntax error
         ops = ('os.name == os.name', 'os.name == 2', "'2' == '2'",
@@ -35,24 +35,25 @@
         OP = 'os.name == "%s"' % os_name
         AND = ' and '
         OR = ' or '
-        assert _interpret(OP+AND+OP)
-        assert _interpret(OP+AND+OP+AND+OP)
-        assert _interpret(OP+OR+OP)
-        assert _interpret(OP+OR+OP+OR+OP)
+        self.assertTrue(_interpret(OP + AND + OP))
+        self.assertTrue(_interpret(OP + AND + OP + AND + OP))
+        self.assertTrue(_interpret(OP + OR + OP))
+        self.assertTrue(_interpret(OP + OR + OP + OR + OP))
 
         # other operators
-        assert _interpret("os.name != 'buuuu'")
-        assert _interpret("python_version > '1.0'")
-        assert _interpret("python_version < '5.0'")
-        assert _interpret("python_version <= '5.0'")
-        assert _interpret("python_version >= '1.0'")
-        assert _interpret("'%s' in os.name" % os_name)
-        assert _interpret("'buuuu' not in os.name")
-        assert _interpret("'buuuu' not in os.name and '%s' in os.name" \
-                            % os_name)
+        self.assertTrue(_interpret("os.name != 'buuuu'"))
+        self.assertTrue(_interpret("python_version > '1.0'"))
+        self.assertTrue(_interpret("python_version < '5.0'"))
+        self.assertTrue(_interpret("python_version <= '5.0'"))
+        self.assertTrue(_interpret("python_version >= '1.0'"))
+        self.assertTrue(_interpret("'%s' in os.name" % os_name))
+        self.assertTrue(_interpret("'buuuu' not in os.name"))
+        self.assertTrue(_interpret(
+            "'buuuu' not in os.name and '%s' in os.name" % os_name))
 
         # execution context
-        assert _interpret('python_version == "0.1"', {'python_version': '0.1'})
+        self.assertTrue(_interpret('python_version == "0.1"',
+                                   {'python_version': '0.1'}))
 
     def test_metadata_read_write(self):
 
@@ -63,25 +64,28 @@
         res.seek(0)
         res = res.read()
         f = open(PKG_INFO)
-        wanted = f.read()
+        try:
+            # XXX this is not used
+            wanted = f.read()
+        finally:
+            f.close()
         self.assertTrue('Keywords: keyring,password,crypt' in res)
-        f.close()
 
     def test_metadata_markers(self):
         # see if we can be platform-aware
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
         content = open(PKG_INFO).read()
         content = content % sys.platform
-        metadata = DistributionMetadata(platform_dependant=True)
+        metadata = DistributionMetadata(platform_dependent=True)
         metadata.read_file(StringIO(content))
-        self.assertEquals(metadata['Requires-Dist'], ['bar'])
+        self.assertEqual(metadata['Requires-Dist'], ['bar'])
 
         # test with context
         context = {'sys.platform': 'okook'}
-        metadata = DistributionMetadata(platform_dependant=True,
+        metadata = DistributionMetadata(platform_dependent=True,
                                         execution_context=context)
         metadata.read_file(StringIO(content))
-        self.assertEquals(metadata['Requires-Dist'], ['foo'])
+        self.assertEqual(metadata['Requires-Dist'], ['foo'])
 
     def test_description(self):
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
@@ -93,14 +97,14 @@
         # see if we can read the description now
         DESC = os.path.join(os.path.dirname(__file__), 'LONG_DESC.txt')
         wanted = open(DESC).read()
-        self.assertEquals(wanted, metadata['Description'])
+        self.assertEqual(wanted, metadata['Description'])
 
         # save the file somewhere and make sure we can read it back
         out = StringIO()
         metadata.write_file(out)
         out.seek(0)
         metadata.read_file(out)
-        self.assertEquals(wanted, metadata['Description'])
+        self.assertEqual(wanted, metadata['Description'])
 
     def test_mapper_apis(self):
         PKG_INFO = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
@@ -115,25 +119,25 @@
     def test_versions(self):
         metadata = DistributionMetadata()
         metadata['Obsoletes'] = 'ok'
-        self.assertEquals(metadata['Metadata-Version'], '1.1')
+        self.assertEqual(metadata['Metadata-Version'], '1.1')
 
         del metadata['Obsoletes']
         metadata['Obsoletes-Dist'] = 'ok'
-        self.assertEquals(metadata['Metadata-Version'], '1.2')
+        self.assertEqual(metadata['Metadata-Version'], '1.2')
 
         del metadata['Obsoletes-Dist']
         metadata['Version'] = '1'
-        self.assertEquals(metadata['Metadata-Version'], '1.0')
+        self.assertEqual(metadata['Metadata-Version'], '1.0')
 
         PKG_INFO = os.path.join(os.path.dirname(__file__),
                                 'SETUPTOOLS-PKG-INFO')
         metadata.read_file(StringIO(open(PKG_INFO).read()))
-        self.assertEquals(metadata['Metadata-Version'], '1.0')
+        self.assertEqual(metadata['Metadata-Version'], '1.0')
 
         PKG_INFO = os.path.join(os.path.dirname(__file__),
                                 'SETUPTOOLS-PKG-INFO2')
         metadata.read_file(StringIO(open(PKG_INFO).read()))
-        self.assertEquals(metadata['Metadata-Version'], '1.1')
+        self.assertEqual(metadata['Metadata-Version'], '1.1')
 
     def test_warnings(self):
         metadata = DistributionMetadata()
@@ -161,7 +165,7 @@
 
         # we should have a certain amount of warnings
         num_wanted = len(values)
-        self.assertEquals(num_wanted, res)
+        self.assertEqual(num_wanted, res)
 
     def test_multiple_predicates(self):
         metadata = DistributionMetadata()
@@ -184,29 +188,29 @@
             res = m.warns
             del m.warns
 
-        self.assertEquals(res, 0)
+        self.assertEqual(res, 0)
 
     def test_project_url(self):
         metadata = DistributionMetadata()
         metadata['Project-URL'] = [('one', 'http://ok')]
-        self.assertEquals(metadata['Project-URL'],
+        self.assertEqual(metadata['Project-URL'],
                           [('one', 'http://ok')])
-        self.assertEquals(metadata.version, '1.2')
+        self.assertEqual(metadata.version, '1.2')
 
     def test_check(self):
         metadata = DistributionMetadata()
         metadata['Version'] = 'rr'
         metadata['Requires-dist'] = ['Foo (a)']
         missing, warnings = metadata.check()
-        self.assertEquals(missing, ['Name', 'Home-page'])
-        self.assertEquals(len(warnings), 2)
+        self.assertEqual(missing, ['Name', 'Home-page'])
+        self.assertEqual(len(warnings), 2)
 
     def test_best_choice(self):
         metadata = DistributionMetadata()
         metadata['Version'] = '1.0'
-        self.assertEquals(metadata.version, PKG_INFO_PREFERRED_VERSION)
+        self.assertEqual(metadata.version, PKG_INFO_PREFERRED_VERSION)
         metadata['Classifier'] = ['ok']
-        self.assertEquals(metadata.version, '1.2')
+        self.assertEqual(metadata.version, '1.2')
 
     def test_project_urls(self):
         # project-url is a bit specific, make sure we write it
@@ -214,7 +218,7 @@
         metadata = DistributionMetadata()
         metadata['Version'] = '1.0'
         metadata['Project-Url'] = [('one', 'http://ok')]
-        self.assertEquals(metadata['Project-Url'], [('one', 'http://ok')])
+        self.assertEqual(metadata['Project-Url'], [('one', 'http://ok')])
         file_ = StringIO()
         metadata.write_file(file_)
         file_.seek(0)
@@ -224,7 +228,7 @@
         file_.seek(0)
         metadata = DistributionMetadata()
         metadata.read_file(file_)
-        self.assertEquals(metadata['Project-Url'], [('one', 'http://ok')])
+        self.assertEqual(metadata['Project-Url'], [('one', 'http://ok')])
 
 
 def test_suite():
diff --git a/src/distutils2/tests/test_msvc9compiler.py b/src/distutils2/tests/test_msvc9compiler.py
--- a/src/distutils2/tests/test_msvc9compiler.py
+++ b/src/distutils2/tests/test_msvc9compiler.py
@@ -105,7 +105,7 @@
         import _winreg
         HKCU = _winreg.HKEY_CURRENT_USER
         keys = Reg.read_keys(HKCU, 'xxxx')
-        self.assertEquals(keys, None)
+        self.assertEqual(keys, None)
 
         keys = Reg.read_keys(HKCU, r'Control Panel')
         self.assertTrue('Desktop' in keys)
@@ -116,20 +116,24 @@
         tempdir = self.mkdtemp()
         manifest = os.path.join(tempdir, 'manifest')
         f = open(manifest, 'w')
-        f.write(_MANIFEST)
-        f.close()
+        try:
+            f.write(_MANIFEST)
+        finally:
+            f.close()
 
         compiler = MSVCCompiler()
         compiler._remove_visual_c_ref(manifest)
 
         # see what we got
         f = open(manifest)
-        # removing trailing spaces
-        content = '\n'.join([line.rstrip() for line in f.readlines()])
-        f.close()
+        try:
+            # removing trailing spaces
+            content = '\n'.join([line.rstrip() for line in f.readlines()])
+        finally:
+            f.close()
 
         # makes sure the manifest was properly cleaned
-        self.assertEquals(content, _CLEANED_MANIFEST)
+        self.assertEqual(content, _CLEANED_MANIFEST)
 
 
 def test_suite():
diff --git a/src/distutils2/tests/test_register.py b/src/distutils2/tests/test_register.py
--- a/src/distutils2/tests/test_register.py
+++ b/src/distutils2/tests/test_register.py
@@ -124,7 +124,7 @@
 
         # with the content similar to WANTED_PYPIRC
         content = open(self.rc).read()
-        self.assertEquals(content, WANTED_PYPIRC)
+        self.assertEqual(content, WANTED_PYPIRC)
 
         # now let's make sure the .pypirc file generated
         # really works : we shouldn't be asked anything
@@ -141,7 +141,7 @@
         self.assertTrue(self.conn.reqs, 2)
         req1 = dict(self.conn.reqs[0].headers)
         req2 = dict(self.conn.reqs[1].headers)
-        self.assertEquals(req2['Content-length'], req1['Content-length'])
+        self.assertEqual(req2['Content-length'], req1['Content-length'])
         self.assertTrue('xxx' in self.conn.reqs[1].data)
 
     def test_password_not_in_file(self):
@@ -154,7 +154,7 @@
 
         # dist.password should be set
         # therefore used afterwards by other commands
-        self.assertEquals(cmd.distribution.password, 'password')
+        self.assertEqual(cmd.distribution.password, 'password')
 
     def test_registering(self):
         # this test runs choice 2
@@ -171,7 +171,7 @@
         self.assertTrue(self.conn.reqs, 1)
         req = self.conn.reqs[0]
         headers = dict(req.headers)
-        self.assertEquals(headers['Content-length'], '608')
+        self.assertEqual(headers['Content-length'], '608')
         self.assertTrue('tarek' in req.data)
 
     def test_password_reset(self):
@@ -189,7 +189,7 @@
         self.assertTrue(self.conn.reqs, 1)
         req = self.conn.reqs[0]
         headers = dict(req.headers)
-        self.assertEquals(headers['Content-length'], '290')
+        self.assertEqual(headers['Content-length'], '290')
         self.assertTrue('tarek' in req.data)
 
     @unittest.skipUnless(DOCUTILS_SUPPORT, 'needs docutils')
@@ -246,8 +246,8 @@
         cmd.ensure_finalized()
         cmd.distribution.metadata['Requires-Dist'] = ['lxml']
         data = cmd.build_post_data('submit')
-        self.assertEquals(data['metadata_version'], '1.2')
-        self.assertEquals(data['requires_dist'], ['lxml'])
+        self.assertEqual(data['metadata_version'], '1.2')
+        self.assertEqual(data['requires_dist'], ['lxml'])
 
 def test_suite():
     return unittest.makeSuite(RegisterTestCase)
diff --git a/src/distutils2/tests/test_sdist.py b/src/distutils2/tests/test_sdist.py
--- a/src/distutils2/tests/test_sdist.py
+++ b/src/distutils2/tests/test_sdist.py
@@ -20,7 +20,6 @@
 
 from os.path import join
 import sys
-import tempfile
 import warnings
 
 from distutils2.tests import captured_stdout
@@ -128,7 +127,7 @@
         # now let's check what we have
         dist_folder = join(self.tmp_dir, 'dist')
         files = os.listdir(dist_folder)
-        self.assertEquals(files, ['fake-1.0.zip'])
+        self.assertEqual(files, ['fake-1.0.zip'])
 
         zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
         try:
@@ -137,7 +136,7 @@
             zip_file.close()
 
         # making sure everything has been pruned correctly
-        self.assertEquals(len(content), 4)
+        self.assertEqual(len(content), 4)
 
     @unittest.skipUnless(zlib, "requires zlib")
     def test_make_distribution(self):
@@ -159,7 +158,7 @@
         dist_folder = join(self.tmp_dir, 'dist')
         result = os.listdir(dist_folder)
         result.sort()
-        self.assertEquals(result,
+        self.assertEqual(result,
                           ['fake-1.0.tar', 'fake-1.0.tar.gz'] )
 
         os.remove(join(dist_folder, 'fake-1.0.tar'))
@@ -173,7 +172,7 @@
 
         result = os.listdir(dist_folder)
         result.sort()
-        self.assertEquals(result,
+        self.assertEqual(result,
                 ['fake-1.0.tar', 'fake-1.0.tar.gz'])
 
     @unittest.skipUnless(zlib, "requires zlib")
@@ -223,7 +222,7 @@
         # now let's check what we have
         dist_folder = join(self.tmp_dir, 'dist')
         files = os.listdir(dist_folder)
-        self.assertEquals(files, ['fake-1.0.zip'])
+        self.assertEqual(files, ['fake-1.0.zip'])
 
         zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
         try:
@@ -232,11 +231,11 @@
             zip_file.close()
 
         # making sure everything was added
-        self.assertEquals(len(content), 11)
+        self.assertEqual(len(content), 11)
 
         # checking the MANIFEST
         manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
-        self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
+        self.assertEqual(manifest, MANIFEST % {'sep': os.sep})
 
     @unittest.skipUnless(zlib, "requires zlib")
     def test_metadata_check_option(self):
@@ -248,7 +247,7 @@
         cmd.ensure_finalized()
         cmd.run()
         warnings = self.get_logs(WARN)
-        self.assertEquals(len(warnings), 1)
+        self.assertEqual(len(warnings), 1)
 
         # trying with a complete set of metadata
         self.clear_logs()
@@ -260,7 +259,7 @@
         # removing manifest generated warnings
         warnings = [warn for warn in warnings if
                     not warn.endswith('-- skipping')]
-        self.assertEquals(len(warnings), 0)
+        self.assertEqual(len(warnings), 0)
 
 
     def test_show_formats(self):
@@ -270,7 +269,7 @@
         num_formats = len(get_archive_formats())
         output = [line for line in stdout.split('\n')
                   if line.strip().startswith('--formats=')]
-        self.assertEquals(len(output), num_formats)
+        self.assertEqual(len(output), num_formats)
 
     def test_finalize_options(self):
 
@@ -278,9 +277,9 @@
         cmd.finalize_options()
 
         # default options set by finalize
-        self.assertEquals(cmd.manifest, 'MANIFEST')
-        self.assertEquals(cmd.template, 'MANIFEST.in')
-        self.assertEquals(cmd.dist_dir, 'dist')
+        self.assertEqual(cmd.manifest, 'MANIFEST')
+        self.assertEqual(cmd.template, 'MANIFEST.in')
+        self.assertEqual(cmd.dist_dir, 'dist')
 
         # formats has to be a string splitable on (' ', ',') or
         # a stringlist
@@ -317,8 +316,8 @@
         archive = tarfile.open(archive_name)
         try:
             for member in archive.getmembers():
-                self.assertEquals(member.uid, 0)
-                self.assertEquals(member.gid, 0)
+                self.assertEqual(member.uid, 0)
+                self.assertEqual(member.gid, 0)
         finally:
             archive.close()
 
@@ -339,7 +338,7 @@
         # rights (see #7408)
         try:
             for member in archive.getmembers():
-                self.assertEquals(member.uid, os.getuid())
+                self.assertEqual(member.uid, os.getuid())
         finally:
             archive.close()
 
diff --git a/src/distutils2/tests/test_spawn.py b/src/distutils2/tests/test_spawn.py
--- a/src/distutils2/tests/test_spawn.py
+++ b/src/distutils2/tests/test_spawn.py
@@ -20,7 +20,7 @@
                                (['nochange', 'nospace'],
                                 ['nochange', 'nospace'])):
             res = _nt_quote_args(args)
-            self.assertEquals(res, wanted)
+            self.assertEqual(res, wanted)
 
 
     @unittest.skipUnless(os.name in ('nt', 'posix'),
diff --git a/src/distutils2/tests/test_util.py b/src/distutils2/tests/test_util.py
--- a/src/distutils2/tests/test_util.py
+++ b/src/distutils2/tests/test_util.py
@@ -100,7 +100,7 @@
             return '/'.join(path)
         os.path.join = _join
 
-        self.assertEquals(convert_path('/home/to/my/stuff'),
+        self.assertEqual(convert_path('/home/to/my/stuff'),
                           '/home/to/my/stuff')
 
         # win
@@ -112,9 +112,9 @@
         self.assertRaises(ValueError, convert_path, '/home/to/my/stuff')
         self.assertRaises(ValueError, convert_path, 'home/to/my/stuff/')
 
-        self.assertEquals(convert_path('home/to/my/stuff'),
+        self.assertEqual(convert_path('home/to/my/stuff'),
                           'home\\to\\my\\stuff')
-        self.assertEquals(convert_path('.'),
+        self.assertEqual(convert_path('.'),
                           os.curdir)
 
     def test_change_root(self):
@@ -127,9 +127,9 @@
             return '/'.join(path)
         os.path.join = _join
 
-        self.assertEquals(change_root('/root', '/old/its/here'),
+        self.assertEqual(change_root('/root', '/old/its/here'),
                           '/root/old/its/here')
-        self.assertEquals(change_root('/root', 'its/here'),
+        self.assertEqual(change_root('/root', 'its/here'),
                           '/root/its/here')
 
         # windows
@@ -146,9 +146,9 @@
             return '\\'.join(path)
         os.path.join = _join
 
-        self.assertEquals(change_root('c:\\root', 'c:\\old\\its\\here'),
+        self.assertEqual(change_root('c:\\root', 'c:\\old\\its\\here'),
                           'c:\\root\\old\\its\\here')
-        self.assertEquals(change_root('c:\\root', 'its\\here'),
+        self.assertEqual(change_root('c:\\root', 'its\\here'),
                           'c:\\root\\its\\here')
 
         # BugsBunny os (it's a great os)
@@ -159,7 +159,7 @@
         # XXX platforms to be covered: os2, mac
 
     def test_split_quoted(self):
-        self.assertEquals(split_quoted('""one"" "two" \'three\' \\four'),
+        self.assertEqual(split_quoted('""one"" "two" \'three\' \\four'),
                           ['one', 'two', 'three', 'four'])
 
     def test_strtobool(self):
@@ -177,7 +177,7 @@
         res = rfc822_escape(header)
         wanted = ('I am a%(8s)spoor%(8s)slonesome%(8s)s'
                   'header%(8s)s') % {'8s': '\n'+8*' '}
-        self.assertEquals(res, wanted)
+        self.assertEqual(res, wanted)
 
     def test_find_exe_version(self):
         # the ld version scheme under MAC OS is:
@@ -195,7 +195,7 @@
                                 ('@(#)PROGRAM:ld  PROJECT:ld64-95.2.12',
                                  '95.2.12')):
             result = _MAC_OS_X_LD_VERSION.search(output)
-            self.assertEquals(result.group(1), version)
+            self.assertEqual(result.group(1), version)
 
     def _find_executable(self, name):
         if name in self._exes:
@@ -205,43 +205,43 @@
     def test_get_compiler_versions(self):
         # get_versions calls distutils.spawn.find_executable on
         # 'gcc', 'ld' and 'dllwrap'
-        self.assertEquals(get_compiler_versions(), (None, None, None))
+        self.assertEqual(get_compiler_versions(), (None, None, None))
 
         # Let's fake we have 'gcc' and it returns '3.4.5'
         self._exes['gcc'] = 'gcc (GCC) 3.4.5 (mingw special)\nFSF'
         res = get_compiler_versions()
-        self.assertEquals(str(res[0]), '3.4.5')
+        self.assertEqual(str(res[0]), '3.4.5')
 
         # and let's see what happens when the version
         # doesn't match the regular expression
         # (\d+\.\d+(\.\d+)*)
         self._exes['gcc'] = 'very strange output'
         res = get_compiler_versions()
-        self.assertEquals(res[0], None)
+        self.assertEqual(res[0], None)
 
         # same thing for ld
         if sys.platform != 'darwin':
             self._exes['ld'] = 'GNU ld version 2.17.50 20060824'
             res = get_compiler_versions()
-            self.assertEquals(str(res[1]), '2.17.50')
+            self.assertEqual(str(res[1]), '2.17.50')
             self._exes['ld'] = '@(#)PROGRAM:ld  PROJECT:ld64-77'
             res = get_compiler_versions()
-            self.assertEquals(res[1], None)
+            self.assertEqual(res[1], None)
         else:
             self._exes['ld'] = 'GNU ld version 2.17.50 20060824'
             res = get_compiler_versions()
-            self.assertEquals(res[1], None)
+            self.assertEqual(res[1], None)
             self._exes['ld'] = '@(#)PROGRAM:ld  PROJECT:ld64-77'
             res = get_compiler_versions()
-            self.assertEquals(str(res[1]), '77')
+            self.assertEqual(str(res[1]), '77')
 
         # and dllwrap
         self._exes['dllwrap'] = 'GNU dllwrap 2.17.50 20060824\nFSF'
         res = get_compiler_versions()
-        self.assertEquals(str(res[2]), '2.17.50')
+        self.assertEqual(str(res[2]), '2.17.50')
         self._exes['dllwrap'] = 'Cheese Wrap'
         res = get_compiler_versions()
-        self.assertEquals(res[2], None)
+        self.assertEqual(res[2], None)
 
     @unittest.skipUnless(hasattr(sys, 'dont_write_bytecode'),
                           'no dont_write_bytecode support')
@@ -294,7 +294,7 @@
         self.write_file(os.path.join(pkg5, '__init__.py'))
 
         res = find_packages([root], ['pkg1.pkg2'])
-        self.assertEquals(set(res), set(['pkg1', 'pkg5', 'pkg1.pkg3', 'pkg1.pkg3.pkg6']))
+        self.assertEqual(set(res), set(['pkg1', 'pkg5', 'pkg1.pkg3', 'pkg1.pkg3.pkg6']))
 
 
 def test_suite():
diff --git a/src/distutils2/tests/test_version.py b/src/distutils2/tests/test_version.py
--- a/src/distutils2/tests/test_version.py
+++ b/src/distutils2/tests/test_version.py
@@ -25,15 +25,15 @@
     def test_basic_versions(self):
 
         for v, s in self.versions:
-            self.assertEquals(str(v), s)
+            self.assertEqual(str(v), s)
 
     def test_from_parts(self):
 
         for v, s in self.versions:
             parts = v.parts
             v2 = V.from_parts(*v.parts)
-            self.assertEquals(v, v2)
-            self.assertEquals(str(v), str(v2))
+            self.assertEqual(v, v2)
+            self.assertEqual(str(v), str(v2))
 
     def test_irrational_versions(self):
 
@@ -96,34 +96,34 @@
 
     def test_suggest_normalized_version(self):
 
-        self.assertEquals(suggest('1.0'), '1.0')
-        self.assertEquals(suggest('1.0-alpha1'), '1.0a1')
-        self.assertEquals(suggest('1.0c2'), '1.0c2')
-        self.assertEquals(suggest('walla walla washington'), None)
-        self.assertEquals(suggest('2.4c1'), '2.4c1')
+        self.assertEqual(suggest('1.0'), '1.0')
+        self.assertEqual(suggest('1.0-alpha1'), '1.0a1')
+        self.assertEqual(suggest('1.0c2'), '1.0c2')
+        self.assertEqual(suggest('walla walla washington'), None)
+        self.assertEqual(suggest('2.4c1'), '2.4c1')
 
         # from setuptools
-        self.assertEquals(suggest('0.4a1.r10'), '0.4a1.post10')
-        self.assertEquals(suggest('0.7a1dev-r66608'), '0.7a1.dev66608')
-        self.assertEquals(suggest('0.6a9.dev-r41475'), '0.6a9.dev41475')
-        self.assertEquals(suggest('2.4preview1'), '2.4c1')
-        self.assertEquals(suggest('2.4pre1') , '2.4c1')
-        self.assertEquals(suggest('2.1-rc2'), '2.1c2')
+        self.assertEqual(suggest('0.4a1.r10'), '0.4a1.post10')
+        self.assertEqual(suggest('0.7a1dev-r66608'), '0.7a1.dev66608')
+        self.assertEqual(suggest('0.6a9.dev-r41475'), '0.6a9.dev41475')
+        self.assertEqual(suggest('2.4preview1'), '2.4c1')
+        self.assertEqual(suggest('2.4pre1') , '2.4c1')
+        self.assertEqual(suggest('2.1-rc2'), '2.1c2')
 
         # from pypi
-        self.assertEquals(suggest('0.1dev'), '0.1.dev0')
-        self.assertEquals(suggest('0.1.dev'), '0.1.dev0')
+        self.assertEqual(suggest('0.1dev'), '0.1.dev0')
+        self.assertEqual(suggest('0.1.dev'), '0.1.dev0')
 
         # we want to be able to parse Twisted
         # development versions are like post releases in Twisted
-        self.assertEquals(suggest('9.0.0+r2363'), '9.0.0.post2363')
+        self.assertEqual(suggest('9.0.0+r2363'), '9.0.0.post2363')
 
         # pre-releases are using markers like "pre1"
-        self.assertEquals(suggest('9.0.0pre1'), '9.0.0c1')
+        self.assertEqual(suggest('9.0.0pre1'), '9.0.0c1')
 
         # we want to be able to parse Tcl-TK
         # they us "p1" "p2" for post releases
-        self.assertEquals(suggest('1.4p1'), '1.4.post1')
+        self.assertEqual(suggest('1.4p1'), '1.4.post1')
 
     def test_predicate(self):
         # VersionPredicate knows how to parse stuff like:
diff --git a/src/distutils2/util.py b/src/distutils2/util.py
--- a/src/distutils2/util.py
+++ b/src/distutils2/util.py
@@ -1,12 +1,12 @@
 """distutils.util
 
-Miscellaneous utility functions -- anything that doesn't fit into
-one of the other *util.py modules.
+Miscellaneous utility functions.
 """
 
 __revision__ = "$Id: util.py 77761 2010-01-26 22:46:15Z tarek.ziade $"
 
 import sys, os, string, re
+from copy import copy
 from fnmatch import fnmatchcase
 
 from distutils2.errors import (DistutilsPlatformError, DistutilsFileError,
@@ -350,12 +350,8 @@
     # "Indirect" byte-compilation: write a temporary script and then
     # run it with the appropriate flags.
     if not direct:
-        try:
-            from tempfile import mkstemp
-            (script_fd, script_name) = mkstemp(".py")
-        except ImportError:
-            from tempfile import mktemp
-            (script_fd, script_name) = None, mktemp(".py")
+        from tempfile import mkstemp
+        script_fd, script_name = mkstemp(".py")
         log.info("writing byte-compilation script '%s'", script_name)
         if not dry_run:
             if script_fd is not None:
@@ -363,43 +359,50 @@
             else:
                 script = open(script_name, "w")
 
-            script.write("""\
-from distutils.util import byte_compile
+            try:
+                script.write("""\
+from distutils2.util import byte_compile
 files = [
 """)
 
-            # XXX would be nice to write absolute filenames, just for
-            # safety's sake (script should be more robust in the face of
-            # chdir'ing before running it).  But this requires abspath'ing
-            # 'prefix' as well, and that breaks the hack in build_lib's
-            # 'byte_compile()' method that carefully tacks on a trailing
-            # slash (os.sep really) to make sure the prefix here is "just
-            # right".  This whole prefix business is rather delicate -- the
-            # problem is that it's really a directory, but I'm treating it
-            # as a dumb string, so trailing slashes and so forth matter.
+                # XXX would be nice to write absolute filenames, just for
+                # safety's sake (script should be more robust in the face of
+                # chdir'ing before running it).  But this requires abspath'ing
+                # 'prefix' as well, and that breaks the hack in build_lib's
+                # 'byte_compile()' method that carefully tacks on a trailing
+                # slash (os.sep really) to make sure the prefix here is "just
+                # right".  This whole prefix business is rather delicate -- the
+                # problem is that it's really a directory, but I'm treating it
+                # as a dumb string, so trailing slashes and so forth matter.
 
-            #py_files = map(os.path.abspath, py_files)
-            #if prefix:
-            #    prefix = os.path.abspath(prefix)
+                #py_files = map(os.path.abspath, py_files)
+                #if prefix:
+                #    prefix = os.path.abspath(prefix)
 
-            script.write(",\n".join(map(repr, py_files)) + "]\n")
-            script.write("""
+                script.write(",\n".join(map(repr, py_files)) + "]\n")
+                script.write("""
 byte_compile(files, optimize=%r, force=%r,
              prefix=%r, base_dir=%r,
              verbose=%r, dry_run=0,
              direct=1)
 """ % (optimize, force, prefix, base_dir, verbose))
 
-            script.close()
+            finally:
+                script.close()
 
         cmd = [sys.executable, script_name]
         if optimize == 1:
             cmd.insert(1, "-O")
         elif optimize == 2:
             cmd.insert(1, "-OO")
-        spawn(cmd, dry_run=dry_run)
-        execute(os.remove, (script_name,), "removing %s" % script_name,
-                dry_run=dry_run)
+
+        env = copy(os.environ)
+        env['PYTHONPATH'] = ':'.join(sys.path)
+        try:
+            spawn(cmd, dry_run=dry_run, env=env)
+        finally:
+            execute(os.remove, (script_name,), "removing %s" % script_name,
+                    dry_run=dry_run)
 
     # "Direct" byte-compilation: use the py_compile module to compile
     # right here, right now.  Note that the script generated in indirect
@@ -539,10 +542,12 @@
     """Create a file with the specified name and write 'contents' (a
     sequence of strings without line terminators) to it.
     """
-    f = open(filename, "w")
-    for line in contents:
-        f.write(line + "\n")
-    f.close()
+    try:
+        f = open(filename, "w")
+        for line in contents:
+            f.write(line + "\n")
+    finally:
+        f.close()
 
 def _is_package(path):
     """Returns True if path is a package (a dir with an __init__ file."""
diff --git a/src/runtests.py b/src/runtests.py
--- a/src/runtests.py
+++ b/src/runtests.py
@@ -1,6 +1,6 @@
 """Tests for distutils2.
 
-The tests for distutils2 are defined in the distutils2.tests package;
+The tests for distutils2 are defined in the distutils2.tests package.
 """
 import sys
 
@@ -8,8 +8,7 @@
     import distutils2.tests
     from distutils2.tests import run_unittest, reap_children, TestFailed
     from distutils2._backport.tests import test_suite as btest_suite
-    # just supporting -q right now
-    # to enable detailed/quiet output
+    # XXX just supporting -q right now to enable detailed/quiet output
     if len(sys.argv) > 1:
         verbose = sys.argv[-1] != '-q'
     else:
@@ -17,7 +16,7 @@
     try:
         try:
             run_unittest([distutils2.tests.test_suite(), btest_suite()],
-                    verbose_=verbose)
+                         verbose_=verbose)
             return 0
         except TestFailed:
             return 1
@@ -28,7 +27,7 @@
     try:
         from distutils2.tests.support import unittest
     except ImportError:
-        print('Error: You have to install unittest2')
+        sys.stderr.write('Error: You have to install unittest2')
         sys.exit(1)
 
     sys.exit(test_main())
diff --git a/src/setup.py b/src/setup.py
--- a/src/setup.py
+++ b/src/setup.py
@@ -11,6 +11,7 @@
 from distutils2.compiler.ccompiler import new_compiler
 from distutils2.command.sdist import sdist
 from distutils2.command.install import install
+from distutils2 import __version__ as VERSION
 from distutils2.util import find_packages
 
 f = open('README.txt')
diff --git a/src/tests.sh b/src/tests.sh
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -1,28 +1,36 @@
 #!/bin/sh
-echo -n "Running tests for Python 2.4..."
-python2.4 runtests.py -q > /dev/null 2> /dev/null
+echo -n "Running tests for Python 2.4... "
+python2.4 -Wd runtests.py -q 2> /dev/null
 if [ $? -ne 0 ];then
     echo "Failed"
-    exit $1
+    exit 1
 else
     echo "Success"
 fi
 
-echo -n "Running tests for Python 2.5..."
-python2.5 runtests.py -q > /dev/null 2> /dev/null
+echo -n "Running tests for Python 2.5... "
+python2.5 -Wd runtests.py -q 2> /dev/null
 if [ $? -ne 0 ];then
     echo "Failed"
-    exit $1
+    exit 1
 else
     echo "Success"
 fi
 
-echo -n "Running tests for Python 2.6..."
-python2.6 runtests.py -q > /dev/null 2> /dev/null
+echo -n "Running tests for Python 2.6... "
+python2.6 -Wd -bb -3 runtests.py -q 2> /dev/null
 if [ $? -ne 0 ];then
     echo "Failed"
-    exit $1
+    exit 1
 else
     echo "Success"
 fi
 
+echo -n "Running tests for Python 2.7... "
+python2.7 -Wd -bb -3 runtests.py -q 2> /dev/null
+if [ $? -ne 0 ];then
+    echo "Failed"
+    exit 1
+else
+    echo "Success"
+fi

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list