mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 12:54:17 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,14 +1,17 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import itertools
|
||||
import os
|
||||
import sys
|
||||
import itertools
|
||||
from importlib.machinery import EXTENSION_SUFFIXES
|
||||
from distutils.command.build_ext import build_ext as _du_build_ext
|
||||
from distutils.file_util import copy_file
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.sysconfig import customize_compiler, get_config_var
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils import log
|
||||
|
||||
from distutils import log
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.command.build_ext import build_ext as _du_build_ext
|
||||
from distutils.errors import DistutilsError
|
||||
from distutils.file_util import copy_file
|
||||
from distutils.sysconfig import customize_compiler
|
||||
from distutils.sysconfig import get_config_var
|
||||
from setuptools.extension import Library
|
||||
|
||||
try:
|
||||
|
|
@ -21,12 +24,12 @@ except ImportError:
|
|||
_build_ext = _du_build_ext
|
||||
|
||||
# make sure _config_vars is initialized
|
||||
get_config_var("LDSHARED")
|
||||
get_config_var('LDSHARED')
|
||||
from distutils.sysconfig import _config_vars as _CONFIG_VARS # noqa
|
||||
|
||||
|
||||
def _customize_compiler_for_shlib(compiler):
|
||||
if sys.platform == "darwin":
|
||||
if sys.platform == 'darwin':
|
||||
# building .dylib requires additional compiler flags on OSX; here we
|
||||
# temporarily substitute the pyconfig.h variables so that distutils'
|
||||
# 'customize_compiler' uses them before we build the shared libraries.
|
||||
|
|
@ -34,9 +37,10 @@ def _customize_compiler_for_shlib(compiler):
|
|||
try:
|
||||
# XXX Help! I don't have any idea whether these are right...
|
||||
_CONFIG_VARS['LDSHARED'] = (
|
||||
"gcc -Wl,-x -dynamiclib -undefined dynamic_lookup")
|
||||
_CONFIG_VARS['CCSHARED'] = " -dynamiclib"
|
||||
_CONFIG_VARS['SO'] = ".dylib"
|
||||
'gcc -Wl,-x -dynamiclib -undefined dynamic_lookup'
|
||||
)
|
||||
_CONFIG_VARS['CCSHARED'] = ' -dynamiclib'
|
||||
_CONFIG_VARS['SO'] = '.dylib'
|
||||
customize_compiler(compiler)
|
||||
finally:
|
||||
_CONFIG_VARS.clear()
|
||||
|
|
@ -49,7 +53,7 @@ have_rtld = False
|
|||
use_stubs = False
|
||||
libtype = 'shared'
|
||||
|
||||
if sys.platform == "darwin":
|
||||
if sys.platform == 'darwin':
|
||||
use_stubs = True
|
||||
elif os.name != 'nt':
|
||||
try:
|
||||
|
|
@ -89,8 +93,10 @@ class build_ext(_build_ext):
|
|||
modpath = fullname.split('.')
|
||||
package = '.'.join(modpath[:-1])
|
||||
package_dir = build_py.get_package_dir(package)
|
||||
dest_filename = os.path.join(package_dir,
|
||||
os.path.basename(filename))
|
||||
dest_filename = os.path.join(
|
||||
package_dir,
|
||||
os.path.basename(filename),
|
||||
)
|
||||
src_filename = os.path.join(self.build_lib, filename)
|
||||
|
||||
# Always copy, even if source is older than destination, to ensure
|
||||
|
|
@ -98,7 +104,7 @@ class build_ext(_build_ext):
|
|||
# used.
|
||||
copy_file(
|
||||
src_filename, dest_filename, verbose=self.verbose,
|
||||
dry_run=self.dry_run
|
||||
dry_run=self.dry_run,
|
||||
)
|
||||
if ext._needs_stub:
|
||||
self.write_stub(package_dir or os.curdir, ext, True)
|
||||
|
|
@ -136,8 +142,10 @@ class build_ext(_build_ext):
|
|||
_build_ext.finalize_options(self)
|
||||
self.extensions = self.extensions or []
|
||||
self.check_extensions_list(self.extensions)
|
||||
self.shlibs = [ext for ext in self.extensions
|
||||
if isinstance(ext, Library)]
|
||||
self.shlibs = [
|
||||
ext for ext in self.extensions
|
||||
if isinstance(ext, Library)
|
||||
]
|
||||
if self.shlibs:
|
||||
self.setup_shlib_compiler()
|
||||
for ext in self.extensions:
|
||||
|
|
@ -163,7 +171,7 @@ class build_ext(_build_ext):
|
|||
|
||||
def setup_shlib_compiler(self):
|
||||
compiler = self.shlib_compiler = new_compiler(
|
||||
compiler=self.compiler, dry_run=self.dry_run, force=self.force
|
||||
compiler=self.compiler, dry_run=self.dry_run, force=self.force,
|
||||
)
|
||||
_customize_compiler_for_shlib(compiler)
|
||||
|
||||
|
|
@ -236,52 +244,60 @@ class build_ext(_build_ext):
|
|||
yield '.pyo'
|
||||
|
||||
def write_stub(self, output_dir, ext, compile=False):
|
||||
log.info("writing stub loader for %s to %s", ext._full_name,
|
||||
output_dir)
|
||||
stub_file = (os.path.join(output_dir, *ext._full_name.split('.')) +
|
||||
'.py')
|
||||
log.info(
|
||||
'writing stub loader for %s to %s', ext._full_name,
|
||||
output_dir,
|
||||
)
|
||||
stub_file = (
|
||||
os.path.join(output_dir, *ext._full_name.split('.')) +
|
||||
'.py'
|
||||
)
|
||||
if compile and os.path.exists(stub_file):
|
||||
raise DistutilsError(stub_file + " already exists! Please delete.")
|
||||
raise DistutilsError(stub_file + ' already exists! Please delete.')
|
||||
if not self.dry_run:
|
||||
f = open(stub_file, 'w')
|
||||
f.write(
|
||||
'\n'.join([
|
||||
"def __bootstrap__():",
|
||||
" global __bootstrap__, __file__, __loader__",
|
||||
" import sys, os, pkg_resources, importlib.util" +
|
||||
if_dl(", dl"),
|
||||
" __file__ = pkg_resources.resource_filename"
|
||||
"(__name__,%r)"
|
||||
'def __bootstrap__():',
|
||||
' global __bootstrap__, __file__, __loader__',
|
||||
' import sys, os, pkg_resources, importlib.util' +
|
||||
if_dl(', dl'),
|
||||
' __file__ = pkg_resources.resource_filename'
|
||||
'(__name__,%r)'
|
||||
% os.path.basename(ext._file_name),
|
||||
" del __bootstrap__",
|
||||
' del __bootstrap__',
|
||||
" if '__loader__' in globals():",
|
||||
" del __loader__",
|
||||
if_dl(" old_flags = sys.getdlopenflags()"),
|
||||
" old_dir = os.getcwd()",
|
||||
" try:",
|
||||
" os.chdir(os.path.dirname(__file__))",
|
||||
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
|
||||
" spec = importlib.util.spec_from_file_location(",
|
||||
" __name__, __file__)",
|
||||
" mod = importlib.util.module_from_spec(spec)",
|
||||
" spec.loader.exec_module(mod)",
|
||||
" finally:",
|
||||
if_dl(" sys.setdlopenflags(old_flags)"),
|
||||
" os.chdir(old_dir)",
|
||||
"__bootstrap__()",
|
||||
"" # terminal \n
|
||||
])
|
||||
' del __loader__',
|
||||
if_dl(' old_flags = sys.getdlopenflags()'),
|
||||
' old_dir = os.getcwd()',
|
||||
' try:',
|
||||
' os.chdir(os.path.dirname(__file__))',
|
||||
if_dl(' sys.setdlopenflags(dl.RTLD_NOW)'),
|
||||
' spec = importlib.util.spec_from_file_location(',
|
||||
' __name__, __file__)',
|
||||
' mod = importlib.util.module_from_spec(spec)',
|
||||
' spec.loader.exec_module(mod)',
|
||||
' finally:',
|
||||
if_dl(' sys.setdlopenflags(old_flags)'),
|
||||
' os.chdir(old_dir)',
|
||||
'__bootstrap__()',
|
||||
'', # terminal \n
|
||||
]),
|
||||
)
|
||||
f.close()
|
||||
if compile:
|
||||
from distutils.util import byte_compile
|
||||
|
||||
byte_compile([stub_file], optimize=0,
|
||||
force=True, dry_run=self.dry_run)
|
||||
byte_compile(
|
||||
[stub_file], optimize=0,
|
||||
force=True, dry_run=self.dry_run,
|
||||
)
|
||||
optimize = self.get_finalized_command('install_lib').optimize
|
||||
if optimize > 0:
|
||||
byte_compile([stub_file], optimize=optimize,
|
||||
force=True, dry_run=self.dry_run)
|
||||
byte_compile(
|
||||
[stub_file], optimize=optimize,
|
||||
force=True, dry_run=self.dry_run,
|
||||
)
|
||||
if os.path.exists(stub_file) and not self.dry_run:
|
||||
os.unlink(stub_file)
|
||||
|
||||
|
|
@ -293,12 +309,13 @@ if use_stubs or os.name == 'nt':
|
|||
self, objects, output_libname, 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):
|
||||
target_lang=None,
|
||||
):
|
||||
self.link(
|
||||
self.SHARED_LIBRARY, objects, output_libname,
|
||||
output_dir, libraries, library_dirs, runtime_library_dirs,
|
||||
export_symbols, debug, extra_preargs, extra_postargs,
|
||||
build_temp, target_lang
|
||||
build_temp, target_lang,
|
||||
)
|
||||
else:
|
||||
# Build static libraries everywhere else
|
||||
|
|
@ -308,7 +325,8 @@ else:
|
|||
self, objects, output_libname, 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):
|
||||
target_lang=None,
|
||||
):
|
||||
# XXX we need to either disallow these attrs on Library instances,
|
||||
# or warn/abort here if set, or something...
|
||||
# libraries=None, library_dirs=None, runtime_library_dirs=None,
|
||||
|
|
@ -318,11 +336,11 @@ else:
|
|||
assert output_dir is None # distutils build_ext doesn't pass this
|
||||
output_dir, filename = os.path.split(output_libname)
|
||||
basename, ext = os.path.splitext(filename)
|
||||
if self.library_filename("x").startswith('lib'):
|
||||
if self.library_filename('x').startswith('lib'):
|
||||
# strip 'lib' prefix; this is kludgy if some platform uses
|
||||
# a different prefix
|
||||
basename = basename[3:]
|
||||
|
||||
self.create_static_lib(
|
||||
objects, basename, output_dir, debug, target_lang
|
||||
objects, basename, output_dir, debug, target_lang,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue