Skip to content

Commit b59d719

Browse files
committed
Use Hook api in languages
1 parent 5f9a667 commit b59d719

File tree

18 files changed

+41
-38
lines changed

18 files changed

+41
-38
lines changed

pre_commit/languages/all.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@
3939
# 'default'.
4040
# """
4141
#
42-
# def run_hook(prefix, hook, file_args):
42+
# def run_hook(hook, file_args):
4343
# """Runs a hook and returns the returncode and output of running that
4444
# hook.
4545
#
4646
# Args:
47-
# prefix - `Prefix` bound to the repository.
48-
# hook - Hook dictionary
47+
# hook - `Hook`
4948
# file_args - The files to be run
5049
#
5150
# Returns:

pre_commit/languages/docker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def docker_cmd():
8585
)
8686

8787

88-
def run_hook(prefix, hook, file_args): # pragma: windows no cover
88+
def run_hook(hook, file_args): # pragma: windows no cover
8989
assert_docker_available()
9090
# Rebuild the docker image in case it has gone missing, as many people do
9191
# automated cleanup of docker images.
92-
build_docker_image(prefix, pull=False)
92+
build_docker_image(hook.prefix, pull=False)
9393

9494
hook_cmd = helpers.to_cmd(hook)
9595
entry_exe, cmd_rest = hook_cmd[0], hook_cmd[1:]
9696

97-
entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
97+
entry_tag = ('--entrypoint', entry_exe, docker_tag(hook.prefix))
9898
cmd = docker_cmd() + entry_tag + cmd_rest
9999
return helpers.run_xargs(hook, cmd, file_args)

pre_commit/languages/docker_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
install_environment = helpers.no_install
1313

1414

15-
def run_hook(prefix, hook, file_args): # pragma: windows no cover
15+
def run_hook(hook, file_args): # pragma: windows no cover
1616
assert_docker_available()
1717
cmd = docker_cmd() + helpers.to_cmd(hook)
1818
return helpers.run_xargs(hook, cmd, file_args)

pre_commit/languages/fail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
install_environment = helpers.no_install
1010

1111

12-
def run_hook(prefix, hook, file_args):
13-
out = hook['entry'].encode('UTF-8') + b'\n\n'
12+
def run_hook(hook, file_args):
13+
out = hook.entry.encode('UTF-8') + b'\n\n'
1414
out += b'\n'.join(f.encode('UTF-8') for f in file_args) + b'\n'
1515
return 1, out, b''

pre_commit/languages/golang.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ def install_environment(prefix, version, additional_dependencies):
7878
rmtree(pkgdir)
7979

8080

81-
def run_hook(prefix, hook, file_args):
82-
with in_env(prefix):
81+
def run_hook(hook, file_args):
82+
with in_env(hook.prefix):
8383
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)

pre_commit/languages/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def environment_dir(ENVIRONMENT_DIR, language_version):
2626

2727

2828
def to_cmd(hook):
29-
return tuple(shlex.split(hook['entry'])) + tuple(hook['args'])
29+
return tuple(shlex.split(hook.entry)) + tuple(hook.args)
3030

3131

3232
def assert_version_default(binary, version):
@@ -57,7 +57,7 @@ def no_install(prefix, version, additional_dependencies):
5757

5858

5959
def target_concurrency(hook):
60-
if hook['require_serial'] or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
60+
if hook.require_serial or 'PRE_COMMIT_NO_CONCURRENCY' in os.environ:
6161
return 1
6262
else:
6363
# Travis appears to have a bunch of CPUs, but we can't use them all.

pre_commit/languages/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ def install_environment(prefix, version, additional_dependencies):
6868
)
6969

7070

71-
def run_hook(prefix, hook, file_args):
72-
with in_env(prefix, hook['language_version']):
71+
def run_hook(hook, file_args):
72+
with in_env(hook.prefix, hook.language_version):
7373
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)

pre_commit/languages/pcre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
install_environment = helpers.no_install
1414

1515

16-
def run_hook(prefix, hook, file_args):
16+
def run_hook(hook, file_args):
1717
# For PCRE the entry is the regular expression to match
18-
cmd = (GREP, '-H', '-n', '-P') + tuple(hook['args']) + (hook['entry'],)
18+
cmd = (GREP, '-H', '-n', '-P') + tuple(hook.args) + (hook.entry,)
1919

2020
# Grep usually returns 0 for matches, and nonzero for non-matches so we
2121
# negate it here.

pre_commit/languages/pygrep.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ def _process_filename_at_once(pattern, filename):
4444
return retv
4545

4646

47-
def run_hook(prefix, hook, file_args):
48-
exe = (sys.executable, '-m', __name__)
49-
exe += tuple(hook['args']) + (hook['entry'],)
47+
def run_hook(hook, file_args):
48+
exe = (sys.executable, '-m', __name__) + tuple(hook.args) + (hook.entry,)
5049
return xargs(exe, file_args)
5150

5251

pre_commit/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def healthy(prefix, language_version):
124124
)
125125
return retcode == 0
126126

127-
def run_hook(prefix, hook, file_args):
128-
with in_env(prefix, hook['language_version']):
127+
def run_hook(hook, file_args):
128+
with in_env(hook.prefix, hook.language_version):
129129
return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
130130

131131
def install_environment(prefix, version, additional_dependencies):

0 commit comments

Comments
 (0)