[Python-checkins] cpython (merge default -> default): Branch merge

eric.araujo python-checkins at python.org
Mon Sep 19 16:11:02 CEST 2011


http://hg.python.org/cpython/rev/cb56ab0cb9c5
changeset:   72411:cb56ab0cb9c5
parent:      72400:a4e4facad164
parent:      72410:9c61f46ea6b4
user:        Éric Araujo <merwok at netwok.org>
date:        Mon Sep 19 16:10:26 2011 +0200
summary:
  Branch merge

files:
  Lib/packaging/command/bdist_dumb.py              |   4 +-
  Lib/packaging/command/build_clib.py              |   3 +-
  Lib/packaging/command/build_ext.py               |  17 +-
  Lib/packaging/command/build_py.py                |   2 +-
  Lib/packaging/command/build_scripts.py           |   4 +-
  Lib/packaging/command/install_dist.py            |  59 +++-----
  Lib/packaging/command/install_distinfo.py        |   9 +-
  Lib/packaging/command/install_lib.py             |   2 +-
  Lib/packaging/command/upload_docs.py             |   1 +
  Lib/packaging/compat.py                          |   8 +-
  Lib/packaging/compiler/bcppcompiler.py           |   1 -
  Lib/packaging/compiler/ccompiler.py              |   1 -
  Lib/packaging/compiler/unixccompiler.py          |   2 +-
  Lib/packaging/create.py                          |  22 +--
  Lib/packaging/database.py                        |   7 +-
  Lib/packaging/dist.py                            |   4 +-
  Lib/packaging/metadata.py                        |   7 +-
  Lib/packaging/pypi/simple.py                     |   7 +-
  Lib/packaging/tests/__init__.py                  |  13 +-
  Lib/packaging/tests/__main__.py                  |   2 +
  Lib/packaging/tests/pypi_server.py               |   7 +-
  Lib/packaging/tests/test_command_bdist_dumb.py   |   2 +-
  Lib/packaging/tests/test_command_build_ext.py    |  19 +-
  Lib/packaging/tests/test_command_build_py.py     |   2 -
  Lib/packaging/tests/test_command_install_dist.py |  12 +-
  Lib/packaging/tests/test_command_install_lib.py  |  11 +-
  Lib/packaging/tests/test_command_register.py     |   2 +-
  Lib/packaging/tests/test_command_upload.py       |  24 +--
  Lib/packaging/tests/test_command_upload_docs.py  |  67 ++++-----
  Lib/packaging/tests/test_create.py               |  13 +-
  Lib/packaging/tests/test_database.py             |   5 +-
  Lib/packaging/tests/test_depgraph.py             |  33 ++--
  Lib/packaging/tests/test_dist.py                 |  16 +-
  Lib/packaging/tests/test_install.py              |   2 +-
  Lib/packaging/tests/test_metadata.py             |   4 +-
  Lib/packaging/tests/test_mixin2to3.py            |   3 -
  Lib/packaging/tests/test_pypi_server.py          |  15 +-
  Lib/packaging/tests/test_run.py                  |  17 +--
  Lib/packaging/tests/test_util.py                 |  10 +-
  Lib/packaging/util.py                            |   6 +-
  Lib/pkgutil.py                                   |   4 +-
  Lib/shutil.py                                    |   8 +-
  Lib/test/regrtest.py                             |  25 +++-
  Lib/test/test_sysconfig.py                       |  16 +-
  44 files changed, 215 insertions(+), 283 deletions(-)


diff --git a/Lib/packaging/command/bdist_dumb.py b/Lib/packaging/command/bdist_dumb.py
--- a/Lib/packaging/command/bdist_dumb.py
+++ b/Lib/packaging/command/bdist_dumb.py
@@ -5,9 +5,9 @@
 """
 
 import os
-
 from shutil import rmtree
 from sysconfig import get_python_version
+
 from packaging.util import get_platform
 from packaging.command.cmd import Command
 from packaging.errors import PackagingPlatformError
@@ -24,7 +24,7 @@
                      "platform name to embed in generated filenames "
                      "(default: %s)" % get_platform()),
                     ('format=', 'f',
-                     "archive format to create (tar, gztar, zip)"),
+                     "archive format to create (tar, gztar, bztar, zip)"),
                     ('keep-temp', 'k',
                      "keep the pseudo-installation tree around after " +
                      "creating the distribution archive"),
diff --git a/Lib/packaging/command/build_clib.py b/Lib/packaging/command/build_clib.py
--- a/Lib/packaging/command/build_clib.py
+++ b/Lib/packaging/command/build_clib.py
@@ -16,7 +16,7 @@
 import os
 from packaging.command.cmd import Command
 from packaging.errors import PackagingSetupError
-from packaging.compiler import customize_compiler
+from packaging.compiler import customize_compiler, new_compiler
 from packaging import logger
 
 
@@ -93,7 +93,6 @@
             return
 
         # Yech -- this is cut 'n pasted from build_ext.py!
-        from packaging.compiler import new_compiler
         self.compiler = new_compiler(compiler=self.compiler,
                                      dry_run=self.dry_run,
                                      force=self.force)
diff --git a/Lib/packaging/command/build_ext.py b/Lib/packaging/command/build_ext.py
--- a/Lib/packaging/command/build_ext.py
+++ b/Lib/packaging/command/build_ext.py
@@ -3,6 +3,7 @@
 import os
 import re
 import sys
+import site
 import logging
 import sysconfig
 
@@ -15,9 +16,6 @@
 from packaging.compiler.extension import Extension
 from packaging import logger
 
-import site
-HAS_USER_SITE = True
-
 if os.name == 'nt':
     from packaging.compiler.msvccompiler import get_build_version
     MSVC_VERSION = int(get_build_version())
@@ -62,6 +60,8 @@
         ('inplace', 'i',
          "ignore build-lib and put compiled extensions into the source " +
          "directory alongside your pure Python modules"),
+        ('user', None,
+         "add user include, library and rpath"),
         ('include-dirs=', 'I',
          "list of directories to search for header files" + sep_by),
         ('define=', 'D',
@@ -88,12 +88,8 @@
          "path to the SWIG executable"),
         ]
 
-    boolean_options = ['inplace', 'debug', 'force']
+    boolean_options = ['inplace', 'debug', 'force', 'user']
 
-    if HAS_USER_SITE:
-        user_options.append(('user', None,
-                             "add user include, library and rpath"))
-        boolean_options.append('user')
 
     help_options = [
         ('help-compiler', None,
@@ -120,8 +116,7 @@
         self.compiler = None
         self.swig = None
         self.swig_opts = None
-        if HAS_USER_SITE:
-            self.user = None
+        self.user = None
 
     def finalize_options(self):
         self.set_undefined_options('build',
@@ -270,7 +265,7 @@
             self.swig_opts = self.swig_opts.split(' ')
 
         # Finally add the user include and library directories if requested
-        if HAS_USER_SITE and self.user:
+        if self.user:
             user_include = os.path.join(site.USER_BASE, "include")
             user_lib = os.path.join(site.USER_BASE, "lib")
             if os.path.isdir(user_include):
diff --git a/Lib/packaging/command/build_py.py b/Lib/packaging/command/build_py.py
--- a/Lib/packaging/command/build_py.py
+++ b/Lib/packaging/command/build_py.py
@@ -388,7 +388,7 @@
                 self.build_module(module, module_file, package)
 
     def byte_compile(self, files):
-        if hasattr(sys, 'dont_write_bytecode') and sys.dont_write_bytecode:
+        if sys.dont_write_bytecode:
             logger.warning('%s: byte-compiling is disabled, skipping.',
                            self.get_command_name())
             return
diff --git a/Lib/packaging/command/build_scripts.py b/Lib/packaging/command/build_scripts.py
--- a/Lib/packaging/command/build_scripts.py
+++ b/Lib/packaging/command/build_scripts.py
@@ -3,7 +3,7 @@
 import os
 import re
 import sysconfig
-import tokenize
+from tokenize import detect_encoding
 
 from packaging.command.cmd import Command
 from packaging.util import convert_path, newer
@@ -83,7 +83,7 @@
                     raise
                 f = None
             else:
-                encoding, lines = tokenize.detect_encoding(f.readline)
+                encoding, lines = detect_encoding(f.readline)
                 f.seek(0)
                 first_line = f.readline()
                 if not first_line:
diff --git a/Lib/packaging/command/install_dist.py b/Lib/packaging/command/install_dist.py
--- a/Lib/packaging/command/install_dist.py
+++ b/Lib/packaging/command/install_dist.py
@@ -14,9 +14,6 @@
 from packaging.errors import PackagingOptionError
 
 
-HAS_USER_SITE = True
-
-
 class install_dist(Command):
 
     description = "install everything from build directory"
@@ -27,6 +24,9 @@
          "installation prefix"),
         ('exec-prefix=', None,
          "(Unix only) prefix for platform-specific files"),
+        ('user', None,
+         "install in user site-packages directory [%s]" %
+         get_path('purelib', '%s_user' % os.name)),
         ('home=', None,
          "(Unix only) home directory to install under"),
 
@@ -97,15 +97,7 @@
         ]
 
     boolean_options = ['compile', 'force', 'skip-build', 'no-distinfo',
-                       'requested', 'no-record']
-
-    if HAS_USER_SITE:
-        user_options.append(
-            ('user', None,
-             "install in user site-packages directory [%s]" %
-             get_path('purelib', '%s_user' % os.name)))
-
-        boolean_options.append('user')
+                       'requested', 'no-record', 'user']
 
     negative_opt = {'no-compile': 'compile', 'no-requested': 'requested'}
 
@@ -115,8 +107,7 @@
         self.prefix = None
         self.exec_prefix = None
         self.home = None
-        if HAS_USER_SITE:
-            self.user = False
+        self.user = False
 
         # These select only the installation base; it's up to the user to
         # specify the installation scheme (currently, that means supplying
@@ -135,9 +126,8 @@
         self.install_lib = None         # set to either purelib or platlib
         self.install_scripts = None
         self.install_data = None
-        if HAS_USER_SITE:
-            self.install_userbase = get_config_var('userbase')
-            self.install_usersite = get_path('purelib', '%s_user' % os.name)
+        self.install_userbase = get_config_var('userbase')
+        self.install_usersite = get_path('purelib', '%s_user' % os.name)
 
         self.compile = None
         self.optimize = None
@@ -219,9 +209,8 @@
             raise PackagingOptionError(
                 "must supply either home or prefix/exec-prefix -- not both")
 
-        if HAS_USER_SITE and self.user and (
-                self.prefix or self.exec_prefix or self.home or
-                self.install_base or self.install_platbase):
+        if self.user and (self.prefix or self.exec_prefix or self.home or
+                          self.install_base or self.install_platbase):
             raise PackagingOptionError(
                 "can't combine user with prefix/exec_prefix/home or "
                 "install_base/install_platbase")
@@ -274,11 +263,9 @@
             'exec_prefix': exec_prefix,
             'srcdir': srcdir,
             'projectbase': projectbase,
-            }
-
-        if HAS_USER_SITE:
-            self.config_vars['userbase'] = self.install_userbase
-            self.config_vars['usersite'] = self.install_usersite
+            'userbase': self.install_userbase,
+            'usersite': self.install_usersite,
+        }
 
         self.expand_basedirs()
 
@@ -295,9 +282,9 @@
 
         self.dump_dirs("post-expand_dirs()")
 
-        # Create directories in the home dir:
-        if HAS_USER_SITE and self.user:
-            self.create_home_path()
+        # Create directories under USERBASE
+        if self.user:
+            self.create_user_dirs()
 
         # Pick the actual directory to install all modules to: either
         # install_purelib or install_platlib, depending on whether this
@@ -311,10 +298,8 @@
 
         # Convert directories from Unix /-separated syntax to the local
         # convention.
-        self.convert_paths('lib', 'purelib', 'platlib',
-                           'scripts', 'data', 'headers')
-        if HAS_USER_SITE:
-            self.convert_paths('userbase', 'usersite')
+        self.convert_paths('lib', 'purelib', 'platlib', 'scripts',
+                           'data', 'headers', 'userbase', 'usersite')
 
         # Well, we're not actually fully completely finalized yet: we still
         # have to deal with 'extra_path', which is the hack for allowing
@@ -355,7 +340,7 @@
                     "installation scheme is incomplete")
             return
 
-        if HAS_USER_SITE and self.user:
+        if self.user:
             if self.install_userbase is None:
                 raise PackagingPlatformError(
                     "user base directory is not specified")
@@ -383,7 +368,7 @@
 
     def finalize_other(self):
         """Finalize options for non-posix platforms"""
-        if HAS_USER_SITE and self.user:
+        if self.user:
             if self.install_userbase is None:
                 raise PackagingPlatformError(
                     "user base directory is not specified")
@@ -494,10 +479,8 @@
             attr = "install_" + name
             setattr(self, attr, change_root(self.root, getattr(self, attr)))
 
-    def create_home_path(self):
-        """Create directories under ~."""
-        if HAS_USER_SITE and not self.user:
-            return
+    def create_user_dirs(self):
+        """Create directories under USERBASE as needed."""
         home = convert_path(os.path.expanduser("~"))
         for name, path in self.config_vars.items():
             if path.startswith(home) and not os.path.isdir(path):
diff --git a/Lib/packaging/command/install_distinfo.py b/Lib/packaging/command/install_distinfo.py
--- a/Lib/packaging/command/install_distinfo.py
+++ b/Lib/packaging/command/install_distinfo.py
@@ -2,14 +2,13 @@
 
 # Forked from the former install_egg_info command by Josip Djolonga
 
+import os
 import csv
-import os
-import re
 import hashlib
+from shutil import rmtree
 
+from packaging import logger
 from packaging.command.cmd import Command
-from packaging import logger
-from shutil import rmtree
 
 
 class install_distinfo(Command):
@@ -28,7 +27,7 @@
         ('no-record', None,
          "do not generate a RECORD file"),
         ('no-resources', None,
-         "do not generate a RESSOURCES list installed file"),
+         "do not generate a RESOURCES file"),
     ]
 
     boolean_options = ['requested', 'no-record', 'no-resources']
diff --git a/Lib/packaging/command/install_lib.py b/Lib/packaging/command/install_lib.py
--- a/Lib/packaging/command/install_lib.py
+++ b/Lib/packaging/command/install_lib.py
@@ -114,7 +114,7 @@
         return outfiles
 
     def byte_compile(self, files):
-        if getattr(sys, 'dont_write_bytecode'):
+        if sys.dont_write_bytecode:
             # XXX do we want this?  because a Python runs without bytecode
             # doesn't mean that the *dists should not contain bytecode
             #--or does it?
diff --git a/Lib/packaging/command/upload_docs.py b/Lib/packaging/command/upload_docs.py
--- a/Lib/packaging/command/upload_docs.py
+++ b/Lib/packaging/command/upload_docs.py
@@ -87,6 +87,7 @@
         content_type, body = encode_multipart(fields, files)
 
         credentials = self.username + ':' + self.password
+        # FIXME should use explicit encoding
         auth = b"Basic " + base64.encodebytes(credentials.encode()).strip()
 
         logger.info("Submitting documentation to %s", self.repository)
diff --git a/Lib/packaging/compat.py b/Lib/packaging/compat.py
--- a/Lib/packaging/compat.py
+++ b/Lib/packaging/compat.py
@@ -1,8 +1,4 @@
-"""Compatibility helpers.
-
-This module provides classes, variables and imports which are used to
-support packaging across Python 2.x and 3.x.
-"""
+"""Compatibility helpers."""
 
 from packaging import logger
 
@@ -10,8 +6,6 @@
 # XXX Having two classes with the same name is not a good thing.
 # XXX 2to3-related code should move from util to this module
 
-# TODO Move common code here: PY3 (bool indicating if we're on 3.x), any, etc.
-
 try:
     from packaging.util import Mixin2to3 as _Mixin2to3
     _CONVERT = True
diff --git a/Lib/packaging/compiler/bcppcompiler.py b/Lib/packaging/compiler/bcppcompiler.py
--- a/Lib/packaging/compiler/bcppcompiler.py
+++ b/Lib/packaging/compiler/bcppcompiler.py
@@ -352,5 +352,4 @@
             try:
                 self.spawn(pp_args)
             except PackagingExecError as msg:
-                print(msg)
                 raise CompileError(msg)
diff --git a/Lib/packaging/compiler/ccompiler.py b/Lib/packaging/compiler/ccompiler.py
--- a/Lib/packaging/compiler/ccompiler.py
+++ b/Lib/packaging/compiler/ccompiler.py
@@ -5,7 +5,6 @@
 """
 
 import os
