Skip to content
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

Colorized output is not disabled when output is redirected #266

Closed
software-dov opened this issue Dec 3, 2019 · 4 comments · Fixed by #267
Closed

Colorized output is not disabled when output is redirected #266

software-dov opened this issue Dec 3, 2019 · 4 comments · Fixed by #267

Comments

@software-dov
Copy link
Contributor

Describe the bug
Redirecting nox output does not correctly determine that stdout is not a tty and adds color control codes to the output.

How to reproduce
Given a noxfile that defines some targets, e.g. unit tests, run
cd path/to/repo && python -m nox -s &> output-log.txt

Expected behavior
The contents of output-log.txt should be plain ASCII (or UTF-8) and not contain cursor control codes.

@dhermes
Copy link
Collaborator

dhermes commented Dec 3, 2019

TIL, neat!

# main.py
import sys


def main():
    print(f"STDIN : {sys.stdin.isatty()}")
    print(f"STDOUT: {sys.stdout.isatty()}")


if __name__ == "__main__":
    main()

yields

$ python main.py
STDIN : True
STDOUT: True
$ python main.py > is_tty.txt && /bin/cat is_tty.txt && rm -f is_tty.txt
STDIN : True
STDOUT: False
$ /usr/bin/touch stdin.txt && python main.py < stdin.txt && rm -f stdin.txt
STDIN : False
STDOUT: True

@dhermes
Copy link
Collaborator

dhermes commented Dec 3, 2019

AFAICT we only check if STDIN is a TTY and only do it in two places (1 and 2).

@software-dov
Copy link
Contributor Author

Why does nox care if STDIN is a TTY?

@theacodes
Copy link
Collaborator

theacodes commented Dec 3, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants