Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,25 @@ def _safe_getenv(k: str, fallback: str | None = None) -> str | None:
file = sys.stdout

if not sys.flags.ignore_environment:
print("== PYTHON_COLORS", _safe_getenv("PYTHON_COLORS"))
if _safe_getenv("PYTHON_COLORS") == "0":
return False
if _safe_getenv("PYTHON_COLORS") == "1":
return True
print("== NO_COLOR", _safe_getenv("NO_COLOR"))
if _safe_getenv("NO_COLOR"):
return False
print("== COLORIZE", COLORIZE)
if not COLORIZE:
return False
print("== FORCE_COLOR", _safe_getenv("FORCE_COLOR"))
if _safe_getenv("FORCE_COLOR"):
return True
print("== TERM", _safe_getenv("TERM"))
if _safe_getenv("TERM") == "dumb":
return False

print('== hasattr(file, "fileno")', hasattr(file, "fileno"))
if not hasattr(file, "fileno"):
return False

Expand All @@ -455,6 +461,11 @@ def _safe_getenv(k: str, fallback: str | None = None) -> str | None:
except (ImportError, AttributeError):
return False

try:
print('== os.isatty(file.fileno())', os.isatty(file.fileno()))
except OSError:
print("== os.isatty(file.fileno()) Failed")
print('== hasattr(file, "isatty") and file.isatty()', hasattr(file, "isatty") and file.isatty())
try:
return os.isatty(file.fileno())
except OSError:
Expand Down
Loading