-import sys
 from shutil import move
 from packaging import logger
 from packaging.util import split_quoted, execute, newer_group, spawn
diff --git a/Lib/packaging/compiler/unixccompiler.py b/Lib/packaging/compiler/unixccompiler.py
--- a/Lib/packaging/compiler/unixccompiler.py
+++ b/Lib/packaging/compiler/unixccompiler.py
@@ -127,7 +127,7 @@
         executables['ranlib'] = ["ranlib"]
 
     # Needed for the filename generation methods provided by the base
-    # class, CCompiler.  NB. whoever instantiates/uses a particular
+    # class, CCompiler.  XXX whoever instantiates/uses a particular
     # UnixCCompiler instance should set 'shared_lib_ext' -- we set a
     # reasonable common default here, but it's not necessarily used on all
     # Unices!
diff --git a/Lib/packaging/create.py b/Lib/packaging/create.py
--- a/Lib/packaging/create.py
+++ b/Lib/packaging/create.py
@@ -25,11 +25,11 @@
 import glob
 import shutil
 import sysconfig
-import tokenize
 from hashlib import md5
 from textwrap import dedent
-from functools import cmp_to_key
+from tokenize import detect_encoding
 from configparser import RawConfigParser
+
 # importing this with an underscore as it should be replaced by the
 # dict form or another structures for all purposes
 from packaging._trove import all_classifiers as _CLASSIFIERS_LIST
@@ -112,7 +112,7 @@
     been loaded before, because we are monkey patching its setup function with
     a particular one"""
     with open("setup.py", "rb") as f:
-        encoding, lines = tokenize.detect_encoding(f.readline)
+        encoding, lines = detect_encoding(f.readline)
     with open("setup.py", encoding=encoding) as f:
         imp.load_module("setup", f, "setup.py", (".py", "r", imp.PY_SOURCE))
 
@@ -370,21 +370,9 @@
                     dist.data_files = [('', dist.data_files)]
                 # add tokens in the destination paths
                 vars = {'distribution.name': data['name']}
-                path_tokens = list(sysconfig.get_paths(vars=vars).items())
-
-                # TODO replace this with a key function
-                def length_comparison(x, y):
-                    len_x = len(x[1])
-                    len_y = len(y[1])
-                    if len_x == len_y:
-                        return 0
-                    elif len_x < len_y:
-                        return -1
-                    else:
-                        return 1
-
+                path_tokens = sysconfig.get_paths(vars=vars).items()
                 # sort tokens to use the longest one first
-                path_tokens.sort(key=cmp_to_key(length_comparison))
+                path_tokens = sorted(path_tokens, key=lambda x: len(x[1]))
                 for dest, srcs in (dist.data_files or []):
                     dest = os.path.join(sys.prefix, dest)
                     dest = dest.replace(os.path.sep, '/')
diff --git a/Lib/packaging/database.py b/Lib/packaging/database.py
--- a/Lib/packaging/database.py
+++ b/Lib/packaging/database.py
@@ -1,12 +1,13 @@
 """PEP 376 implementation."""
 
-import io
 import os
 import re
 import csv
 import sys
 import zipimport
+from io import StringIO
 from hashlib import md5
+
 from packaging import logger
 from packaging.errors import PackagingError
 from packaging.version import suggest_normalized_version, VersionPredicate
@@ -173,7 +174,7 @@
     def get_resource_path(self, relative_path):
         with self.get_distinfo_file('RESOURCES') as resources_file:
             resources_reader = csv.reader(resources_file, delimiter=',',
-                                           lineterminator='\n')
+                                          lineterminator='\n')
             for relative, destination in resources_reader:
                 if relative == relative_path:
                     return destination
@@ -334,7 +335,7 @@
             else:
                 # FIXME handle the case where zipfile is not available
                 zipf = zipimport.zipimporter(path)
-                fileobj = io.StringIO(
+                fileobj = StringIO(
                     zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
                 self.metadata = Metadata(fileobj=fileobj)
                 try:
diff --git a/Lib/packaging/dist.py b/Lib/packaging/dist.py
--- a/Lib/packaging/dist.py
+++ b/Lib/packaging/dist.py
@@ -537,7 +537,7 @@
     def _get_command_groups(self):
         """Helper function to retrieve all the command class names divided
         into standard commands (listed in
-        packaging2.command.STANDARD_COMMANDS) and extra commands (given in
+        packaging.command.STANDARD_COMMANDS) and extra commands (given in
         self.cmdclass and not standard commands).
         """
         extra_commands = [cmd for cmd in self.cmdclass
@@ -547,7 +547,7 @@
     def print_commands(self):
         """Print out a help message listing all available commands with a
         description of each.  The list is divided into standard commands
-        (listed in packaging2.command.STANDARD_COMMANDS) and extra commands
+        (listed in packaging.command.STANDARD_COMMANDS) and extra commands
         (given in self.cmdclass and not standard commands).  The
         descriptions come from the command class attribute
         'description'.
diff --git a/Lib/packaging/metadata.py b/Lib/packaging/metadata.py
--- a/Lib/packaging/metadata.py
+++ b/Lib/packaging/metadata.py
@@ -552,16 +552,17 @@
         return data
 
     # Mapping API
+    # XXX these methods should return views or sets in 3.x
 
     def keys(self):
-        return _version2fieldlist(self['Metadata-Version'])
+        return list(_version2fieldlist(self['Metadata-Version']))
 
     def __iter__(self):
         for key in self.keys():
             yield key
 
     def values(self):
-        return [self[key] for key in list(self.keys())]
+        return [self[key] for key in self.keys()]
 
     def items(self):
-        return [(key, self[key]) for key in list(self.keys())]
+        return [(key, self[key]) for key in self.keys()]
diff --git a/Lib/packaging/pypi/simple.py b/Lib/packaging/pypi/simple.py
--- a/Lib/packaging/pypi/simple.py
+++ b/Lib/packaging/pypi/simple.py
@@ -23,12 +23,11 @@
 from packaging import __version__ as packaging_version
 from packaging.pypi.base import BaseClient
 from packaging.pypi.dist import (ReleasesList, EXTENSIONS,
-                                  get_infos_from_url, MD5_HASH)
+                                 get_infos_from_url, MD5_HASH)
 from packaging.pypi.errors import (PackagingPyPIError, DownloadError,
-                                    UnableToDownload, CantParseArchiveName,
-                                    ReleaseNotFound, ProjectNotFound)
+                                   UnableToDownload, CantParseArchiveName,
+                                   ReleaseNotFound, ProjectNotFound)
 from packaging.pypi.mirrors import get_mirrors
-from packaging.metadata import Metadata
 
 __all__ = ['Crawler', 'DEFAULT_SIMPLE_INDEX_URL']
 
diff --git a/Lib/packaging/tests/__init__.py b/Lib/packaging/tests/__init__.py
--- a/Lib/packaging/tests/__init__.py
+++ b/Lib/packaging/tests/__init__.py
@@ -6,17 +6,15 @@
 to return an initialized unittest.TestSuite instance.
 
 Utility code is included in packaging.tests.support.
+
+Always import unittest from this module: it will be unittest from the
+standard library for packaging tests and unittest2 for distutils2 tests.
 """
 
-# Put this text back for the backport
-#Always import unittest from this module, it will be the right version
-#(standard library unittest for 3.2 and higher, third-party unittest2
-#elease for older versions).
-
 import os
 import sys
 import unittest
-from test.support import TESTFN
+from io import StringIO
 
 # XXX move helpers to support, add tests for them, remove things that
 # duplicate test.support (or keep them for the backport; needs thinking)
@@ -115,9 +113,8 @@
 
 
 def captured_stdout(func, *args, **kw):
-    import io
     orig_stdout = getattr(sys, 'stdout')
-    setattr(sys, 'stdout', io.StringIO())
+    setattr(sys, 'stdout', StringIO())
     try:
         res = func(*args, **kw)
         sys.stdout.seek(0)
diff --git a/Lib/packaging/tests/__main__.py b/Lib/packaging/tests/__main__.py
--- a/Lib/packaging/tests/__main__.py
+++ b/Lib/packaging/tests/__main__.py
@@ -14,6 +14,8 @@
         start_dir = os.path.dirname(__file__)
         top_dir = os.path.dirname(os.path.dirname(start_dir))
         test_loader = unittest.TestLoader()
+        # XXX find out how to use unittest.main, to get command-line options
+        # (failfast, catch, etc.)
         run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
     finally:
         reap_children()
diff --git a/Lib/packaging/tests/pypi_server.py b/Lib/packaging/tests/pypi_server.py
--- a/Lib/packaging/tests/pypi_server.py
+++ b/Lib/packaging/tests/pypi_server.py
@@ -40,6 +40,7 @@
 
 from packaging.tests import unittest
 
+
 PYPI_DEFAULT_STATIC_PATH = os.path.join(
     os.path.dirname(os.path.abspath(__file__)), 'pypiserver')
 
@@ -219,7 +220,7 @@
                         relative_path += "index.html"
 
                     if relative_path.endswith('.tar.gz'):
-                        with open(fs_path + relative_path, 'br') as file:
+                        with open(fs_path + relative_path, 'rb') as file:
                             data = file.read()
                         headers = [('Content-type', 'application/x-gtar')]
                     else:
@@ -260,8 +261,8 @@
             self.send_header(header, value)
         self.end_headers()
 
-        if type(data) is str:
-            data = data.encode()
+        if isinstance(data, str):
+            data = data.encode('utf-8')
 
         self.wfile.write(data)
 
diff --git a/Lib/packaging/tests/test_command_bdist_dumb.py b/Lib/packaging/tests/test_command_bdist_dumb.py
--- a/Lib/packaging/tests/test_command_bdist_dumb.py
+++ b/Lib/packaging/tests/test_command_bdist_dumb.py
@@ -35,7 +35,7 @@
 
         dist = Distribution({'name': 'foo', 'version': '0.1',
                              'py_modules': ['foo'],
-                             'home-page': 'xxx', 'author': 'xxx',
+                             'home_page': 'xxx', 'author': 'xxx',
                              'author_email': 'xxx'})
         os.chdir(pkg_dir)
         cmd = bdist_dumb(dist)
diff --git a/Lib/packaging/tests/test_command_build_ext.py b/Lib/packaging/tests/test_command_build_ext.py
--- a/Lib/packaging/tests/test_command_build_ext.py
+++ b/Lib/packaging/tests/test_command_build_ext.py
@@ -9,8 +9,8 @@
                               PackagingPlatformError)
 from packaging.command.build_ext import build_ext
 from packaging.compiler.extension import Extension
+
 from test.script_helper import assert_python_ok
-
 from packaging.tests import support, unittest, verbose
 
 
@@ -18,18 +18,13 @@
                        support.LoggingCatcher,
                        unittest.TestCase):
     def setUp(self):
-        # Create a simple test environment
-        # Note that we're making changes to sys.path
         super(BuildExtTestCase, self).setUp()
         self.tmp_dir = self.mkdtemp()
         self.old_user_base = site.USER_BASE
         site.USER_BASE = self.mkdtemp()
 
     def tearDown(self):
-        # Get everything back to normal
-        if sys.version > "2.6":
-            site.USER_BASE = self.old_user_base
-
+        site.USER_BASE = self.old_user_base
         super(BuildExtTestCase, self).tearDown()
 
     def test_build_ext(self):
@@ -78,23 +73,21 @@
         old = sys.platform
 
         sys.platform = 'sunos'  # fooling finalize_options
-        from sysconfig import _CONFIG_VARS
 
-        old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
-        _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
+        old_var = sysconfig.get_config_var('Py_ENABLE_SHARED')
+        sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = 1
         try:
             cmd.ensure_finalized()
         finally:
             sys.platform = old
             if old_var is None:
-                del _CONFIG_VARS['Py_ENABLE_SHARED']
+                del sysconfig._CONFIG_VARS['Py_ENABLE_SHARED']
             else:
-                _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
+                sysconfig._CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
 
         # make sure we get some library dirs under solaris
         self.assertGreater(len(cmd.library_dirs), 0)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_user_site(self):
         dist = Distribution({'name': 'xx'})
         cmd = build_ext(dist)
diff --git a/Lib/packaging/tests/test_command_build_py.py b/Lib/packaging/tests/test_command_build_py.py
--- a/Lib/packaging/tests/test_command_build_py.py
+++ b/Lib/packaging/tests/test_command_build_py.py
@@ -99,8 +99,6 @@
             os.chdir(cwd)
             sys.stdout = old_stdout
 
-    @unittest.skipUnless(hasattr(sys, 'dont_write_bytecode'),
-                         'sys.dont_write_bytecode not supported')
     def test_dont_write_bytecode(self):
         # makes sure byte_compile is not used
         pkg_dir, dist = self.create_dist()
diff --git a/Lib/packaging/tests/test_command_install_dist.py b/Lib/packaging/tests/test_command_install_dist.py
--- a/Lib/packaging/tests/test_command_install_dist.py
+++ b/Lib/packaging/tests/test_command_install_dist.py
@@ -72,7 +72,6 @@
         check_path(cmd.install_scripts, os.path.join(destination, "bin"))
         check_path(cmd.install_data, destination)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_user_site(self):
         # test install with --user
         # preparing the environment for the test
@@ -173,12 +172,11 @@
         cmd.home = 'home'
         self.assertRaises(PackagingOptionError, cmd.finalize_options)
 
-        if sys.version >= '2.6':
-            # can't combine user with with prefix/exec_prefix/home or
-            # install_(plat)base
-            cmd.prefix = None
-            cmd.user = 'user'
-            self.assertRaises(PackagingOptionError, cmd.finalize_options)
+        # can't combine user with with prefix/exec_prefix/home or
+        # install_(plat)base
+        cmd.prefix = None
+        cmd.user = 'user'
+        self.assertRaises(PackagingOptionError, cmd.finalize_options)
 
     def test_old_record(self):
         # test pre-PEP 376 --record option (outside dist-info dir)
diff --git a/Lib/packaging/tests/test_command_install_lib.py b/Lib/packaging/tests/test_command_install_lib.py
--- a/Lib/packaging/tests/test_command_install_lib.py
+++ b/Lib/packaging/tests/test_command_install_lib.py
@@ -7,13 +7,6 @@
 from packaging.compiler.extension import Extension
 from packaging.errors import PackagingOptionError
 
-try:
-    no_bytecode = sys.dont_write_bytecode
-    bytecode_support = True
-except AttributeError:
-    no_bytecode = False
-    bytecode_support = False
-
 
 class InstallLibTestCase(support.TempdirManager,
                          support.LoggingCatcher,
@@ -40,7 +33,7 @@
         cmd.finalize_options()
         self.assertEqual(cmd.optimize, 2)
 
-    @unittest.skipIf(no_bytecode, 'byte-compile not supported')
+    @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile disabled')
     def test_byte_compile(self):
         pkg_dir, dist = self.create_dist()
         cmd = install_lib(dist)
@@ -89,8 +82,6 @@
         # get_input should return 2 elements
         self.assertEqual(len(cmd.get_inputs()), 2)
 
-    @unittest.skipUnless(bytecode_support,
-                         'sys.dont_write_bytecode not supported')
     def test_dont_write_bytecode(self):
         # makes sure byte_compile is not used
         pkg_dir, dist = self.create_dist()
diff --git a/Lib/packaging/tests/test_command_register.py b/Lib/packaging/tests/test_command_register.py
--- a/Lib/packaging/tests/test_command_register.py
+++ b/Lib/packaging/tests/test_command_register.py
@@ -99,7 +99,7 @@
 
     def _get_cmd(self, metadata=None):
         if metadata is None:
-            metadata = {'home-page': 'xxx', 'author': 'xxx',
+            metadata = {'home_page': 'xxx', 'author': 'xxx',
                         'author_email': 'xxx',
                         'name': 'xxx', 'version': 'xxx'}
         pkg_info, dist = self.create_dist(**metadata)
diff --git a/Lib/packaging/tests/test_command_upload.py b/Lib/packaging/tests/test_command_upload.py
--- a/Lib/packaging/tests/test_command_upload.py
+++ b/Lib/packaging/tests/test_command_upload.py
@@ -1,6 +1,5 @@
 """Tests for packaging.command.upload."""
 import os
-import sys
 
 from packaging.command.upload import upload
 from packaging.dist import Distribution
@@ -103,22 +102,23 @@
         command, pyversion, filename = 'xxx', '3.3', path
         dist_files = [(command, pyversion, filename)]
 
-        # lets run it
-        pkg_dir, dist = self.create_dist(dist_files=dist_files, author='dédé')
+        # let's run it
+        dist = self.create_dist(dist_files=dist_files, author='dédé')[1]
         cmd = upload(dist)
         cmd.ensure_finalized()
         cmd.repository = self.pypi.full_address
         cmd.run()
 
-        # what did we send ?
+        # what did we send?
         handler, request_data = self.pypi.requests[-1]
         headers = handler.headers
-        #self.assertIn('dédé', str(request_data))
+        self.assertIn('dédé'.encode('utf-8'), request_data)
         self.assertIn(b'xxx', request_data)
 
         self.assertEqual(int(headers['content-length']), len(request_data))
         self.assertLess(int(headers['content-length']), 2500)
-        self.assertTrue(headers['content-type'].startswith('multipart/form-data'))
+        self.assertTrue(headers['content-type'].startswith(
+            'multipart/form-data'))
         self.assertEqual(handler.command, 'POST')
         self.assertNotIn('\n', headers['authorization'])
 
@@ -132,20 +132,16 @@
         self.write_file(os.path.join(docs_path, "index.html"), "yellow")
         self.write_file(self.rc, PYPIRC)
 
-        # lets run it
-        pkg_dir, dist = self.create_dist(dist_files=dist_files, author='dédé')
+        # let's run it
+        dist = self.create_dist(dist_files=dist_files, author='dédé')[1]
 
         cmd = upload(dist)
         cmd.get_finalized_command("build").run()
         cmd.upload_docs = True
         cmd.ensure_finalized()
         cmd.repository = self.pypi.full_address
-        prev_dir = os.getcwd()
-        try:
-            os.chdir(self.tmp_dir)
-            cmd.run()
-        finally:
-            os.chdir(prev_dir)
+        os.chdir(self.tmp_dir)
+        cmd.run()
 
         handler, request_data = self.pypi.requests[-1]
         action, name, content = request_data.split(
diff --git a/Lib/packaging/tests/test_command_upload_docs.py b/Lib/packaging/tests/test_command_upload_docs.py
--- a/Lib/packaging/tests/test_command_upload_docs.py
+++ b/Lib/packaging/tests/test_command_upload_docs.py
@@ -1,6 +1,5 @@
 """Tests for packaging.command.upload_docs."""
 import os
-import sys
 import shutil
 import zipfile
 try:
@@ -19,7 +18,7 @@
     from packaging.tests.pypi_server import PyPIServerTestCase
 except ImportError:
     threading = None
-    PyPIServerTestCase = object
+    PyPIServerTestCase = unittest.TestCase
 
 
 PYPIRC = """\
@@ -52,34 +51,27 @@
 
     def test_default_uploaddir(self):
         sandbox = self.mkdtemp()
-        previous = os.getcwd()
         os.chdir(sandbox)
-        try:
-            os.mkdir("build")
-            self.prepare_sample_dir("build")
-            self.cmd.ensure_finalized()
-            self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
-        finally:
-            os.chdir(previous)
+        os.mkdir("build")
+        self.prepare_sample_dir("build")
+        self.cmd.ensure_finalized()
+        self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
 
     def test_default_uploaddir_looks_for_doc_also(self):
         sandbox = self.mkdtemp()
-        previous = os.getcwd()
         os.chdir(sandbox)
-        try:
-            os.mkdir("build")
-            self.prepare_sample_dir("build")
-            os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
-            self.cmd.ensure_finalized()
-            self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
-        finally:
-            os.chdir(previous)
+        os.mkdir("build")
+        self.prepare_sample_dir("build")
+        os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
+        self.cmd.ensure_finalized()
+        self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
 
     def prepare_sample_dir(self, sample_dir=None):
         if sample_dir is None:
             sample_dir = self.mkdtemp()
         os.mkdir(os.path.join(sample_dir, "docs"))
-        self.write_file(os.path.join(sample_dir, "docs", "index.html"), "Ce mortel ennui")
+        self.write_file(os.path.join(sample_dir, "docs", "index.html"),
+                        "Ce mortel ennui")
         self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la")
         return sample_dir
 
@@ -108,9 +100,8 @@
         self.assertTrue(handler.headers['content-type']
             .startswith('multipart/form-data;'))
 
-        action, name, version, content =\
-            request_data.split("----------------GHSKFJDLGDS7543FJKLFHRE75642756743254".encode())[1:5]
-
+        action, name, version, content = request_data.split(
+            b'----------------GHSKFJDLGDS7543FJKLFHRE75642756743254')[1:5]
 
         # check that we picked the right chunks
         self.assertIn(b'name=":action"', action)
@@ -126,27 +117,25 @@
 
     @unittest.skipIf(_ssl is None, 'Needs SSL support')
     def test_https_connection(self):
-        https_called = False
-
-        orig_https = upload_docs_mod.http.client.HTTPSConnection
+        self.https_called = False
+        self.addCleanup(
+            setattr, upload_docs_mod.http.client, 'HTTPSConnection',
+            upload_docs_mod.http.client.HTTPSConnection)
 
         def https_conn_wrapper(*args):
-            nonlocal https_called
-            https_called = True
+            self.https_called = True
             # the testing server is http
             return upload_docs_mod.http.client.HTTPConnection(*args)
 
         upload_docs_mod.http.client.HTTPSConnection = https_conn_wrapper
-        try:
-            self.prepare_command()
-            self.cmd.run()
-            self.assertFalse(https_called)
 
-            self.cmd.repository = self.cmd.repository.replace("http", "https")
-            self.cmd.run()
-            self.assertTrue(https_called)
-        finally:
-            upload_docs_mod.http.client.HTTPSConnection = orig_https
+        self.prepare_command()
+        self.cmd.run()
+        self.assertFalse(self.https_called)
+
+        self.cmd.repository = self.cmd.repository.replace("http", "https")
+        self.cmd.run()
+        self.assertTrue(self.https_called)
 
     def test_handling_response(self):
         self.pypi.default_response_status = '403 Forbidden'
@@ -155,7 +144,8 @@
         self.assertIn('Upload failed (403): Forbidden', self.get_logs()[-1])
 
         self.pypi.default_response_status = '301 Moved Permanently'
-        self.pypi.default_response_headers.append(("Location", "brand_new_location"))
+        self.pypi.default_response_headers.append(
+            ("Location", "brand_new_location"))
         self.cmd.run()
         self.assertIn('brand_new_location', self.get_logs()[-1])
 
@@ -185,6 +175,7 @@
         self.assertTrue(record, "should report the response")
         self.assertIn(self.pypi.default_response_data, record)
 
+
 def test_suite():
     return unittest.makeSuite(UploadDocsTestCase)
 
diff --git a/Lib/packaging/tests/test_create.py b/Lib/packaging/tests/test_create.py
--- a/Lib/packaging/tests/test_create.py
+++ b/Lib/packaging/tests/test_create.py
@@ -1,8 +1,8 @@
 """Tests for packaging.create."""
-import io
 import os
 import sys
 import sysconfig
+from io import StringIO
 from textwrap import dedent
 from packaging.create import MainProgram, ask_yn, ask, main
 
@@ -20,8 +20,8 @@
         super(CreateTestCase, self).setUp()
         self._stdin = sys.stdin  # TODO use Inputs
         self._stdout = sys.stdout
-        sys.stdin = io.StringIO()
-        sys.stdout = io.StringIO()
+        sys.stdin = StringIO()
+        sys.stdout = StringIO()
         self._cwd = os.getcwd()
         self.wdir = self.mkdtemp()
         os.chdir(self.wdir)
@@ -135,7 +135,8 @@
         sys.stdin.seek(0)
         main()
 
-        with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
+        path = os.path.join(self.wdir, 'setup.cfg')
+        with open(path, encoding='utf-8') as fp:
             contents = fp.read()
 
         self.assertEqual(contents, dedent("""\
@@ -210,7 +211,9 @@
         sys.stdin.seek(0)
         # FIXME Out of memory error.
         main()
-        with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
+
+        path = os.path.join(self.wdir, 'setup.cfg')
+        with open(path, encoding='utf-8') as fp:
             contents = fp.read()
 
         self.assertEqual(contents, dedent("""\
diff --git a/Lib/packaging/tests/test_database.py b/Lib/packaging/tests/test_database.py
--- a/Lib/packaging/tests/test_database.py
+++ b/Lib/packaging/tests/test_database.py
@@ -49,8 +49,8 @@
         # distributions
         tmpdir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, tmpdir)
-        self.fake_dists_path = os.path.join(tmpdir, 'fake_dists')
-        self.fake_dists_path = os.path.realpath(self.fake_dists_path)
+        self.fake_dists_path = os.path.realpath(
+            os.path.join(tmpdir, 'fake_dists'))
         fake_dists_src = os.path.abspath(
             os.path.join(os.path.dirname(__file__), 'fake_dists'))
         shutil.copytree(fake_dists_src, self.fake_dists_path)
@@ -58,6 +58,7 @@
         # back (to avoid getting a read-only copy of a read-only file).  we
         # could pass a custom copy_function to change the mode of files, but
         # shutil gives no control over the mode of directories :(
+        # see http://bugs.python.org/issue1666318
         for root, dirs, files in os.walk(self.fake_dists_path):
             os.chmod(root, 0o755)
             for f in files:
diff --git a/Lib/packaging/tests/test_depgraph.py b/Lib/packaging/tests/test_depgraph.py
--- a/Lib/packaging/tests/test_depgraph.py
+++ b/Lib/packaging/tests/test_depgraph.py
@@ -1,10 +1,11 @@
 """Tests for packaging.depgraph """
-import io
 import os
 import re
 import sys
-import packaging.database
+from io import StringIO
+
 from packaging import depgraph
+from packaging.database import get_distribution, enable_cache, disable_cache
 
 from packaging.tests import unittest, support
 from packaging.tests.support import requires_zlib
@@ -30,13 +31,13 @@
         path = os.path.abspath(path)
         sys.path.insert(0, path)
         self.addCleanup(sys.path.remove, path)
-        self.addCleanup(packaging.database.enable_cache)
-        packaging.database.disable_cache()
+        self.addCleanup(enable_cache)
+        disable_cache()
 
     def test_generate_graph(self):
         dists = []
         for name in self.DISTROS_DIST:
-            dist = packaging.database.get_distribution(name)
+            dist = get_distribution(name)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -61,7 +62,7 @@
     def test_generate_graph_egg(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -104,7 +105,7 @@
     def test_dependent_dists(self):
         dists = []
         for name in self.DISTROS_DIST:
-            dist = packaging.database.get_distribution(name)
+            dist = get_distribution(name)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -123,7 +124,7 @@
     def test_dependent_dists_egg(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -158,12 +159,12 @@
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf)
         buf.seek(0)
         matches = []
@@ -189,12 +190,12 @@
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf, skip_disconnected=False)
         buf.seek(0)
         lines = buf.readlines()
@@ -250,12 +251,12 @@
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf)
         buf.seek(0)
         matches = []
@@ -273,7 +274,7 @@
     def test_repr(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -282,7 +283,7 @@
 
     @requires_zlib
     def test_main(self):
-        tempout = io.StringIO()
+        tempout = StringIO()
         old = sys.stdout
         sys.stdout = tempout
         oldargv = sys.argv[:]
diff --git a/Lib/packaging/tests/test_dist.py b/Lib/packaging/tests/test_dist.py
--- a/Lib/packaging/tests/test_dist.py
+++ b/Lib/packaging/tests/test_dist.py
@@ -3,13 +3,14 @@
 import sys
 import logging
 import textwrap
+
 import packaging.dist
 
 from packaging.dist import Distribution
 from packaging.command import set_command
 from packaging.command.cmd import Command
 from packaging.errors import PackagingModuleError, PackagingOptionError
-from packaging.tests import TESTFN, captured_stdout
+from packaging.tests import captured_stdout
 from packaging.tests import support, unittest
 from packaging.tests.support import create_distribution
 from test.support import unload
@@ -48,12 +49,13 @@
 
     @unittest.skip('needs to be updated')
     def test_debug_mode(self):
-        self.addCleanup(os.unlink, TESTFN)
-        with open(TESTFN, "w") as f:
+        tmpdir = self.mkdtemp()
+        setupcfg = os.path.join(tmpdir, 'setup.cfg')
+        with open(setupcfg, "w") as f:
             f.write("[global]\n")
             f.write("command_packages = foo.bar, splat")
 
-        files = [TESTFN]
+        files = [setupcfg]
         sys.argv.append("build")
         __, stdout = captured_stdout(create_distribution, files)
         self.assertEqual(stdout, '')
@@ -70,7 +72,7 @@
         Distribution(attrs={'author': 'xxx',
                             'name': 'xxx',
                             'version': '1.2',
-                            'home-page': 'xxxx',
+                            'home_page': 'xxxx',
                             'badoptname': 'xxx'})
         logs = self.get_logs(logging.WARNING)
         self.assertEqual(len(logs), 1)
@@ -80,7 +82,7 @@
         # an empty options dictionary should not stay in the
         # list of attributes
         dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx',
-                                   'version': '1.2', 'home-page': 'xxxx',
+                                   'version': '1.2', 'home_page': 'xxxx',
                                    'options': {}})
 
         self.assertEqual([], self.get_logs(logging.WARNING))
@@ -97,7 +99,7 @@
         dist = Distribution(attrs={'author': 'xxx',
                                    'name': 'xxx',
                                    'version': 'xxx',
-                                   'home-page': 'xxxx',
+                                   'home_page': 'xxxx',
                                    'options': {'sdist': {'owner': 'root'}}})
 
         self.assertIn('owner', dist.get_option_dict('sdist'))
diff --git a/Lib/packaging/tests/test_install.py b/Lib/packaging/tests/test_install.py
--- a/Lib/packaging/tests/test_install.py
+++ b/Lib/packaging/tests/test_install.py
@@ -1,8 +1,8 @@
 """Tests for the packaging.install module."""
 import os
 import logging
+from tempfile import mkstemp
 from sysconfig import is_python_build
-from tempfile import mkstemp
 
 from packaging import install
 from packaging.pypi.xmlrpc import Client
diff --git a/Lib/packaging/tests/test_metadata.py b/Lib/packaging/tests/test_metadata.py
--- a/Lib/packaging/tests/test_metadata.py
+++ b/Lib/packaging/tests/test_metadata.py
@@ -101,7 +101,7 @@
 
         # XXX caveat: the keys method and friends are not 3.x-style views
         # should be changed or documented
-        self.assertEqual(list(metadata), list(metadata.keys()))
+        self.assertEqual(list(metadata), metadata.keys())
 
     def test_read_metadata(self):
         fields = {'name': 'project',
@@ -301,7 +301,7 @@
         Metadata(mapping={'author': 'xxx',
                           'name': 'xxx',
                           'version': 'xxx',
-                          'home-page': 'xxxx'})
+                          'home_page': 'xxxx'})
         logs = self.get_logs(logging.WARNING)
         self.assertEqual(1, len(logs))
         self.assertIn('not a valid version', logs[0])
diff --git a/Lib/packaging/tests/test_mixin2to3.py b/Lib/packaging/tests/test_mixin2to3.py
--- a/Lib/packaging/tests/test_mixin2to3.py
+++ b/Lib/packaging/tests/test_mixin2to3.py
@@ -9,7 +9,6 @@
                         support.LoggingCatcher,
                         unittest.TestCase):
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_convert_code_only(self):
         # used to check if code gets converted properly.
         code = "print 'test'"
