mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-15 13:30:17 -06:00
Minor cleanups
This commit is contained in:
@@ -9,7 +9,6 @@ from pre_commit.languages import helpers
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'docker'
|
||||
@@ -97,8 +96,4 @@ def run_hook(prefix, hook, file_args): # pragma: windows no cover
|
||||
|
||||
entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
|
||||
cmd = docker_cmd() + entry_tag + cmd_rest
|
||||
return xargs(
|
||||
cmd,
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, cmd, file_args)
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages.docker import assert_docker_available
|
||||
from pre_commit.languages.docker import docker_cmd
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -16,8 +15,4 @@ install_environment = helpers.no_install
|
||||
def run_hook(prefix, hook, file_args): # pragma: windows no cover
|
||||
assert_docker_available()
|
||||
cmd = docker_cmd() + helpers.to_cmd(hook)
|
||||
return xargs(
|
||||
cmd,
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, cmd, file_args)
|
||||
|
||||
@@ -11,7 +11,6 @@ from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import rmtree
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'golangenv'
|
||||
@@ -81,8 +80,4 @@ def install_environment(prefix, version, additional_dependencies):
|
||||
|
||||
def run_hook(prefix, hook, file_args):
|
||||
with in_env(prefix):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -5,6 +5,7 @@ import os
|
||||
import shlex
|
||||
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
def run_setup_cmd(prefix, cmd):
|
||||
@@ -61,3 +62,7 @@ def target_concurrency(hook):
|
||||
return multiprocessing.cpu_count()
|
||||
except NotImplementedError:
|
||||
return 1
|
||||
|
||||
|
||||
def run_xargs(hook, cmd, file_args):
|
||||
return xargs(cmd, file_args, target_concurrency=target_concurrency(hook))
|
||||
|
||||
@@ -10,7 +10,6 @@ from pre_commit.languages import helpers
|
||||
from pre_commit.languages.python import bin_dir
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'node_env'
|
||||
@@ -71,8 +70,4 @@ def install_environment(prefix, version, additional_dependencies):
|
||||
|
||||
def run_hook(prefix, hook, file_args):
|
||||
with in_env(prefix, hook['language_version']):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -12,7 +12,6 @@ from pre_commit.parse_shebang import find_executable
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'py_env'
|
||||
@@ -127,11 +126,7 @@ def py_interface(_dir, _make_venv):
|
||||
|
||||
def run_hook(prefix, hook, file_args):
|
||||
with in_env(prefix, hook['language_version']):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
def install_environment(prefix, version, additional_dependencies):
|
||||
additional_dependencies = tuple(additional_dependencies)
|
||||
|
||||
@@ -12,7 +12,6 @@ from pre_commit.languages import helpers
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import resource_bytesio
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'rbenv'
|
||||
@@ -126,8 +125,4 @@ def install_environment(
|
||||
|
||||
def run_hook(prefix, hook, file_args): # pragma: windows no cover
|
||||
with in_env(prefix, hook['language_version']):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -10,7 +10,6 @@ from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = 'rustenv'
|
||||
@@ -91,8 +90,4 @@ def install_environment(prefix, version, additional_dependencies):
|
||||
|
||||
def run_hook(prefix, hook, file_args):
|
||||
with in_env(prefix):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -13,8 +12,4 @@ install_environment = helpers.no_install
|
||||
def run_hook(prefix, hook, file_args):
|
||||
cmd = helpers.to_cmd(hook)
|
||||
cmd = (prefix.path(cmd[0]),) + cmd[1:]
|
||||
return xargs(
|
||||
cmd,
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, cmd, file_args)
|
||||
|
||||
@@ -8,7 +8,6 @@ from pre_commit.envcontext import Var
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
ENVIRONMENT_DIR = 'swift_env'
|
||||
get_default_version = helpers.basic_get_default_version
|
||||
@@ -53,8 +52,4 @@ def install_environment(
|
||||
|
||||
def run_hook(prefix, hook, file_args): # pragma: windows no cover
|
||||
with in_env(prefix):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
@@ -11,8 +10,4 @@ install_environment = helpers.no_install
|
||||
|
||||
|
||||
def run_hook(prefix, hook, file_args):
|
||||
return xargs(
|
||||
helpers.to_cmd(hook),
|
||||
file_args,
|
||||
target_concurrency=helpers.target_concurrency(hook),
|
||||
)
|
||||
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
|
||||
|
||||
@@ -108,9 +108,8 @@ def xargs(cmd, varargs, **kwargs):
|
||||
def run_cmd_partition(run_cmd):
|
||||
return cmd_output(*run_cmd, encoding=None, retcode=None)
|
||||
|
||||
with _thread_mapper(
|
||||
min(len(partitions), target_concurrency),
|
||||
) as thread_map:
|
||||
threads = min(len(partitions), target_concurrency)
|
||||
with _thread_mapper(threads) as thread_map:
|
||||
results = thread_map(run_cmd_partition, partitions)
|
||||
|
||||
for proc_retcode, proc_out, proc_err in results:
|
||||
|
||||
Reference in New Issue
Block a user