Minor cleanups

This commit is contained in:
Anthony Sottile 2018-11-01 18:05:36 -07:00
parent 9125439c3a
commit 6bac405d40
12 changed files with 17 additions and 63 deletions

View file

@ -9,7 +9,6 @@ from pre_commit.languages import helpers
from pre_commit.util import CalledProcessError from pre_commit.util import CalledProcessError
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'docker' 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)) entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
cmd = docker_cmd() + entry_tag + cmd_rest cmd = docker_cmd() + entry_tag + cmd_rest
return xargs( return helpers.run_xargs(hook, cmd, file_args)
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -4,7 +4,6 @@ from __future__ import unicode_literals
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.languages.docker import assert_docker_available from pre_commit.languages.docker import assert_docker_available
from pre_commit.languages.docker import docker_cmd from pre_commit.languages.docker import docker_cmd
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = None ENVIRONMENT_DIR = None
@ -16,8 +15,4 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args): # pragma: windows no cover def run_hook(prefix, hook, file_args): # pragma: windows no cover
assert_docker_available() assert_docker_available()
cmd = docker_cmd() + helpers.to_cmd(hook) cmd = docker_cmd() + helpers.to_cmd(hook)
return xargs( return helpers.run_xargs(hook, cmd, file_args)
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -11,7 +11,6 @@ from pre_commit.languages import helpers
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.util import rmtree from pre_commit.util import rmtree
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'golangenv' ENVIRONMENT_DIR = 'golangenv'
@ -81,8 +80,4 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
with in_env(prefix): with in_env(prefix):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -5,6 +5,7 @@ import os
import shlex import shlex
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
def run_setup_cmd(prefix, cmd): def run_setup_cmd(prefix, cmd):
@ -61,3 +62,7 @@ def target_concurrency(hook):
return multiprocessing.cpu_count() return multiprocessing.cpu_count()
except NotImplementedError: except NotImplementedError:
return 1 return 1
def run_xargs(hook, cmd, file_args):
return xargs(cmd, file_args, target_concurrency=target_concurrency(hook))

View file

@ -10,7 +10,6 @@ from pre_commit.languages import helpers
from pre_commit.languages.python import bin_dir from pre_commit.languages.python import bin_dir
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'node_env' ENVIRONMENT_DIR = 'node_env'
@ -71,8 +70,4 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
with in_env(prefix, hook['language_version']): with in_env(prefix, hook['language_version']):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -12,7 +12,6 @@ from pre_commit.parse_shebang import find_executable
from pre_commit.util import CalledProcessError from pre_commit.util import CalledProcessError
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'py_env' ENVIRONMENT_DIR = 'py_env'
@ -127,11 +126,7 @@ def py_interface(_dir, _make_venv):
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
with in_env(prefix, hook['language_version']): with in_env(prefix, hook['language_version']):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)
def install_environment(prefix, version, additional_dependencies): def install_environment(prefix, version, additional_dependencies):
additional_dependencies = tuple(additional_dependencies) additional_dependencies = tuple(additional_dependencies)

View file

@ -12,7 +12,6 @@ from pre_commit.languages import helpers
from pre_commit.util import CalledProcessError from pre_commit.util import CalledProcessError
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import resource_bytesio from pre_commit.util import resource_bytesio
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'rbenv' ENVIRONMENT_DIR = 'rbenv'
@ -126,8 +125,4 @@ def install_environment(
def run_hook(prefix, hook, file_args): # pragma: windows no cover def run_hook(prefix, hook, file_args): # pragma: windows no cover
with in_env(prefix, hook['language_version']): with in_env(prefix, hook['language_version']):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -10,7 +10,6 @@ from pre_commit.envcontext import Var
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'rustenv' ENVIRONMENT_DIR = 'rustenv'
@ -91,8 +90,4 @@ def install_environment(prefix, version, additional_dependencies):
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
with in_env(prefix): with in_env(prefix):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = None ENVIRONMENT_DIR = None
@ -13,8 +12,4 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
cmd = helpers.to_cmd(hook) cmd = helpers.to_cmd(hook)
cmd = (prefix.path(cmd[0]),) + cmd[1:] cmd = (prefix.path(cmd[0]),) + cmd[1:]
return xargs( return helpers.run_xargs(hook, cmd, file_args)
cmd,
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -8,7 +8,6 @@ from pre_commit.envcontext import Var
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.util import clean_path_on_failure from pre_commit.util import clean_path_on_failure
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = 'swift_env' ENVIRONMENT_DIR = 'swift_env'
get_default_version = helpers.basic_get_default_version 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 def run_hook(prefix, hook, file_args): # pragma: windows no cover
with in_env(prefix): with in_env(prefix):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.xargs import xargs
ENVIRONMENT_DIR = None ENVIRONMENT_DIR = None
@ -11,8 +10,4 @@ install_environment = helpers.no_install
def run_hook(prefix, hook, file_args): def run_hook(prefix, hook, file_args):
return xargs( return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
helpers.to_cmd(hook),
file_args,
target_concurrency=helpers.target_concurrency(hook),
)

View file

@ -108,9 +108,8 @@ def xargs(cmd, varargs, **kwargs):
def run_cmd_partition(run_cmd): def run_cmd_partition(run_cmd):
return cmd_output(*run_cmd, encoding=None, retcode=None) return cmd_output(*run_cmd, encoding=None, retcode=None)
with _thread_mapper( threads = min(len(partitions), target_concurrency)
min(len(partitions), target_concurrency), with _thread_mapper(threads) as thread_map:
) as thread_map:
results = thread_map(run_cmd_partition, partitions) results = thread_map(run_cmd_partition, partitions)
for proc_retcode, proc_out, proc_err in results: for proc_retcode, proc_out, proc_err in results: