Skip to content

Commit

Permalink
Merge pull request #3480 from pypa/bugfix/distutils-164
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco authored Aug 3, 2022
2 parents 9b0cf7e + 4ae3db7 commit a2c4c57
Show file tree
Hide file tree
Showing 74 changed files with 1,037 additions and 1,081 deletions.
1 change: 1 addition & 0 deletions changelog.d/3480.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merge with pypa/distutils@c397f4c
12 changes: 5 additions & 7 deletions setuptools/_distutils/_msvccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def _get_vc_env(plat_spec):

try:
out = subprocess.check_output(
'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
f'cmd /u /c "{vcvarsall}" {plat_spec} && set',
stderr=subprocess.STDOUT,
).decode('utf-16le', errors='replace')
except subprocess.CalledProcessError as exc:
log.error(exc.output)
raise DistutilsPlatformError("Error executing {}".format(exc.cmd))
raise DistutilsPlatformError(f"Error executing {exc.cmd}")

env = {
key.lower(): value
Expand Down Expand Up @@ -232,7 +232,7 @@ def initialize(self, plat_name=None):
# sanity check for platforms to prevent obscure errors later.
if plat_name not in PLAT_TO_VCVARS:
raise DistutilsPlatformError(
"--plat-name must be one of {}".format(tuple(PLAT_TO_VCVARS))
f"--plat-name must be one of {tuple(PLAT_TO_VCVARS)}"
)

# Get the vcvarsall.bat spec for the requested platform.
Expand Down Expand Up @@ -341,7 +341,7 @@ def make_out_path(p):
# Better to raise an exception instead of silently continuing
# and later complain about sources and targets having
# different lengths
raise CompileError("Don't know how to compile {}".format(p))
raise CompileError(f"Don't know how to compile {p}")

return list(map(make_out_path, source_filenames))

Expand Down Expand Up @@ -425,9 +425,7 @@ def compile( # noqa: C901
continue
else:
# how to handle this file?
raise CompileError(
"Don't know how to compile {} to {}".format(src, obj)
)
raise CompileError(f"Don't know how to compile {src} to {obj}")

args = [self.cc] + compile_opts + pp_opts
if add_cpp_opts:
Expand Down
4 changes: 2 additions & 2 deletions setuptools/_distutils/bcppcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def link( # noqa: C901
def_file = os.path.join(temp_dir, '%s.def' % modname)
contents = ['EXPORTS']
for sym in export_symbols or []:
contents.append(' %s=_%s' % (sym, sym))
contents.append(' {}=_{}'.format(sym, sym))
self.execute(write_file, (def_file, contents), "writing %s" % def_file)

# Borland C++ has problems with '/' in paths
Expand Down Expand Up @@ -346,7 +346,7 @@ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
(base, ext) = os.path.splitext(os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc', '.res']):
raise UnknownFileError(
"unknown file type '%s' (from '%s')" % (ext, src_name)
"unknown file type '{}' (from '{}')".format(ext, src_name)
)
if strip_dir:
base = os.path.basename(base)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
base = base[os.path.isabs(base) :] # If abs, chop off leading /
if ext not in self.src_extensions:
raise UnknownFileError(
"unknown file type '%s' (from '%s')" % (ext, src_name)
"unknown file type '{}' (from '{}')".format(ext, src_name)
)
if strip_dir:
base = os.path.basename(base)
Expand Down
8 changes: 4 additions & 4 deletions setuptools/_distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def dump_options(self, header=None, indent=""):
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
self.announce(indent + "%s = %s" % (option, value), level=log.INFO)
self.announce(indent + "{} = {}".format(option, value), level=log.INFO)

def run(self):
"""A command's raison d'etre: carry out the action it exists to
Expand Down Expand Up @@ -215,7 +215,7 @@ def _ensure_stringlike(self, option, what, default=None):
return default
elif not isinstance(val, str):
raise DistutilsOptionError(
"'%s' must be a %s (got `%s`)" % (option, what, val)
"'{}' must be a {} (got `{}`)".format(option, what, val)
)
return val

Expand Down Expand Up @@ -243,7 +243,7 @@ def ensure_string_list(self, option):
ok = False
if not ok:
raise DistutilsOptionError(
"'%s' must be a list of strings (got %r)" % (option, val)
"'{}' must be a list of strings (got {!r})".format(option, val)
)

def _ensure_tested_string(self, option, tester, what, error_fmt, default=None):
Expand Down Expand Up @@ -424,7 +424,7 @@ def make_file(
raise TypeError("'infiles' must be a string, or a list or tuple of strings")

if exec_msg is None:
exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
exec_msg = "generating {} from {}".format(outfile, ', '.join(infiles))

# If 'outfile' must be regenerated (either because it doesn't
# exist, is out-of-date, or the 'force' flag is true) then
Expand Down
31 changes: 10 additions & 21 deletions setuptools/_distutils/command/bdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ def show_formats():
pretty_printer.print_help("List of available distribution formats:")


class ListCompat(dict):
# adapter to allow for Setuptools compatibility in format_commands
def append(self, item):
return


class bdist(Command):

description = "create a built (binary) distribution"
Expand Down Expand Up @@ -71,23 +65,18 @@ class bdist(Command):
default_format = {'posix': 'gztar', 'nt': 'zip'}

# Define commands in preferred order for the --help-formats option
format_commands = ListCompat(
{
'rpm': ('bdist_rpm', "RPM distribution"),
'gztar': ('bdist_dumb', "gzip'ed tar file"),
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
'xztar': ('bdist_dumb', "xz'ed tar file"),
'ztar': ('bdist_dumb', "compressed tar file"),
'tar': ('bdist_dumb', "tar file"),
'wininst': ('bdist_wininst', "Windows executable installer"),
'zip': ('bdist_dumb', "ZIP file"),
'msi': ('bdist_msi', "Microsoft Installer"),
}
format_commands = dict(
rpm=('bdist_rpm', "RPM distribution"),
gztar=('bdist_dumb', "gzip'ed tar file"),
bztar=('bdist_dumb', "bzip2'ed tar file"),
xztar=('bdist_dumb', "xz'ed tar file"),
ztar=('bdist_dumb', "compressed tar file"),
tar=('bdist_dumb', "tar file"),
wininst=('bdist_wininst', "Windows executable installer"),
zip=('bdist_dumb', "ZIP file"),
msi=('bdist_msi', "Microsoft Installer"),
)

# for compatibility until Setuptools references only format_commands
format_command = format_commands

def initialize_options(self):
self.bdist_base = None
self.plat_name = None
Expand Down
4 changes: 3 additions & 1 deletion setuptools/_distutils/command/bdist_dumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def run(self):

# And make an archive relative to the root of the
# pseudo-installation tree.
archive_basename = "%s.%s" % (self.distribution.get_fullname(), self.plat_name)
archive_basename = "{}.{}".format(
self.distribution.get_fullname(), self.plat_name
)

pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
if not self.relative:
Expand Down
10 changes: 5 additions & 5 deletions setuptools/_distutils/command/bdist_msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def run(self): # noqa: C901
if not target_version:
assert self.skip_build, "Should have already checked this"
target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
plat_specifier = ".{}-{}".format(self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base, 'lib' + plat_specifier)

Expand Down Expand Up @@ -286,7 +286,7 @@ def run(self): # noqa: C901
# in Add-Remove-Programs (APR)
fullname = self.distribution.get_fullname()
if self.target_version:
product_name = "Python %s %s" % (self.target_version, fullname)
product_name = "Python {} {}".format(self.target_version, fullname)
else:
product_name = "Python %s" % (fullname)
self.db = msilib.init_database(
Expand Down Expand Up @@ -347,7 +347,7 @@ def add_files(self): # noqa: C901
for file in os.listdir(dir.absolute):
afile = os.path.join(dir.absolute, file)
if os.path.isdir(afile):
short = "%s|%s" % (dir.make_short(file), file)
short = "{}|{}".format(dir.make_short(file), file)
default = file + version
newdir = Directory(db, cab, dir, file, default, short)
todo.append(newdir)
Expand Down Expand Up @@ -1103,12 +1103,12 @@ def add_ui(self):
def get_installer_filename(self, fullname):
# Factored out to allow overriding in subclasses
if self.target_version:
base_name = "%s.%s-py%s.msi" % (
base_name = "{}.{}-py{}.msi".format(
fullname,
self.plat_name,
self.target_version,
)
else:
base_name = "%s.%s.msi" % (fullname, self.plat_name)
base_name = "{}.{}.msi".format(fullname, self.plat_name)
installer_name = os.path.join(self.dist_dir, base_name)
return installer_name
8 changes: 4 additions & 4 deletions setuptools/_distutils/command/bdist_rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def run(self): # noqa: C901
nvr_string = "%{name}-%{version}-%{release}"
src_rpm = nvr_string + ".src.rpm"
non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
q_cmd = r"rpm -q --qf '{} {}\n' --specfile '{}'".format(
src_rpm,
non_src_rpm,
spec_path,
Expand Down Expand Up @@ -488,9 +488,9 @@ def _make_spec_file(self): # noqa: C901
):
val = getattr(self, field.lower())
if isinstance(val, list):
spec_file.append('%s: %s' % (field, ' '.join(val)))
spec_file.append('{}: {}'.format(field, ' '.join(val)))
elif val is not None:
spec_file.append('%s: %s' % (field, val))
spec_file.append('{}: {}'.format(field, val))

if self.distribution.get_url():
spec_file.append('Url: ' + self.distribution.get_url())
Expand Down Expand Up @@ -527,7 +527,7 @@ def _make_spec_file(self): # noqa: C901

# rpm scripts
# figure out default build script
def_setup_call = "%s %s" % (self.python, os.path.basename(sys.argv[0]))
def_setup_call = "{} {}".format(self.python, os.path.basename(sys.argv[0]))
def_build = "%s build" % def_setup_call
if self.use_rpm_opt_flags:
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
Expand Down
16 changes: 8 additions & 8 deletions setuptools/_distutils/command/bdist_wininst.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def run(self):
if not target_version:
assert self.skip_build, "Should have already checked this"
target_version = '%d.%d' % sys.version_info[:2]
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
plat_specifier = ".{}-{}".format(self.plat_name, target_version)
build = self.get_finalized_command('build')
build.build_lib = os.path.join(build.build_base, 'lib' + plat_specifier)

Expand Down Expand Up @@ -259,8 +259,8 @@ def escape(s):
]:
data = getattr(metadata, name, "")
if data:
info = info + ("\n %s: %s" % (name.capitalize(), escape(data)))
lines.append("%s=%s" % (name, escape(data)))
info = info + ("\n {}: {}".format(name.capitalize(), escape(data)))
lines.append("{}={}".format(name, escape(data)))

# The [setup] section contains entries controlling
# the installer runtime.
Expand All @@ -280,7 +280,7 @@ def escape(s):
import time
import distutils

build_info = "Built %s with distutils-%s" % (
build_info = "Built {} with distutils-{}".format(
time.ctime(time.time()),
distutils.__version__,
)
Expand Down Expand Up @@ -319,7 +319,7 @@ def create_exe(self, arcname, fullname, bitmap=None):
# We need to normalize newlines, so we open in text mode and
# convert back to bytes. "latin-1" simply avoids any possible
# failures.
with open(self.pre_install_script, "r", encoding="latin-1") as script:
with open(self.pre_install_script, encoding="latin-1") as script:
script_data = script.read().encode("latin-1")
cfgdata = cfgdata + script_data + b"\n\0"
else:
Expand Down Expand Up @@ -349,11 +349,11 @@ def get_installer_filename(self, fullname):
# it's better to include this in the name
installer_name = os.path.join(
self.dist_dir,
"%s.%s-py%s.exe" % (fullname, self.plat_name, self.target_version),
"{}.{}-py{}.exe".format(fullname, self.plat_name, self.target_version),
)
else:
installer_name = os.path.join(
self.dist_dir, "%s.%s.exe" % (fullname, self.plat_name)
self.dist_dir, "{}.{}.exe".format(fullname, self.plat_name)
)
return installer_name

Expand Down Expand Up @@ -410,7 +410,7 @@ def get_exe_bytes(self): # noqa: C901
else:
sfix = ''

filename = os.path.join(directory, "wininst-%s%s.exe" % (bv, sfix))
filename = os.path.join(directory, "wininst-{}{}.exe".format(bv, sfix))
f = open(filename, "rb")
try:
return f.read()
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def finalize_options(self): # noqa: C901
"using './configure --help' on your platform)"
)

plat_specifier = ".%s-%s" % (self.plat_name, sys.implementation.cache_tag)
plat_specifier = ".{}-{}".format(self.plat_name, sys.implementation.cache_tag)

# 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
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _filter_build_errors(self, ext):
except (CCompilerError, DistutilsError, CompileError) as e:
if not ext.optional:
raise
self.warn('building extension "%s" failed: %s' % (ext.name, e))
self.warn('building extension "{}" failed: {}'.format(ext.name, e))

def build_extension(self, ext):
sources = ext.sources
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def check_restructuredtext(self):
if line is None:
warning = warning[1]
else:
warning = '%s (line %s)' % (warning[1], line)
warning = '{} (line {})'.format(warning[1], line)
self.warn(warning)

def _check_rst_data(self, data):
Expand Down
6 changes: 3 additions & 3 deletions setuptools/_distutils/command/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def send_metadata(self): # noqa: C901
auth.add_password(self.realm, host, username, password)
# send the info to the server and report the result
code, result = self.post_to_server(self.build_post_data('submit'), auth)
self.announce('Server response (%s): %s' % (code, result), log.INFO)
self.announce('Server response ({}): {}'.format(code, result), log.INFO)

# possibly save the login
if code == 200:
Expand Down Expand Up @@ -224,7 +224,7 @@ def send_metadata(self): # noqa: C901
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 ' 'complete registration.'))
log.info('Follow the instructions in it to ' 'complete registration.')
elif choice == '3':
data = {':action': 'password_reset'}
data['email'] = ''
Expand Down Expand Up @@ -265,7 +265,7 @@ def post_to_server(self, data, auth=None): # noqa: C901
'''Post a query to the server, and return a string response.'''
if 'name' in data:
self.announce(
'Registering %s to %s' % (data['name'], self.repository), log.INFO
'Registering {} to {}'.format(data['name'], self.repository), log.INFO
)
# Build up the MIME payload for the urllib2 POST data
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/command/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def prune_file_list(self):
seps = '/'

vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr', '_darcs']
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
vcs_ptrn = r'(^|{})({})({}).*'.format(seps, '|'.join(vcs_dirs), seps)
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)

def write_manifest(self):
Expand Down
6 changes: 3 additions & 3 deletions setuptools/_distutils/command/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def upload_file(self, command, pyversion, filename): # noqa: C901
body.write(end_boundary)
body = body.getvalue()

msg = "Submitting %s to %s" % (filename, self.repository)
msg = "Submitting {} to {}".format(filename, self.repository)
self.announce(msg, log.INFO)

# build the Request
Expand All @@ -194,12 +194,12 @@ def upload_file(self, command, pyversion, filename): # noqa: C901
raise

if status == 200:
self.announce('Server response (%s): %s' % (status, reason), log.INFO)
self.announce('Server response ({}): {}'.format(status, reason), log.INFO)
if self.show_response:
text = self._read_pypi_response(result)
msg = '\n'.join(('-' * 75, text, '-' * 75))
self.announce(msg, log.INFO)
else:
msg = 'Upload failed (%s): %s' % (status, reason)
msg = 'Upload failed ({}): {}'.format(status, reason)
self.announce(msg, log.ERROR)
raise DistutilsError(msg)
Loading

0 comments on commit a2c4c57

Please sign in to comment.