Skip to content

Commit

Permalink
give docker a tty output when expecting color
Browse files Browse the repository at this point in the history
this makes the behavior more consistent with the system language
and would help the executable run in a docker container to
produce a colored output.
  • Loading branch information
glehmann committed Feb 10, 2024
1 parent 7384838 commit 7918e45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pre_commit/languages/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_docker_user() -> tuple[str, ...]: # pragma: win32 no cover
return ()


def docker_cmd() -> tuple[str, ...]: # pragma: win32 no cover
def docker_cmd(color: bool) -> tuple[str, ...]: # pragma: win32 no cover
return (
'docker', 'run',
'--rm',
Expand All @@ -118,7 +118,7 @@ def docker_cmd() -> tuple[str, ...]: # pragma: win32 no cover
# unshared label. Only the current container can use a private volume.
'-v', f'{_get_docker_path(os.getcwd())}:/src:rw,Z',
'--workdir', '/src',
)
) + (('--tty',) if color else ())


def run_hook(
Expand All @@ -139,7 +139,7 @@ def run_hook(

entry_tag = ('--entrypoint', entry_exe, docker_tag(prefix))
return lang_base.run_xargs(
(*docker_cmd(), *entry_tag, *cmd_rest),
(*docker_cmd(color), *entry_tag, *cmd_rest),
file_args,
require_serial=require_serial,
color=color,
Expand Down
2 changes: 1 addition & 1 deletion pre_commit/languages/docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run_hook(
require_serial: bool,
color: bool,
) -> tuple[int, bytes]: # pragma: win32 no cover
cmd = docker_cmd() + lang_base.hook_cmd(entry, args)
cmd = docker_cmd(color) + lang_base.hook_cmd(entry, args)
return lang_base.run_xargs(
cmd,
file_args,
Expand Down

0 comments on commit 7918e45

Please sign in to comment.