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
|
|
@ -25,27 +25,29 @@ bug reports or API stability):
|
|||
|
||||
Again, this is not a formal definition! Just a "taste" of the module.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import tokenize
|
||||
import shutil
|
||||
import contextlib
|
||||
import sys
|
||||
import tempfile
|
||||
import tokenize
|
||||
|
||||
import setuptools
|
||||
import distutils
|
||||
|
||||
import setuptools
|
||||
from pkg_resources import parse_requirements
|
||||
|
||||
__all__ = ['get_requires_for_build_sdist',
|
||||
'get_requires_for_build_wheel',
|
||||
'prepare_metadata_for_build_wheel',
|
||||
'build_wheel',
|
||||
'build_sdist',
|
||||
'__legacy__',
|
||||
'SetupRequirementsError']
|
||||
__all__ = [
|
||||
'get_requires_for_build_sdist',
|
||||
'get_requires_for_build_wheel',
|
||||
'prepare_metadata_for_build_wheel',
|
||||
'build_wheel',
|
||||
'build_sdist',
|
||||
'__legacy__',
|
||||
'SetupRequirementsError',
|
||||
]
|
||||
|
||||
|
||||
class SetupRequirementsError(BaseException):
|
||||
|
|
@ -92,8 +94,10 @@ def no_install_setup_requires():
|
|||
|
||||
|
||||
def _get_immediate_subdirectories(a_dir):
|
||||
return [name for name in os.listdir(a_dir)
|
||||
if os.path.isdir(os.path.join(a_dir, name))]
|
||||
return [
|
||||
name for name in os.listdir(a_dir)
|
||||
if os.path.isdir(os.path.join(a_dir, name))
|
||||
]
|
||||
|
||||
|
||||
def _file_with_extension(directory, extension):
|
||||
|
|
@ -106,19 +110,20 @@ def _file_with_extension(directory, extension):
|
|||
except ValueError:
|
||||
raise ValueError(
|
||||
'No distribution was found. Ensure that `setup.py` '
|
||||
'is not empty and that it calls `setup()`.')
|
||||
'is not empty and that it calls `setup()`.',
|
||||
)
|
||||
return file
|
||||
|
||||
|
||||
def _open_setup_script(setup_script):
|
||||
if not os.path.exists(setup_script):
|
||||
# Supply a default setup.py
|
||||
return io.StringIO(u"from setuptools import setup; setup()")
|
||||
return io.StringIO('from setuptools import setup; setup()')
|
||||
|
||||
return getattr(tokenize, 'open', open)(setup_script)
|
||||
|
||||
|
||||
class _BuildMetaBackend(object):
|
||||
class _BuildMetaBackend:
|
||||
|
||||
def _fix_config(self, config_settings):
|
||||
config_settings = config_settings or {}
|
||||
|
|
@ -129,7 +134,7 @@ class _BuildMetaBackend(object):
|
|||
config_settings = self._fix_config(config_settings)
|
||||
|
||||
sys.argv = sys.argv[:1] + ['egg_info'] + \
|
||||
config_settings["--global-option"]
|
||||
config_settings['--global-option']
|
||||
try:
|
||||
with Distribution.patch():
|
||||
self.run_setup()
|
||||
|
|
@ -152,23 +157,29 @@ class _BuildMetaBackend(object):
|
|||
def get_requires_for_build_wheel(self, config_settings=None):
|
||||
config_settings = self._fix_config(config_settings)
|
||||
return self._get_build_requires(
|
||||
config_settings, requirements=['wheel'])
|
||||
config_settings, requirements=['wheel'],
|
||||
)
|
||||
|
||||
def get_requires_for_build_sdist(self, config_settings=None):
|
||||
config_settings = self._fix_config(config_settings)
|
||||
return self._get_build_requires(config_settings, requirements=[])
|
||||
|
||||
def prepare_metadata_for_build_wheel(self, metadata_directory,
|
||||
config_settings=None):
|
||||
def prepare_metadata_for_build_wheel(
|
||||
self, metadata_directory,
|
||||
config_settings=None,
|
||||
):
|
||||
sys.argv = sys.argv[:1] + [
|
||||
'dist_info', '--egg-base', metadata_directory]
|
||||
'dist_info', '--egg-base', metadata_directory,
|
||||
]
|
||||
with no_install_setup_requires():
|
||||
self.run_setup()
|
||||
|
||||
dist_info_directory = metadata_directory
|
||||
while True:
|
||||
dist_infos = [f for f in os.listdir(dist_info_directory)
|
||||
if f.endswith('.dist-info')]
|
||||
dist_infos = [
|
||||
f for f in os.listdir(dist_info_directory)
|
||||
if f.endswith('.dist-info')
|
||||
]
|
||||
|
||||
if (
|
||||
len(dist_infos) == 0 and
|
||||
|
|
@ -176,7 +187,8 @@ class _BuildMetaBackend(object):
|
|||
):
|
||||
|
||||
dist_info_directory = os.path.join(
|
||||
dist_info_directory, os.listdir(dist_info_directory)[0])
|
||||
dist_info_directory, os.listdir(dist_info_directory)[0],
|
||||
)
|
||||
continue
|
||||
|
||||
assert len(dist_infos) == 1
|
||||
|
|
@ -187,27 +199,33 @@ class _BuildMetaBackend(object):
|
|||
if dist_info_directory != metadata_directory:
|
||||
shutil.move(
|
||||
os.path.join(dist_info_directory, dist_infos[0]),
|
||||
metadata_directory)
|
||||
metadata_directory,
|
||||
)
|
||||
shutil.rmtree(dist_info_directory, ignore_errors=True)
|
||||
|
||||
return dist_infos[0]
|
||||
|
||||
def _build_with_temp_dir(self, setup_command, result_extension,
|
||||
result_directory, config_settings):
|
||||
def _build_with_temp_dir(
|
||||
self, setup_command, result_extension,
|
||||
result_directory, config_settings,
|
||||
):
|
||||
config_settings = self._fix_config(config_settings)
|
||||
result_directory = os.path.abspath(result_directory)
|
||||
|
||||
# Build in a temporary directory, then copy to the target.
|
||||
os.makedirs(result_directory, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(dir=result_directory) as tmp_dist_dir:
|
||||
sys.argv = (sys.argv[:1] + setup_command +
|
||||
['--dist-dir', tmp_dist_dir] +
|
||||
config_settings["--global-option"])
|
||||
sys.argv = (
|
||||
sys.argv[:1] + setup_command +
|
||||
['--dist-dir', tmp_dist_dir] +
|
||||
config_settings['--global-option']
|
||||
)
|
||||
with no_install_setup_requires():
|
||||
self.run_setup()
|
||||
|
||||
result_basename = _file_with_extension(
|
||||
tmp_dist_dir, result_extension)
|
||||
tmp_dist_dir, result_extension,
|
||||
)
|
||||
result_path = os.path.join(result_directory, result_basename)
|
||||
if os.path.exists(result_path):
|
||||
# os.rename will fail overwriting on non-Unix.
|
||||
|
|
@ -216,15 +234,21 @@ class _BuildMetaBackend(object):
|
|||
|
||||
return result_basename
|
||||
|
||||
def build_wheel(self, wheel_directory, config_settings=None,
|
||||
metadata_directory=None):
|
||||
return self._build_with_temp_dir(['bdist_wheel'], '.whl',
|
||||
wheel_directory, config_settings)
|
||||
def build_wheel(
|
||||
self, wheel_directory, config_settings=None,
|
||||
metadata_directory=None,
|
||||
):
|
||||
return self._build_with_temp_dir(
|
||||
['bdist_wheel'], '.whl',
|
||||
wheel_directory, config_settings,
|
||||
)
|
||||
|
||||
def build_sdist(self, sdist_directory, config_settings=None):
|
||||
return self._build_with_temp_dir(['sdist', '--formats', 'gztar'],
|
||||
'.tar.gz', sdist_directory,
|
||||
config_settings)
|
||||
return self._build_with_temp_dir(
|
||||
['sdist', '--formats', 'gztar'],
|
||||
'.tar.gz', sdist_directory,
|
||||
config_settings,
|
||||
)
|
||||
|
||||
|
||||
class _BuildMetaLegacyBackend(_BuildMetaBackend):
|
||||
|
|
@ -238,6 +262,7 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend):
|
|||
packaging mechanism,
|
||||
and will eventually be removed.
|
||||
"""
|
||||
|
||||
def run_setup(self, setup_script='setup.py'):
|
||||
# In order to maintain compatibility with scripts assuming that
|
||||
# the setup.py script is in a directory on the PYTHONPATH, inject
|
||||
|
|
@ -255,8 +280,7 @@ class _BuildMetaLegacyBackend(_BuildMetaBackend):
|
|||
sys.argv[0] = setup_script
|
||||
|
||||
try:
|
||||
super(_BuildMetaLegacyBackend,
|
||||
self).run_setup(setup_script=setup_script)
|
||||
super().run_setup(setup_script=setup_script)
|
||||
finally:
|
||||
# While PEP 517 frontends should be calling each hook in a fresh
|
||||
# subprocess according to the standard (and thus it should not be
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue