[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-04-13 00:00:18 +00:00
parent 72ad6dc953
commit f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions

View file

@ -12,16 +12,23 @@ the "typical" Unix-style command-line C compiler:
* link static library handled by 'ar' command (possibly with 'ranlib')
* link shared library handled by 'cc -shared'
"""
from __future__ import annotations
import os, sys, re, shlex
import os
import re
import shlex
import sys
from distutils import sysconfig
from distutils.dep_util import newer
from distutils.ccompiler import \
CCompiler, gen_preprocess_options, gen_lib_options
from distutils.errors import \
DistutilsExecError, CompileError, LibError, LinkError
from distutils import log
from distutils import sysconfig
from distutils.ccompiler import CCompiler
from distutils.ccompiler import gen_lib_options
from distutils.ccompiler import gen_preprocess_options
from distutils.dep_util import newer
from distutils.errors import CompileError
from distutils.errors import DistutilsExecError
from distutils.errors import LibError
from distutils.errors import LinkError
if sys.platform == 'darwin':
import _osx_support
@ -52,18 +59,19 @@ class UnixCCompiler(CCompiler):
# are pretty generic; they will probably have to be set by an outsider
# (eg. using information discovered by the sysconfig about building
# Python extensions).
executables = {'preprocessor' : None,
'compiler' : ["cc"],
'compiler_so' : ["cc"],
'compiler_cxx' : ["cc"],
'linker_so' : ["cc", "-shared"],
'linker_exe' : ["cc"],
'archiver' : ["ar", "-cr"],
'ranlib' : None,
}
executables = {
'preprocessor': None,
'compiler': ['cc'],
'compiler_so': ['cc'],
'compiler_cxx': ['cc'],
'linker_so': ['cc', '-shared'],
'linker_exe': ['cc'],
'archiver': ['ar', '-cr'],
'ranlib': None,
}
if sys.platform[:6] == "darwin":
executables['ranlib'] = ["ranlib"]
if sys.platform[:6] == 'darwin':
executables['ranlib'] = ['ranlib']
# Needed for the filename generation methods provided by the base
# class, CCompiler. NB. whoever instantiates/uses a particular
@ -71,19 +79,21 @@ class UnixCCompiler(CCompiler):
# reasonable common default here, but it's not necessarily used on all
# Unices!
src_extensions = [".c",".C",".cc",".cxx",".cpp",".m"]
obj_extension = ".o"
static_lib_extension = ".a"
shared_lib_extension = ".so"
dylib_lib_extension = ".dylib"
xcode_stub_lib_extension = ".tbd"
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
src_extensions = ['.c', '.C', '.cc', '.cxx', '.cpp', '.m']
obj_extension = '.o'
static_lib_extension = '.a'
shared_lib_extension = '.so'
dylib_lib_extension = '.dylib'
xcode_stub_lib_extension = '.tbd'
static_lib_format = shared_lib_format = dylib_lib_format = 'lib%s%s'
xcode_stub_lib_format = dylib_lib_format
if sys.platform == "cygwin":
exe_extension = ".exe"
if sys.platform == 'cygwin':
exe_extension = '.exe'
def preprocess(self, source, output_file=None, macros=None,
include_dirs=None, extra_preargs=None, extra_postargs=None):
def preprocess(
self, source, output_file=None, macros=None,
include_dirs=None, extra_preargs=None, extra_postargs=None,
):
fixed_args = self._fix_compile_args(None, macros, include_dirs)
ignore, macros, include_dirs = fixed_args
pp_opts = gen_preprocess_options(macros, include_dirs)
@ -111,16 +121,22 @@ class UnixCCompiler(CCompiler):
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
if sys.platform == 'darwin':
compiler_so = _osx_support.compiler_fixup(compiler_so,
cc_args + extra_postargs)
compiler_so = _osx_support.compiler_fixup(
compiler_so,
cc_args + extra_postargs,
)
try:
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
self.spawn(
compiler_so + cc_args + [src, '-o', obj] +
extra_postargs,
)
except DistutilsExecError as msg:
raise CompileError(msg)
def create_static_lib(self, objects, output_libname,
output_dir=None, debug=0, target_lang=None):
def create_static_lib(
self, objects, output_libname,
output_dir=None, debug=0, target_lang=None,
):
objects, output_dir = self._fix_object_args(objects, output_dir)
output_filename = \
@ -128,9 +144,11 @@ class UnixCCompiler(CCompiler):
if self._need_link(objects, output_filename):
self.mkpath(os.path.dirname(output_filename))
self.spawn(self.archiver +
[output_filename] +
objects + self.objects)
self.spawn(
self.archiver +
[output_filename] +
objects + self.objects,
)
# Not many Unices required ranlib anymore -- SunOS 4.x is, I
# think the only major Unix that does. Maybe we need some
@ -143,28 +161,36 @@ class UnixCCompiler(CCompiler):
except DistutilsExecError as msg:
raise LibError(msg)
else:
log.debug("skipping %s (up-to-date)", output_filename)
log.debug('skipping %s (up-to-date)', output_filename)
def link(self, target_desc, objects,
output_filename, output_dir=None, libraries=None,
library_dirs=None, runtime_library_dirs=None,
export_symbols=None, debug=0, extra_preargs=None,
extra_postargs=None, build_temp=None, target_lang=None):
def link(
self, target_desc, objects,
output_filename, output_dir=None, libraries=None,
library_dirs=None, runtime_library_dirs=None,
export_symbols=None, debug=0, extra_preargs=None,
extra_postargs=None, build_temp=None, target_lang=None,
):
objects, output_dir = self._fix_object_args(objects, output_dir)
fixed_args = self._fix_lib_args(libraries, library_dirs,
runtime_library_dirs)
fixed_args = self._fix_lib_args(
libraries, library_dirs,
runtime_library_dirs,
)
libraries, library_dirs, runtime_library_dirs = fixed_args
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries)
lib_opts = gen_lib_options(
self, library_dirs, runtime_library_dirs,
libraries,
)
if not isinstance(output_dir, (str, type(None))):
raise TypeError("'output_dir' must be a string or None")
if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename)
if self._need_link(objects, output_filename):
ld_args = (objects + self.objects +
lib_opts + ['-o', output_filename])
ld_args = (
objects + self.objects +
lib_opts + ['-o', output_filename]
)
if debug:
ld_args[:0] = ['-g']
if extra_preargs:
@ -177,14 +203,14 @@ class UnixCCompiler(CCompiler):
linker = self.linker_exe[:]
else:
linker = self.linker_so[:]
if target_lang == "c++" and self.compiler_cxx:
if target_lang == 'c++' and self.compiler_cxx:
# skip over environment variable settings if /usr/bin/env
# is used to set up the linker's environment.
# This is needed on OSX. Note: this assumes that the
# normal and C++ compiler have the same environment
# settings.
i = 0
if os.path.basename(linker[0]) == "env":
if os.path.basename(linker[0]) == 'env':
i = 1
while '=' in linker[i]:
i += 1
@ -196,7 +222,7 @@ class UnixCCompiler(CCompiler):
else:
offset = 0
linker[i+offset] = self.compiler_cxx[i]
linker[i + offset] = self.compiler_cxx[i]
if sys.platform == 'darwin':
linker = _osx_support.compiler_fixup(linker, ld_args)
@ -205,17 +231,17 @@ class UnixCCompiler(CCompiler):
except DistutilsExecError as msg:
raise LinkError(msg)
else:
log.debug("skipping %s (up-to-date)", output_filename)
log.debug('skipping %s (up-to-date)', output_filename)
# -- Miscellaneous methods -----------------------------------------
# These are all used by the 'gen_lib_options() function, in
# ccompiler.py.
def library_dir_option(self, dir):
return "-L" + dir
return '-L' + dir
def _is_gcc(self, compiler_name):
return "gcc" in compiler_name or "g++" in compiler_name
return 'gcc' in compiler_name or 'g++' in compiler_name
def runtime_library_dir_option(self, dir):
# XXX Hackish, at the very least. See Python bug #445902:
@ -231,40 +257,40 @@ class UnixCCompiler(CCompiler):
# this time, there's no way to determine this information from
# the configuration data stored in the Python installation, so
# we use this hack.
compiler = os.path.basename(shlex.split(sysconfig.get_config_var("CC"))[0])
if sys.platform[:6] == "darwin":
compiler = os.path.basename(shlex.split(sysconfig.get_config_var('CC'))[0])
if sys.platform[:6] == 'darwin':
from distutils.util import get_macosx_target_ver, split_version
macosx_target_ver = get_macosx_target_ver()
if macosx_target_ver and split_version(macosx_target_ver) >= [10, 5]:
return "-Wl,-rpath," + dir
else: # no support for -rpath on earlier macOS versions
return "-L" + dir
elif sys.platform[:7] == "freebsd":
return "-Wl,-rpath=" + dir
elif sys.platform[:5] == "hp-ux":
return '-Wl,-rpath,' + dir
else: # no support for -rpath on earlier macOS versions
return '-L' + dir
elif sys.platform[:7] == 'freebsd':
return '-Wl,-rpath=' + dir
elif sys.platform[:5] == 'hp-ux':
if self._is_gcc(compiler):
return ["-Wl,+s", "-L" + dir]
return ["+s", "-L" + dir]
return ['-Wl,+s', '-L' + dir]
return ['+s', '-L' + dir]
else:
if self._is_gcc(compiler):
# gcc on non-GNU systems does not need -Wl, but can
# use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably
# safest to keep doing so.
if sysconfig.get_config_var("GNULD") == "yes":
if sysconfig.get_config_var('GNULD') == 'yes':
# GNU ld needs an extra option to get a RUNPATH
# instead of just an RPATH.
return "-Wl,--enable-new-dtags,-R" + dir
return '-Wl,--enable-new-dtags,-R' + dir
else:
return "-Wl,-R" + dir
return '-Wl,-R' + dir
else:
# No idea how --enable-new-dtags would be passed on to
# ld if this system was using GNU ld. Don't know if a
# system like this even exists.
return "-R" + dir
return '-R' + dir
def library_option(self, lib):
return "-l" + lib
return '-l' + lib
def find_library_file(self, dirs, lib, debug=0):
shared_f = self.library_filename(lib, lib_type='shared')
@ -298,8 +324,6 @@ class UnixCCompiler(CCompiler):
else:
sysroot = m.group(1)
for dir in dirs:
shared = os.path.join(dir, shared_f)
dylib = os.path.join(dir, dylib_f)
@ -308,7 +332,9 @@ class UnixCCompiler(CCompiler):
if sys.platform == 'darwin' and (
dir.startswith('/System/') or (
dir.startswith('/usr/') and not dir.startswith('/usr/local/'))):
dir.startswith('/usr/') and not dir.startswith('/usr/local/')
)
):
shared = os.path.join(sysroot, dir[1:], shared_f)
dylib = os.path.join(sysroot, dir[1:], dylib_f)