New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
give docker a tty output when expecting color #3122
Conversation
I haven't looked at the tests (quite obviously!) — I'm waiting on a opinion on this change before taking care of that :-) |
this won't work because one can enable color without a tty and docker will crash |
never heard of docker crashing because of that I ran a few tests to be sure: ~/s/pre-commit (docker-tty|✔) $ docker run --tty --rm debian grep --color Debian /etc/issue 2>&1
Debian GNU/Linux 12 \n \l
~/s/pre-commit (docker-tty|✔) $ docker run --tty --rm debian grep --color Debian /etc/issue 2>&1 | cat
Debian GNU/Linux 12 \n \l
~/s/pre-commit (docker-tty|✔) $ docker run --rm debian grep --color Debian /etc/issue 2>&1 | cat
Debian GNU/Linux 12 \n \l no color in that case and just to make sure that the ~/s/pre-commit (docker-tty|✔) $ python -c "import sys; print(sys.stdout.isatty())" 2>&1 | cat
False
~/s/pre-commit (docker-tty|✔) $ python -c "import sys; print(sys.stdout.isatty())" 2>&1
True
~/s/pre-commit (docker-tty|✔) $ python -c "import sys; print(sys.stderr.isatty())" 2>&1 | cat
False
~/s/pre-commit (docker-tty|✔) $ python -c "import sys; print(sys.stderr.isatty())" 2>&1
True I may be missing something though. Could you be more explicit on how docker will be crashing? |
it drops the tty ability on stdout but not on stdin |
~/s/pre-commit (docker-tty|✔) $ echo | docker run --tty --rm debian grep --color Debian /etc/issue 2>&1 | cat
Debian GNU/Linux 12 \n \l still no crash (but some color) ~/s/pre-commit (docker-tty|✔) $ echo | python -c "import sys; print(sys.stdin.isatty()); print(sys.stdout.isatty()); print(sys.stderr.isatty()); " 2>&1 | cat
False
False
False and no tty anywhere docker makes the program running in the container that there is a tty though
which is good to have some color. It may cause some problems with the programs that expect some interactivity, but I think |
hmm perhaps we can try this then. there's definitely easily reproducible cases where |
I've been using it for two weeks and haven't seen any problem. Does it look good enough for you to merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a test demonstrating your change
pre_commit/languages/docker.py
Outdated
@@ -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 ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than use +
it would probably be clearer if you used something like get_docker_user
above -- maybe write a little function for that?
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! |
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.