summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/archive_util.py2
-rw-r--r--Lib/distutils/cmd.py3
-rw-r--r--Lib/distutils/command/bdist_dumb.py2
-rw-r--r--Lib/distutils/command/bdist_msi.py2
-rw-r--r--Lib/distutils/command/bdist_wininst.py2
-rw-r--r--Lib/distutils/command/build.py4
-rw-r--r--Lib/distutils/command/build_ext.py6
-rw-r--r--Lib/distutils/command/config.py4
-rw-r--r--Lib/distutils/command/install.py12
-rw-r--r--Lib/distutils/command/install_egg_info.py4
-rw-r--r--Lib/distutils/command/register.py8
-rw-r--r--Lib/distutils/command/sdist.py15
-rw-r--r--Lib/distutils/core.py5
-rw-r--r--Lib/distutils/dist.py3
-rw-r--r--Lib/distutils/extension.py1
-rw-r--r--Lib/distutils/sysconfig.py41
-rw-r--r--Lib/distutils/tests/test_bdist_rpm.py4
-rw-r--r--Lib/distutils/tests/test_build.py5
-rw-r--r--Lib/distutils/tests/test_build_ext.py1
-rw-r--r--Lib/distutils/tests/test_build_py.py3
-rw-r--r--Lib/distutils/tests/test_clean.py2
-rw-r--r--Lib/distutils/tests/test_config.py2
-rw-r--r--Lib/distutils/tests/test_core.py30
-rw-r--r--Lib/distutils/tests/test_cygwinccompiler.py3
-rw-r--r--Lib/distutils/tests/test_dep_util.py1
-rw-r--r--Lib/distutils/tests/test_file_util.py1
-rw-r--r--Lib/distutils/tests/test_install_data.py2
-rw-r--r--Lib/distutils/tests/test_install_headers.py2
-rw-r--r--Lib/distutils/tests/test_install_lib.py3
-rw-r--r--Lib/distutils/tests/test_msvc9compiler.py2
-rw-r--r--Lib/distutils/tests/test_spawn.py14
-rw-r--r--Lib/distutils/tests/test_unixccompiler.py1
-rw-r--r--Lib/distutils/text_file.py2
-rw-r--r--Lib/distutils/util.py15
34 files changed, 97 insertions, 110 deletions
diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py
index bed1384..78ae575 100644
--- a/Lib/distutils/archive_util.py
+++ b/Lib/distutils/archive_util.py
@@ -171,7 +171,7 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):
zip.write(path, path)
- log.info("adding '%s'" % path)
+ log.info("adding '%s'", path)
zip.close()
return zip_filename
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py
index c89d5ef..b5d9dc3 100644
--- a/Lib/distutils/cmd.py
+++ b/Lib/distutils/cmd.py
@@ -329,8 +329,7 @@ class Command:
# -- External world manipulation -----------------------------------
def warn(self, msg):
- log.warn("warning: %s: %s\n" %
- (self.get_command_name(), msg))
+ log.warn("warning: %s: %s\n", self.get_command_name(), msg)
def execute(self, func, args, msg=None, level=1):
util.execute(func, args, msg, dry_run=self.dry_run)
diff --git a/Lib/distutils/command/bdist_dumb.py b/Lib/distutils/command/bdist_dumb.py
index f1bfb24..e9274d9 100644
--- a/Lib/distutils/command/bdist_dumb.py
+++ b/Lib/distutils/command/bdist_dumb.py
@@ -85,7 +85,7 @@ class bdist_dumb(Command):
install.skip_build = self.skip_build
install.warn_dir = 0
- log.info("installing to %s" % self.bdist_dir)
+ log.info("installing to %s", self.bdist_dir)
self.run_command('install')
# And make an archive relative to the root of the
diff --git a/Lib/distutils/command/bdist_msi.py b/Lib/distutils/command/bdist_msi.py
index b3cfe9c..f6c21ae 100644
--- a/Lib/distutils/command/bdist_msi.py
+++ b/Lib/distutils/command/bdist_msi.py
@@ -199,7 +199,7 @@ class bdist_msi(Command):
target_version = self.target_version
if not target_version:
assert self.skip_build, "Should have already checked this"
- target_version = sys.version[0:3]
+ target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base,
diff --git a/Lib/distutils/command/bdist_wininst.py b/Lib/distutils/command/bdist_wininst.py
index 0c0e2c1..d3e1d3a 100644
--- a/Lib/distutils/command/bdist_wininst.py
+++ b/Lib/distutils/command/bdist_wininst.py
@@ -141,7 +141,7 @@ class bdist_wininst(Command):
target_version = self.target_version
if not target_version:
assert self.skip_build, "Should have already checked this"
- target_version = sys.version[0:3]
+ target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base,
diff --git a/Lib/distutils/command/build.py b/Lib/distutils/command/build.py
index 337dd0b..c6f52e6 100644
--- a/Lib/distutils/command/build.py
+++ b/Lib/distutils/command/build.py
@@ -81,7 +81,7 @@ class build(Command):
"--plat-name only supported on Windows (try "
"using './configure --help' on your platform)")
- plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
+ plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
# share the same build directories. Doing so confuses the build
@@ -114,7 +114,7 @@ class build(Command):
'temp' + plat_specifier)
if self.build_scripts is None:
self.build_scripts = os.path.join(self.build_base,
- 'scripts-' + sys.version[0:3])
+ 'scripts-%d.%d' % sys.version_info[:2])
if self.executable is None:
self.executable = os.path.normpath(sys.executable)
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index f03a4e3..5e51ae4 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -363,9 +363,9 @@ class build_ext(Command):
ext_name, build_info = ext
- log.warn(("old-style (ext_name, build_info) tuple found in "
- "ext_modules for extension '%s'"
- "-- please convert to Extension instance" % ext_name))
+ log.warn("old-style (ext_name, build_info) tuple found in "
+ "ext_modules for extension '%s'"
+ "-- please convert to Extension instance", ext_name)
if not (isinstance(ext_name, str) and
extension_name_re.match(ext_name)):
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 847e858..4ae153d 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -9,7 +9,7 @@ configure-like tasks: "try to compile this C code", or "figure out where
this header file lives".
"""
-import sys, os, re
+import os, re
from distutils.core import Command
from distutils.errors import DistutilsExecError
@@ -337,7 +337,7 @@ def dump_file(filename, head=None):
If head is not None, will be dumped before the file content.
"""
if head is None:
- log.info('%s' % filename)
+ log.info('%s', filename)
else:
log.info(head)
file = open(filename)
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index 67db007..0258d3de 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -175,6 +175,7 @@ class install(Command):
self.compile = None
self.optimize = None
+ # Deprecated
# These two are for putting non-packagized distributions into their
# own directory and creating a .pth file if it makes sense.
# 'extra_path' comes from the setup file; 'install_path_file' can
@@ -290,8 +291,8 @@ class install(Command):
'dist_version': self.distribution.get_version(),
'dist_fullname': self.distribution.get_fullname(),
'py_version': py_version,
- 'py_version_short': py_version[0:3],
- 'py_version_nodot': py_version[0] + py_version[2],
+ 'py_version_short': '%d.%d' % sys.version_info[:2],
+ 'py_version_nodot': '%d%d' % sys.version_info[:2],
'sys_prefix': prefix,
'prefix': prefix,
'sys_exec_prefix': exec_prefix,
@@ -344,6 +345,7 @@ class install(Command):
'scripts', 'data', 'headers',
'userbase', 'usersite')
+ # Deprecated
# Well, we're not actually fully completely finalized yet: we still
# have to deal with 'extra_path', which is the hack for allowing
# non-packagized module distributions (hello, Numerical Python!) to
@@ -385,7 +387,7 @@ class install(Command):
else:
opt_name = opt_name.translate(longopt_xlate)
val = getattr(self, opt_name)
- log.debug(" %s: %s" % (opt_name, val))
+ log.debug(" %s: %s", opt_name, val)
def finalize_unix(self):
"""Finalizes options for posix platforms."""
@@ -490,6 +492,10 @@ class install(Command):
self.extra_path = self.distribution.extra_path
if self.extra_path is not None:
+ log.warn(
+ "Distribution option extra_path is deprecated. "
+ "See issue27919 for details."
+ )
if isinstance(self.extra_path, str):
self.extra_path = self.extra_path.split(',')
diff --git a/Lib/distutils/command/install_egg_info.py b/Lib/distutils/command/install_egg_info.py
index c2a7d64..0ddc736 100644
--- a/Lib/distutils/command/install_egg_info.py
+++ b/Lib/distutils/command/install_egg_info.py
@@ -21,10 +21,10 @@ class install_egg_info(Command):
def finalize_options(self):
self.set_undefined_options('install_lib',('install_dir','install_dir'))
- basename = "%s-%s-py%s.egg-info" % (
+ basename = "%s-%s-py%d.%d.egg-info" % (
to_filename(safe_name(self.distribution.get_name())),
to_filename(safe_version(self.distribution.get_version())),
- sys.version[:3]
+ *sys.version_info[:2]
)
self.target = os.path.join(self.install_dir, basename)
self.outputs = [self.target]
diff --git a/Lib/distutils/command/register.py b/Lib/distutils/command/register.py
index 86343c8..0fac94e 100644
--- a/Lib/distutils/command/register.py
+++ b/Lib/distutils/command/register.py
@@ -5,7 +5,7 @@ Implements the Distutils 'register' command (register with the repository).
# created 2002/10/21, Richard Jones
-import os, string, getpass
+import getpass
import io
import urllib.parse, urllib.request
from warnings import warn
@@ -94,7 +94,7 @@ class register(PyPIRCCommand):
'''
# send the info to the server and report the result
(code, result) = self.post_to_server(self.build_post_data('verify'))
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
def send_metadata(self):
''' Send the metadata to the package index server.
@@ -205,7 +205,7 @@ Your selection [default 1]: ''', log.INFO)
data['email'] = input(' EMail: ')
code, result = self.post_to_server(data)
if code != 200:
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
else:
log.info('You will receive an email shortly.')
log.info(('Follow the instructions in it to '
@@ -216,7 +216,7 @@ Your selection [default 1]: ''', log.INFO)
while not data['email']:
data['email'] = input('Your email address: ')
code, result = self.post_to_server(data)
- log.info('Server response (%s): %s' % (code, result))
+ log.info('Server response (%s): %s', code, result)
def build_post_data(self, action):
# figure the data to send - the metadata plus some additional
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
index 7ea3d5f..4fd1d47 100644
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -3,7 +3,6 @@
Implements the Distutils 'sdist' command (create a source distribution)."""
import os
-import string
import sys
from types import *
from glob import glob
@@ -92,9 +91,6 @@ class sdist(Command):
negative_opt = {'no-defaults': 'use-defaults',
'no-prune': 'prune' }
- default_format = {'posix': 'gztar',
- 'nt': 'zip' }
-
sub_commands = [('check', checking_metadata)]
def initialize_options(self):
@@ -111,7 +107,7 @@ class sdist(Command):
self.manifest_only = 0
self.force_manifest = 0
- self.formats = None
+ self.formats = ['gztar']
self.keep_temp = 0
self.dist_dir = None
@@ -127,13 +123,6 @@ class sdist(Command):
self.template = "MANIFEST.in"
self.ensure_string_list('formats')
- if self.formats is None:
- try:
- self.formats = [self.default_format[os.name]]
- except KeyError:
- raise DistutilsPlatformError(
- "don't know how to create source distributions "
- "on platform %s" % os.name)
bad_format = archive_util.check_archive_formats(self.formats)
if bad_format:
@@ -423,7 +412,7 @@ class sdist(Command):
log.info(msg)
for file in files:
if not os.path.isfile(file):
- log.warn("'%s' not a regular file -- skipping" % file)
+ log.warn("'%s' not a regular file -- skipping", file)
else:
dest = os.path.join(base_dir, file)
self.copy_file(file, dest, link=link)
diff --git a/Lib/distutils/core.py b/Lib/distutils/core.py
index f05b34b..d603d4a 100644
--- a/Lib/distutils/core.py
+++ b/Lib/distutils/core.py
@@ -204,16 +204,15 @@ def run_setup (script_name, script_args=None, stop_after="run"):
global _setup_stop_after, _setup_distribution
_setup_stop_after = stop_after
- save_argv = sys.argv
+ save_argv = sys.argv.copy()
g = {'__file__': script_name}
- l = {}
try:
try:
sys.argv[0] = script_name
if script_args is not None:
sys.argv[1:] = script_args
with open(script_name, 'rb') as f:
- exec(f.read(), g, l)
+ exec(f.read(), g)
finally:
sys.argv = save_argv
_setup_stop_after = None
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py
index ffb33ff6..62a2451 100644
--- a/Lib/distutils/dist.py
+++ b/Lib/distutils/dist.py
@@ -1018,8 +1018,7 @@ class DistributionMetadata:
"maintainer", "maintainer_email", "url",
"license", "description", "long_description",
"keywords", "platforms", "fullname", "contact",
- "contact_email", "license", "classifiers",
- "download_url",
+ "contact_email", "classifiers", "download_url",
# PEP 314
"provides", "requires", "obsoletes",
)
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index 7efbb74..c507da3 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -4,7 +4,6 @@ Provides the Extension class, used to describe C/C++ extension
modules in setup scripts."""
import os
-import sys
import warnings
# This class is really only used by the "build_ext" command, so it might
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 573724d..f72b7f5 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -70,7 +70,7 @@ def get_python_version():
leaving off the patchlevel. Sample return values could be '1.5'
or '2.2'.
"""
- return sys.version[:3]
+ return '%d.%d' % sys.version_info[:2]
def get_python_inc(plat_specific=0, prefix=None):
@@ -242,6 +242,8 @@ def get_makefile_filename():
return os.path.join(_sys_home or project_base, "Makefile")
lib_dir = get_python_lib(plat_specific=0, standard_lib=1)
config_file = 'config-{}{}'.format(get_python_version(), build_flags)
+ if hasattr(sys.implementation, '_multiarch'):
+ config_file += '-%s' % sys.implementation._multiarch
return os.path.join(lib_dir, config_file, 'Makefile')
@@ -415,38 +417,13 @@ _config_vars = None
def _init_posix():
"""Initialize the module as appropriate for POSIX systems."""
- g = {}
- # load the installed Makefile:
- try:
- filename = get_makefile_filename()
- parse_makefile(filename, g)
- except OSError as msg:
- my_msg = "invalid Python installation: unable to open %s" % filename
- if hasattr(msg, "strerror"):
- my_msg = my_msg + " (%s)" % msg.strerror
-
- raise DistutilsPlatformError(my_msg)
-
- # load the installed pyconfig.h:
- try:
- filename = get_config_h_filename()
- with open(filename) as file:
- parse_config_h(file, g)
- except OSError as msg:
- my_msg = "invalid Python installation: unable to open %s" % filename
- if hasattr(msg, "strerror"):
- my_msg = my_msg + " (%s)" % msg.strerror
-
- raise DistutilsPlatformError(my_msg)
-
- # On AIX, there are wrong paths to the linker scripts in the Makefile
- # -- these paths are relative to the Python source, but when installed
- # the scripts are in another directory.
- if python_build:
- g['LDSHARED'] = g['BLDSHARED']
-
+ # _sysconfigdata is generated at build time, see the sysconfig module
+ name = '_sysconfigdata_' + sys.abiflags
+ _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
+ build_time_vars = _temp.build_time_vars
global _config_vars
- _config_vars = g
+ _config_vars = {}
+ _config_vars.update(build_time_vars)
def _init_nt():
diff --git a/Lib/distutils/tests/test_bdist_rpm.py b/Lib/distutils/tests/test_bdist_rpm.py
index 25c14ab..c1a2a04 100644
--- a/Lib/distutils/tests/test_bdist_rpm.py
+++ b/Lib/distutils/tests/test_bdist_rpm.py
@@ -3,16 +3,12 @@
import unittest
import sys
import os
-import tempfile
-import shutil
from test.support import run_unittest
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
from distutils.spawn import find_executable
-from distutils import spawn
-from distutils.errors import DistutilsExecError
SETUP_PY = """\
from distutils.core import setup
diff --git a/Lib/distutils/tests/test_build.py b/Lib/distutils/tests/test_build.py
index 3391f36..b020a5b 100644
--- a/Lib/distutils/tests/test_build.py
+++ b/Lib/distutils/tests/test_build.py
@@ -27,7 +27,7 @@ class BuildTestCase(support.TempdirManager,
# build_platlib is 'build/lib.platform-x.x[-pydebug]'
# examples:
# build/lib.macosx-10.3-i386-2.7
- plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
+ plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
if hasattr(sys, 'gettotalrefcount'):
self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
plat_spec += '-pydebug'
@@ -42,7 +42,8 @@ class BuildTestCase(support.TempdirManager,
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])
+ wanted = os.path.join(cmd.build_base,
+ 'scripts-%d.%d' % sys.version_info[:2])
self.assertEqual(cmd.build_scripts, wanted)
# executable is os.path.normpath(sys.executable)
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index 4e397ea..47b586c 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -166,7 +166,6 @@ class BuildExtTestCase(TempdirManager,
cmd = self.build_ext(dist)
cmd.finalize_options()
- from distutils import sysconfig
py_include = sysconfig.get_python_inc()
self.assertIn(py_include, cmd.include_dirs)
diff --git a/Lib/distutils/tests/test_build_py.py b/Lib/distutils/tests/test_build_py.py
index 18283dc..0712e92 100644
--- a/Lib/distutils/tests/test_build_py.py
+++ b/Lib/distutils/tests/test_build_py.py
@@ -168,7 +168,8 @@ class BuildPyTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled', self.logs[0][1])
+ self.assertIn('byte-compiling is disabled',
+ self.logs[0][1] % self.logs[0][2])
def test_suite():
diff --git a/Lib/distutils/tests/test_clean.py b/Lib/distutils/tests/test_clean.py
index b64f300..c605afd 100644
--- a/Lib/distutils/tests/test_clean.py
+++ b/Lib/distutils/tests/test_clean.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.clean."""
-import sys
import os
import unittest
-import getpass
from distutils.command.clean import clean
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_config.py b/Lib/distutils/tests/test_config.py
index a384497..77ef788 100644
--- a/Lib/distutils/tests/test_config.py
+++ b/Lib/distutils/tests/test_config.py
@@ -1,8 +1,6 @@
"""Tests for distutils.pypirc.pypirc."""
-import sys
import os
import unittest
-import tempfile
from distutils.core import PyPIRCCommand
from distutils.core import Distribution
diff --git a/Lib/distutils/tests/test_core.py b/Lib/distutils/tests/test_core.py
index 654227c..27ce732 100644
--- a/Lib/distutils/tests/test_core.py
+++ b/Lib/distutils/tests/test_core.py
@@ -29,6 +29,21 @@ from distutils.core import setup
setup()
"""
+setup_does_nothing = """\
+from distutils.core import setup
+setup()
+"""
+
+
+setup_defines_subclass = """\
+from distutils.core import setup
+from distutils.command.install import install as _install
+
+class install(_install):
+ sub_commands = _install.sub_commands + ['cmd']
+
+setup(cmdclass={'install': install})
+"""
class CoreTestCase(support.EnvironGuard, unittest.TestCase):
@@ -67,6 +82,21 @@ class CoreTestCase(support.EnvironGuard, unittest.TestCase):
distutils.core.run_setup(
self.write_setup(setup_using___file__))
+ def test_run_setup_preserves_sys_argv(self):
+ # Make sure run_setup does not clobber sys.argv
+ argv_copy = sys.argv.copy()
+ distutils.core.run_setup(
+ self.write_setup(setup_does_nothing))
+ self.assertEqual(sys.argv, argv_copy)
+
+ def test_run_setup_defines_subclass(self):
+ # Make sure the script can use __file__; if that's missing, the test
+ # setup.py script will raise NameError.
+ dist = distutils.core.run_setup(
+ self.write_setup(setup_defines_subclass))
+ install = dist.get_command_obj('install')
+ self.assertIn('cmd', install.sub_commands)
+
def test_run_setup_uses_current_dir(self):
# This tests that the setup script is run with the current directory
# as its own current directory; this was temporarily broken by a
diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py
index 8569216..9dc869d 100644
--- a/Lib/distutils/tests/test_cygwinccompiler.py
+++ b/Lib/distutils/tests/test_cygwinccompiler.py
@@ -3,11 +3,10 @@ import unittest
import sys
import os
from io import BytesIO
-import subprocess
from test.support import run_unittest
from distutils import cygwinccompiler
-from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
+from distutils.cygwinccompiler import (check_config_h,
CONFIG_H_OK, CONFIG_H_NOTOK,
CONFIG_H_UNCERTAIN, get_versions,
get_msvcr)
diff --git a/Lib/distutils/tests/test_dep_util.py b/Lib/distutils/tests/test_dep_util.py
index 3e1c366..c6fae39 100644
--- a/Lib/distutils/tests/test_dep_util.py
+++ b/Lib/distutils/tests/test_dep_util.py
@@ -1,7 +1,6 @@
"""Tests for distutils.dep_util."""
import unittest
import os
-import time
from distutils.dep_util import newer, newer_pairwise, newer_group
from distutils.errors import DistutilsFileError
diff --git a/Lib/distutils/tests/test_file_util.py b/Lib/distutils/tests/test_file_util.py
index a6d04f0..03040af 100644
--- a/Lib/distutils/tests/test_file_util.py
+++ b/Lib/distutils/tests/test_file_util.py
@@ -1,7 +1,6 @@
"""Tests for distutils.file_util."""
import unittest
import os
-import shutil
import errno
from unittest.mock import patch
diff --git a/Lib/distutils/tests/test_install_data.py b/Lib/distutils/tests/test_install_data.py
index 4d8c00a..32ab296 100644
--- a/Lib/distutils/tests/test_install_data.py
+++ b/Lib/distutils/tests/test_install_data.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.install_data."""
-import sys
import os
import unittest
-import getpass
from distutils.command.install_data import install_data
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_install_headers.py b/Lib/distutils/tests/test_install_headers.py
index d953157..2217b32 100644
--- a/Lib/distutils/tests/test_install_headers.py
+++ b/Lib/distutils/tests/test_install_headers.py
@@ -1,8 +1,6 @@
"""Tests for distutils.command.install_headers."""
-import sys
import os
import unittest
-import getpass
from distutils.command.install_headers import install_headers
from distutils.tests import support
diff --git a/Lib/distutils/tests/test_install_lib.py b/Lib/distutils/tests/test_install_lib.py
index 5378aa8..fda6315 100644
--- a/Lib/distutils/tests/test_install_lib.py
+++ b/Lib/distutils/tests/test_install_lib.py
@@ -104,7 +104,8 @@ class InstallLibTestCase(support.TempdirManager,
finally:
sys.dont_write_bytecode = old_dont_write_bytecode
- self.assertIn('byte-compiling is disabled', self.logs[0][1])
+ self.assertIn('byte-compiling is disabled',
+ self.logs[0][1] % self.logs[0][2])
def test_suite():
diff --git a/Lib/distutils/tests/test_msvc9compiler.py b/Lib/distutils/tests/test_msvc9compiler.py
index 5e18c61..77a07ef 100644
--- a/Lib/distutils/tests/test_msvc9compiler.py
+++ b/Lib/distutils/tests/test_msvc9compiler.py
@@ -125,7 +125,7 @@ class msvc9compilerTestCase(support.TempdirManager,
self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
# looking for values that should exist on all
- # windows registeries versions.
+ # windows registry versions.
path = r'Control Panel\Desktop'
v = Reg.get_value(path, 'dragfullwindows')
self.assertIn(v, ('0', '1', '2'))
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index 6c7eb20..5edc24a 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -1,11 +1,11 @@
"""Tests for distutils.spawn."""
import unittest
+import sys
import os
-import time
-from test.support import captured_stdout, run_unittest
+from test.support import run_unittest, unix_shell
from distutils.spawn import _nt_quote_args
-from distutils.spawn import spawn, find_executable
+from distutils.spawn import spawn
from distutils.errors import DistutilsExecError
from distutils.tests import support
@@ -30,9 +30,9 @@ class SpawnTestCase(support.TempdirManager,
# creating something executable
# through the shell that returns 1
- if os.name == 'posix':
+ if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 1')
+ self.write_file(exe, '#!%s\nexit 1' % unix_shell)
else:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 1')
@@ -41,9 +41,9 @@ class SpawnTestCase(support.TempdirManager,
self.assertRaises(DistutilsExecError, spawn, [exe])
# now something that works
- if os.name == 'posix':
+ if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh')
- self.write_file(exe, '#!/bin/sh\nexit 0')
+ self.write_file(exe, '#!%s\nexit 0' % unix_shell)
else:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 0')
diff --git a/Lib/distutils/tests/test_unixccompiler.py b/Lib/distutils/tests/test_unixccompiler.py
index e171ee9..efba27e 100644
--- a/Lib/distutils/tests/test_unixccompiler.py
+++ b/Lib/distutils/tests/test_unixccompiler.py
@@ -1,5 +1,4 @@
"""Tests for distutils.unixccompiler."""
-import os
import sys
import unittest
from test.support import EnvironmentVarGuard, run_unittest
diff --git a/Lib/distutils/text_file.py b/Lib/distutils/text_file.py
index 478336f..93abad3 100644
--- a/Lib/distutils/text_file.py
+++ b/Lib/distutils/text_file.py
@@ -4,7 +4,7 @@ provides the TextFile class, which gives an interface to text files
that (optionally) takes care of stripping comments, ignoring blank
lines, and joining lines with backslashes."""
-import sys, os, io
+import sys, io
class TextFile:
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index e423325..fdcf6fa 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -7,8 +7,8 @@ one of the other *util.py modules.
import os
import re
import importlib.util
-import sys
import string
+import sys
from distutils.errors import DistutilsPlatformError
from distutils.dep_util import newer
from distutils.spawn import spawn
@@ -350,6 +350,11 @@ def byte_compile (py_files,
generated in indirect mode; unless you know what you're doing, leave
it set to None.
"""
+
+ # Late import to fix a bootstrap issue: _posixsubprocess is built by
+ # setup.py, but setup.py uses distutils.
+ import subprocess
+
# nothing is done if sys.dont_write_bytecode is True
if sys.dont_write_bytecode:
raise DistutilsByteCompileError('byte-compiling is disabled.')
@@ -412,11 +417,9 @@ byte_compile(files, optimize=%r, force=%r,
script.close()
- cmd = [sys.executable, script_name]
- if optimize == 1:
- cmd.insert(1, "-O")
- elif optimize == 2:
- cmd.insert(1, "-OO")
+ cmd = [sys.executable]
+ cmd.extend(subprocess._optim_args_from_interpreter_flags())
+ cmd.append(script_name)
spawn(cmd, dry_run=dry_run)
execute(os.remove, (script_name,), "removing %s" % script_name,
dry_run=dry_run)