@@ -26,7 +25,6 @@
 
         self.assertEqual(expected, converted)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_doctests_only(self):
         # used to check if doctests gets converted properly.
         doctest = textwrap.dedent('''\
@@ -57,7 +55,6 @@
 
         self.assertEqual(expected, converted)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_additional_fixers(self):
         # used to check if use_2to3_fixers works
         code = 'type(x) is not T'
diff --git a/Lib/packaging/tests/test_pypi_server.py b/Lib/packaging/tests/test_pypi_server.py
--- a/Lib/packaging/tests/test_pypi_server.py
+++ b/Lib/packaging/tests/test_pypi_server.py
@@ -1,13 +1,12 @@
 """Tests for packaging.command.bdist."""
-import sys
-
 import urllib.request
 import urllib.parse
 import urllib.error
 
 try:
     import threading
-    from packaging.tests.pypi_server import PyPIServer, PYPI_DEFAULT_STATIC_PATH
+    from packaging.tests.pypi_server import (
+        PyPIServer, PYPI_DEFAULT_STATIC_PATH)
 except ImportError:
     threading = None
     PyPIServer = None
@@ -32,18 +31,19 @@
 
             headers = {"X-test-header": "Mister Iceberg"}
 
-            request = urllib.request.Request(server.full_address, data, headers)
+            request = urllib.request.Request(
+                server.full_address, data, headers)
             urllib.request.urlopen(request)
             self.assertEqual(len(server.requests), 1)
             handler, request_data = server.requests[-1]
             self.assertIn(data, request_data)
             self.assertIn("x-test-header", handler.headers)
-            self.assertEqual(handler.headers["x-test-header"], "Mister Iceberg")
+            self.assertEqual(handler.headers["x-test-header"],
+                             "Mister Iceberg")
 
         finally:
             server.stop()
 
-
     def test_serve_static_content(self):
         # PYPI Mocked server can serve static content from disk.
 
@@ -74,7 +74,8 @@
             self.assertTrue(uses_local_files_for(server, "/simple/index.html"))
 
             # and another one in another root path
-            self.assertTrue(uses_local_files_for(server, "/external/index.html"))
+            self.assertTrue(uses_local_files_for(server,
+                                                 "/external/index.html"))
 
         finally:
             server.stop()
diff --git a/Lib/packaging/tests/test_run.py b/Lib/packaging/tests/test_run.py
--- a/Lib/packaging/tests/test_run.py
+++ b/Lib/packaging/tests/test_run.py
@@ -2,11 +2,10 @@
 
 import os
 import sys
-import shutil
 from io import StringIO
 
 from packaging import install
-from packaging.tests import unittest, support, TESTFN
+from packaging.tests import unittest, support
 from packaging.run import main
 
 from test.script_helper import assert_python_ok
@@ -35,28 +34,14 @@
     def setUp(self):
         super(RunTestCase, self).setUp()
         self.old_stdout = sys.stdout
-        self.cleanup_testfn()
         self.old_argv = sys.argv, sys.argv[:]
 
     def tearDown(self):
         sys.stdout = self.old_stdout
-        self.cleanup_testfn()
         sys.argv = self.old_argv[0]
         sys.argv[:] = self.old_argv[1]
         super(RunTestCase, self).tearDown()
 
-    def cleanup_testfn(self):
-        path = TESTFN
-        if os.path.isfile(path):
-            os.remove(path)
-        elif os.path.isdir(path):
-            shutil.rmtree(path)
-
-    def write_setup(self, text, path=TESTFN):
-        with open(path, "w") as fp:
-            fp.write(text)
-        return path
-
     # TODO restore the tests removed six months ago and port them to pysetup
 
     def test_install(self):
diff --git a/Lib/packaging/tests/test_util.py b/Lib/packaging/tests/test_util.py
--- a/Lib/packaging/tests/test_util.py
+++ b/Lib/packaging/tests/test_util.py
@@ -15,7 +15,7 @@
 from packaging import util
 from packaging.dist import Distribution
 from packaging.util import (
-    convert_path, change_root, split_quoted, strtobool,
+    convert_path, change_root, split_quoted, strtobool, run_2to3,
     get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages,
     spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob,
     RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging,
@@ -319,8 +319,6 @@
         res = get_compiler_versions()
         self.assertEqual(res[2], None)
 
-    @unittest.skipUnless(hasattr(sys, 'dont_write_bytecode'),
-                         'sys.dont_write_bytecode not supported')
     def test_dont_write_bytecode(self):
         # makes sure byte_compile raise a PackagingError
         # if sys.dont_write_bytecode is True
@@ -374,7 +372,7 @@
 
         res = find_packages([root], ['pkg1.pkg2'])
         self.assertEqual(set(res), set(['pkg1', 'pkg5', 'pkg1.pkg3',
-                                         'pkg1.pkg3.pkg6']))
+                                        'pkg1.pkg3.pkg6']))
 
     def test_resolve_name(self):
         self.assertIs(str, resolve_name('builtins.str'))
@@ -407,7 +405,6 @@
         finally:
             sys.path.remove(tmp_dir)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_run_2to3_on_code(self):
         content = "print 'test'"
         converted_content = "print('test')"
@@ -416,13 +413,11 @@
         file_handle.write(content)
         file_handle.flush()
         file_handle.seek(0)
-        from packaging.util import run_2to3
         run_2to3([file_name])
         new_content = "".join(file_handle.read())
         file_handle.close()
         self.assertEqual(new_content, converted_content)
 
-    @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
     def test_run_2to3_on_doctests(self):
         # to check if text files containing doctests only get converted.
         content = ">>> print 'test'\ntest\n"
@@ -432,7 +427,6 @@
         file_handle.write(content)
         file_handle.flush()
         file_handle.seek(0)
-        from packaging.util import run_2to3
         run_2to3([file_name], doctests_only=True)
         new_content = "".join(file_handle.readlines())
         file_handle.close()
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -326,7 +326,7 @@
     """
     # nothing is done if sys.dont_write_bytecode is True
     # FIXME this should not raise an error
-    if hasattr(sys, 'dont_write_bytecode') and sys.dont_write_bytecode:
+    if sys.dont_write_bytecode:
         raise PackagingByteCompileError('byte-compiling is disabled.')
 
     # First, if the caller didn't force us into direct or indirect mode,
@@ -346,8 +346,10 @@
     # run it with the appropriate flags.
     if not direct:
         from tempfile import mkstemp
-        # XXX script_fd may leak, use something better than mkstemp
+        # XXX use something better than mkstemp
         script_fd, script_name = mkstemp(".py")
+        os.close(script_fd)
+        script_fd = None
         logger.info("writing byte-compilation script '%s'", script_name)
         if not dry_run:
             if script_fd is not None:
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -307,9 +307,9 @@
     def get_filename(self, fullname=None):
         fullname = self._fix_name(fullname)
         mod_type = self.etc[2]
-        if self.etc[2]==imp.PKG_DIRECTORY:
+        if mod_type==imp.PKG_DIRECTORY:
             return self._get_delegate().get_filename()
-        elif self.etc[2] in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
+        elif mod_type in (imp.PY_SOURCE, imp.PY_COMPILED, imp.C_EXTENSION):
             return self.filename
         return None
 
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -391,7 +391,7 @@
         compress_ext['bzip2'] = '.bz2'
 
     # flags for compression program, each element of list will be an argument
-    if compress is not None and compress not in compress_ext.keys():
+    if compress is not None and compress not in compress_ext:
         raise ValueError("bad value for 'compress', or compression format not "
                          "supported : {0}".format(compress))
 
@@ -497,7 +497,7 @@
     'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
     'bztar': (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
     'tar':   (_make_tarball, [('compress', None)], "uncompressed tar file"),
-    'zip':   (_make_zipfile, [],"ZIP file")
+    'zip':   (_make_zipfile, [], "ZIP file")
     }
 
 if _BZ2_SUPPORTED:
@@ -530,7 +530,7 @@
     if not isinstance(extra_args, (tuple, list)):
         raise TypeError('extra_args needs to be a sequence')
     for element in extra_args:
-        if not isinstance(element, (tuple, list)) or len(element) !=2 :
+        if not isinstance(element, (tuple, list)) or len(element) !=2:
             raise TypeError('extra_args elements are : (arg_name, value)')
 
     _ARCHIVE_FORMATS[name] = (function, extra_args, description)
@@ -682,7 +682,7 @@
             if not name.endswith('/'):
                 # file
                 data = zip.read(info.filename)
-                f = open(target,'wb')
+                f = open(target, 'wb')
                 try:
                     f.write(data)
                 finally:
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -965,7 +965,9 @@
                  'warnings.filters', 'asyncore.socket_map',
                  'logging._handlers', 'logging._handlerList', 'sys.gettrace',
                  'sys.warnoptions', 'threading._dangling',
-                 'multiprocessing.process._dangling')
+                 'multiprocessing.process._dangling',
+                 'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES',
+                )
 
     def get_sys_argv(self):
         return id(sys.argv), sys.argv, sys.argv[:]
@@ -1083,6 +1085,27 @@
         multiprocessing.process._dangling.clear()
         multiprocessing.process._dangling.update(saved)
 
+    def get_sysconfig__CONFIG_VARS(self):
+        # make sure the dict is initialized
+        sysconfig.get_config_var('prefix')
+        return (id(sysconfig._CONFIG_VARS), sysconfig._CONFIG_VARS,
+                dict(sysconfig._CONFIG_VARS))
+    def restore_sysconfig__CONFIG_VARS(self, saved):
+        sysconfig._CONFIG_VARS = saved[1]
+        sysconfig._CONFIG_VARS.clear()
+        sysconfig._CONFIG_VARS.update(saved[2])
+
+    def get_sysconfig__SCHEMES(self):
+        # it's mildly evil to look at the internal attribute, but it's easier
+        # than copying a RawConfigParser object
+        return (id(sysconfig._SCHEMES), sysconfig._SCHEMES._sections,
+                sysconfig._SCHEMES._sections.copy())
+    def restore_sysconfig__SCHEMES(self, saved):
+        sysconfig._SCHEMES._sections = saved[1]
+        sysconfig._SCHEMES._sections.clear()
+        sysconfig._SCHEMES._sections.update(saved[2])
+
+
     def resource_info(self):
         for name in self.resources:
             method_suffix = name.replace('.', '_')
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -39,7 +39,7 @@
         self._config_vars = copy(sysconfig._CONFIG_VARS)
         self._added_envvars = []
         self._changed_envvars = []
-        for var in ('MACOSX_DEPLOYMENT_TARGET', 'Path'):
+        for var in ('MACOSX_DEPLOYMENT_TARGET', 'PATH'):
             if var in os.environ:
                 self._changed_envvars.append((var, os.environ[var]))
             else:
@@ -87,21 +87,19 @@
         scheme = get_paths()
         default_scheme = _get_default_scheme()
         wanted = _expand_vars(default_scheme, None)
-        wanted = list(wanted.items())
-        wanted.sort()
-        scheme = list(scheme.items())
-        scheme.sort()
+        wanted = sorted(wanted.items())
+        scheme = sorted(scheme.items())
         self.assertEqual(scheme, wanted)
 
     def test_get_path(self):
-        # xxx make real tests here
+        # XXX make real tests here
         for scheme in _SCHEMES:
             for name in _SCHEMES[scheme]:
                 res = get_path(name, scheme)
 
     def test_get_config_vars(self):
         cvars = get_config_vars()
-        self.assertTrue(isinstance(cvars, dict))
+        self.assertIsInstance(cvars, dict)
         self.assertTrue(cvars)
 
     def test_get_platform(self):
@@ -236,8 +234,8 @@
         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
         # to add the directory to the path.
         if sys.platform == "win32":
-            os.environ["Path"] = "{};{}".format(
-                os.path.dirname(sys.executable), os.environ["Path"])
+            os.environ["PATH"] = "{};{}".format(
+                os.path.dirname(sys.executable), os.environ["PATH"])
 
         # Issue 7880
         def get(python):

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


More information about the Python-checkins mailing list