151 days ago · Tech · hide · Fediverse post

I learned about the sys.stdout.isatty() method in Python which allows you to detect if your code is running in a terminal. For example: Pythonimport sys if sys.stdout.isatty(): print("This program is running in a terminal!") else: print("This program is running somewhere else, like a CI/CD pipeline")Running the program outputs the following: Console$ python3 tty.py This program is running in a terminal! But if we pipe the program into some other tool, like cat, it is no longer running in a terminal and prints the other message: Console$ python3 tty.py | cat This program is running somewhere else, like a CI/CD pipeline This is why some colorized output from code is not colorized in CI/CD pipelines. The code itself checks if it’s being run in a terminal, and if not, it doesn’t display colors that would result in junk being displayed due to the nature of ANSI escape codes used in colorization. I always thought that it was the CI/CD systems that suppressed color output but that’s not…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town