mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-12 05:54:18 +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
|
|
@ -8,6 +8,7 @@ available.
|
|||
Written by: Fred L. Drake, Jr.
|
||||
Email: <fdrake@acm.org>
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import _imp
|
||||
import os
|
||||
|
|
@ -27,8 +28,8 @@ BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
|
|||
# Path to the base directory of the project. On Windows the binary may
|
||||
# live in project/PCbuild/win32 or project/PCbuild/amd64.
|
||||
# set for cross builds
|
||||
if "_PYTHON_PROJECT_BASE" in os.environ:
|
||||
project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"])
|
||||
if '_PYTHON_PROJECT_BASE' in os.environ:
|
||||
project_base = os.path.abspath(os.environ['_PYTHON_PROJECT_BASE'])
|
||||
else:
|
||||
if sys.executable:
|
||||
project_base = os.path.dirname(os.path.abspath(sys.executable))
|
||||
|
|
@ -42,27 +43,31 @@ else:
|
|||
# building an extension with an un-installed Python, so we use
|
||||
# different (hard-wired) directories.
|
||||
def _is_python_source_dir(d):
|
||||
for fn in ("Setup", "Setup.local"):
|
||||
if os.path.isfile(os.path.join(d, "Modules", fn)):
|
||||
for fn in ('Setup', 'Setup.local'):
|
||||
if os.path.isfile(os.path.join(d, 'Modules', fn)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
_sys_home = getattr(sys, '_home', None)
|
||||
|
||||
if os.name == 'nt':
|
||||
def _fix_pcbuild(d):
|
||||
if d and os.path.normcase(d).startswith(
|
||||
os.path.normcase(os.path.join(PREFIX, "PCbuild"))):
|
||||
os.path.normcase(os.path.join(PREFIX, 'PCbuild')),
|
||||
):
|
||||
return PREFIX
|
||||
return d
|
||||
project_base = _fix_pcbuild(project_base)
|
||||
_sys_home = _fix_pcbuild(_sys_home)
|
||||
|
||||
|
||||
def _python_build():
|
||||
if _sys_home:
|
||||
return _is_python_source_dir(_sys_home)
|
||||
return _is_python_source_dir(project_base)
|
||||
|
||||
|
||||
python_build = _python_build()
|
||||
|
||||
|
||||
|
|
@ -78,6 +83,7 @@ except AttributeError:
|
|||
# this attribute, which is fine.
|
||||
pass
|
||||
|
||||
|
||||
def get_python_version():
|
||||
"""Return a string containing the major and minor Python version,
|
||||
leaving off the patchlevel. Sample return values could be '1.5'
|
||||
|
|
@ -99,7 +105,7 @@ def get_python_inc(plat_specific=0, prefix=None):
|
|||
"""
|
||||
if prefix is None:
|
||||
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
|
||||
if os.name == "posix":
|
||||
if os.name == 'posix':
|
||||
if IS_PYPY and sys.version_info < (3, 8):
|
||||
return os.path.join(prefix, 'include')
|
||||
if python_build:
|
||||
|
|
@ -115,18 +121,21 @@ def get_python_inc(plat_specific=0, prefix=None):
|
|||
return os.path.normpath(incdir)
|
||||
implementation = 'pypy' if IS_PYPY else 'python'
|
||||
python_dir = implementation + get_python_version() + build_flags
|
||||
return os.path.join(prefix, "include", python_dir)
|
||||
elif os.name == "nt":
|
||||
return os.path.join(prefix, 'include', python_dir)
|
||||
elif os.name == 'nt':
|
||||
if python_build:
|
||||
# Include both the include and PC dir to ensure we can find
|
||||
# pyconfig.h
|
||||
return (os.path.join(prefix, "include") + os.path.pathsep +
|
||||
os.path.join(prefix, "PC"))
|
||||
return os.path.join(prefix, "include")
|
||||
return (
|
||||
os.path.join(prefix, 'include') + os.path.pathsep +
|
||||
os.path.join(prefix, 'PC')
|
||||
)
|
||||
return os.path.join(prefix, 'include')
|
||||
else:
|
||||
raise DistutilsPlatformError(
|
||||
"I don't know where Python installs its C header files "
|
||||
"on platform '%s'" % os.name)
|
||||
"on platform '%s'" % os.name,
|
||||
)
|
||||
|
||||
|
||||
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
||||
|
|
@ -149,7 +158,7 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
|||
if prefix is None:
|
||||
prefix = PREFIX
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "lib-python", sys.version[0])
|
||||
return os.path.join(prefix, 'lib-python', sys.version[0])
|
||||
return os.path.join(prefix, 'site-packages')
|
||||
|
||||
if prefix is None:
|
||||
|
|
@ -158,31 +167,33 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
|||
else:
|
||||
prefix = plat_specific and EXEC_PREFIX or PREFIX
|
||||
|
||||
if os.name == "posix":
|
||||
if os.name == 'posix':
|
||||
if plat_specific or standard_lib:
|
||||
# Platform-specific modules (any module from a non-pure-Python
|
||||
# module distribution) or standard Python library modules.
|
||||
libdir = getattr(sys, "platlibdir", "lib")
|
||||
libdir = getattr(sys, 'platlibdir', 'lib')
|
||||
else:
|
||||
# Pure Python
|
||||
libdir = "lib"
|
||||
libdir = 'lib'
|
||||
implementation = 'pypy' if IS_PYPY else 'python'
|
||||
libpython = os.path.join(prefix, libdir,
|
||||
implementation + get_python_version())
|
||||
libpython = os.path.join(
|
||||
prefix, libdir,
|
||||
implementation + get_python_version(),
|
||||
)
|
||||
if standard_lib:
|
||||
return libpython
|
||||
else:
|
||||
return os.path.join(libpython, "site-packages")
|
||||
elif os.name == "nt":
|
||||
return os.path.join(libpython, 'site-packages')
|
||||
elif os.name == 'nt':
|
||||
if standard_lib:
|
||||
return os.path.join(prefix, "Lib")
|
||||
return os.path.join(prefix, 'Lib')
|
||||
else:
|
||||
return os.path.join(prefix, "Lib", "site-packages")
|
||||
return os.path.join(prefix, 'Lib', 'site-packages')
|
||||
else:
|
||||
raise DistutilsPlatformError(
|
||||
"I don't know where Python installs its library "
|
||||
"on platform '%s'" % os.name)
|
||||
|
||||
"on platform '%s'" % os.name,
|
||||
)
|
||||
|
||||
|
||||
def customize_compiler(compiler):
|
||||
|
|
@ -191,8 +202,8 @@ def customize_compiler(compiler):
|
|||
Mainly needed on Unix, so we can plug in the information that
|
||||
varies across Unices and is stored in Python's Makefile.
|
||||
"""
|
||||
if compiler.compiler_type == "unix":
|
||||
if sys.platform == "darwin":
|
||||
if compiler.compiler_type == 'unix':
|
||||
if sys.platform == 'darwin':
|
||||
# Perform first-time customization of compiler-related
|
||||
# config vars on OS X now that we know we need a compiler.
|
||||
# This is primarily to support Pythons from binary
|
||||
|
|
@ -209,13 +220,17 @@ def customize_compiler(compiler):
|
|||
_config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
|
||||
|
||||
(cc, cxx, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \
|
||||
get_config_vars('CC', 'CXX', 'CFLAGS',
|
||||
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS')
|
||||
get_config_vars(
|
||||
'CC', 'CXX', 'CFLAGS',
|
||||
'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS',
|
||||
)
|
||||
|
||||
if 'CC' in os.environ:
|
||||
newcc = os.environ['CC']
|
||||
if('LDSHARED' not in os.environ
|
||||
and ldshared.startswith(cc)):
|
||||
if (
|
||||
'LDSHARED' not in os.environ and
|
||||
ldshared.startswith(cc)
|
||||
):
|
||||
# If CC is overridden, use that as the default
|
||||
# command for LDSHARED as well
|
||||
ldshared = newcc + ldshared[len(cc):]
|
||||
|
|
@ -227,7 +242,7 @@ def customize_compiler(compiler):
|
|||
if 'CPP' in os.environ:
|
||||
cpp = os.environ['CPP']
|
||||
else:
|
||||
cpp = cc + " -E" # not always
|
||||
cpp = cc + ' -E' # not always
|
||||
if 'LDFLAGS' in os.environ:
|
||||
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
|
||||
if 'CFLAGS' in os.environ:
|
||||
|
|
@ -252,7 +267,8 @@ def customize_compiler(compiler):
|
|||
compiler_cxx=cxx,
|
||||
linker_so=ldshared,
|
||||
linker_exe=cc,
|
||||
archiver=archiver)
|
||||
archiver=archiver,
|
||||
)
|
||||
|
||||
if 'RANLIB' in os.environ and compiler.executables.get('ranlib', None):
|
||||
compiler.set_executables(ranlib=os.environ['RANLIB'])
|
||||
|
|
@ -263,8 +279,8 @@ def customize_compiler(compiler):
|
|||
def get_config_h_filename():
|
||||
"""Return full pathname of installed pyconfig.h file."""
|
||||
if python_build:
|
||||
if os.name == "nt":
|
||||
inc_dir = os.path.join(_sys_home or project_base, "PC")
|
||||
if os.name == 'nt':
|
||||
inc_dir = os.path.join(_sys_home or project_base, 'PC')
|
||||
else:
|
||||
inc_dir = _sys_home or project_base
|
||||
else:
|
||||
|
|
@ -276,9 +292,9 @@ def get_config_h_filename():
|
|||
def get_makefile_filename():
|
||||
"""Return full pathname of installed Makefile from the Python build."""
|
||||
if python_build:
|
||||
return os.path.join(_sys_home or project_base, "Makefile")
|
||||
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)
|
||||
config_file = f'config-{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')
|
||||
|
|
@ -293,8 +309,8 @@ def parse_config_h(fp, g=None):
|
|||
"""
|
||||
if g is None:
|
||||
g = {}
|
||||
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
|
||||
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
|
||||
define_rx = re.compile('#define ([A-Z][A-Za-z0-9_]+) (.*)\n')
|
||||
undef_rx = re.compile('/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n')
|
||||
#
|
||||
while True:
|
||||
line = fp.readline()
|
||||
|
|
@ -303,8 +319,10 @@ def parse_config_h(fp, g=None):
|
|||
m = define_rx.match(line)
|
||||
if m:
|
||||
n, v = m.group(1, 2)
|
||||
try: v = int(v)
|
||||
except ValueError: pass
|
||||
try:
|
||||
v = int(v)
|
||||
except ValueError:
|
||||
pass
|
||||
g[n] = v
|
||||
else:
|
||||
m = undef_rx.match(line)
|
||||
|
|
@ -315,9 +333,10 @@ def parse_config_h(fp, g=None):
|
|||
|
||||
# Regexes needed for parsing Makefile (and similar syntaxes,
|
||||
# like old-style Setup files).
|
||||
_variable_rx = re.compile(r"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
|
||||
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
|
||||
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
|
||||
_variable_rx = re.compile(r'([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)')
|
||||
_findvar1_rx = re.compile(r'\$\(([A-Za-z][A-Za-z0-9_]*)\)')
|
||||
_findvar2_rx = re.compile(r'\${([A-Za-z][A-Za-z0-9_]*)}')
|
||||
|
||||
|
||||
def parse_makefile(fn, g=None):
|
||||
"""Parse a Makefile-style file.
|
||||
|
|
@ -327,7 +346,7 @@ def parse_makefile(fn, g=None):
|
|||
used instead of a new dictionary.
|
||||
"""
|
||||
from distutils.text_file import TextFile
|
||||
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors="surrogateescape")
|
||||
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1, errors='surrogateescape')
|
||||
|
||||
if g is None:
|
||||
g = {}
|
||||
|
|
@ -336,7 +355,7 @@ def parse_makefile(fn, g=None):
|
|||
|
||||
while True:
|
||||
line = fp.readline()
|
||||
if line is None: # eof
|
||||
if line is None: # eof
|
||||
break
|
||||
m = _variable_rx.match(line)
|
||||
if m:
|
||||
|
|
@ -345,7 +364,7 @@ def parse_makefile(fn, g=None):
|
|||
# `$$' is a literal `$' in make
|
||||
tmpv = v.replace('$$', '')
|
||||
|
||||
if "$" in tmpv:
|
||||
if '$' in tmpv:
|
||||
notdone[n] = v
|
||||
else:
|
||||
try:
|
||||
|
|
@ -381,7 +400,7 @@ def parse_makefile(fn, g=None):
|
|||
|
||||
elif n in renamed_variables:
|
||||
if name.startswith('PY_') and name[3:] in renamed_variables:
|
||||
item = ""
|
||||
item = ''
|
||||
|
||||
elif 'PY_' + n in notdone:
|
||||
found = False
|
||||
|
|
@ -389,14 +408,15 @@ def parse_makefile(fn, g=None):
|
|||
else:
|
||||
item = str(done['PY_' + n])
|
||||
else:
|
||||
done[n] = item = ""
|
||||
done[n] = item = ''
|
||||
if found:
|
||||
after = value[m.end():]
|
||||
value = value[:m.start()] + item + after
|
||||
if "$" in after:
|
||||
if '$' in after:
|
||||
notdone[name] = value
|
||||
else:
|
||||
try: value = int(value)
|
||||
try:
|
||||
value = int(value)
|
||||
except ValueError:
|
||||
done[name] = value.strip()
|
||||
else:
|
||||
|
|
@ -404,7 +424,7 @@ def parse_makefile(fn, g=None):
|
|||
del notdone[name]
|
||||
|
||||
if name.startswith('PY_') \
|
||||
and name[3:] in renamed_variables:
|
||||
and name[3:] in renamed_variables:
|
||||
|
||||
name = name[3:]
|
||||
if name not in done:
|
||||
|
|
@ -452,21 +472,25 @@ def expand_makefile_vars(s, vars):
|
|||
|
||||
_config_vars = None
|
||||
|
||||
|
||||
def _init_posix():
|
||||
"""Initialize the module as appropriate for POSIX systems."""
|
||||
# _sysconfigdata is generated at build time, see the sysconfig module
|
||||
name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME',
|
||||
name = os.environ.get(
|
||||
'_PYTHON_SYSCONFIGDATA_NAME',
|
||||
'_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
|
||||
abi=sys.abiflags,
|
||||
platform=sys.platform,
|
||||
multiarch=getattr(sys.implementation, '_multiarch', ''),
|
||||
))
|
||||
abi=sys.abiflags,
|
||||
platform=sys.platform,
|
||||
multiarch=getattr(sys.implementation, '_multiarch', ''),
|
||||
),
|
||||
)
|
||||
try:
|
||||
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
|
||||
except ImportError:
|
||||
# Python 3.5 and pypy 7.3.1
|
||||
_temp = __import__(
|
||||
'_sysconfigdata', globals(), locals(), ['build_time_vars'], 0)
|
||||
'_sysconfigdata', globals(), locals(), ['build_time_vars'], 0,
|
||||
)
|
||||
build_time_vars = _temp.build_time_vars
|
||||
global _config_vars
|
||||
_config_vars = {}
|
||||
|
|
@ -484,8 +508,8 @@ def _init_nt():
|
|||
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
|
||||
|
||||
g['EXT_SUFFIX'] = _imp.extension_suffixes()[0]
|
||||
g['EXE'] = ".exe"
|
||||
g['VERSION'] = get_python_version().replace(".", "")
|
||||
g['EXE'] = '.exe'
|
||||
g['VERSION'] = get_python_version().replace('.', '')
|
||||
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
|
||||
|
||||
global _config_vars
|
||||
|
|
@ -504,7 +528,7 @@ def get_config_vars(*args):
|
|||
"""
|
||||
global _config_vars
|
||||
if _config_vars is None:
|
||||
func = globals().get("_init_" + os.name)
|
||||
func = globals().get('_init_' + os.name)
|
||||
if func:
|
||||
func()
|
||||
else:
|
||||
|
|
@ -543,10 +567,12 @@ def get_config_vars(*args):
|
|||
# Normally it is relative to the build directory. However, during
|
||||
# testing, for example, we might be running a non-installed python
|
||||
# from a different directory.
|
||||
if python_build and os.name == "posix":
|
||||
if python_build and os.name == 'posix':
|
||||
base = project_base
|
||||
if (not os.path.isabs(_config_vars['srcdir']) and
|
||||
base != os.getcwd()):
|
||||
if (
|
||||
not os.path.isabs(_config_vars['srcdir']) and
|
||||
base != os.getcwd()
|
||||
):
|
||||
# srcdir is relative and we are not in the same directory
|
||||
# as the executable. Assume executable is in the build
|
||||
# directory and make srcdir absolute.
|
||||
|
|
@ -567,6 +593,7 @@ def get_config_vars(*args):
|
|||
else:
|
||||
return _config_vars
|
||||
|
||||
|
||||
def get_config_var(name):
|
||||
"""Return the value of a single variable using the dictionary
|
||||
returned by 'get_config_vars()'. Equivalent to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue