From 3f96d54af2347db540541f5c5dd1f6fd24592e1a Mon Sep 17 00:00:00 2001 From: John Sirois Date: Mon, 30 Sep 2024 12:24:05 -0700 Subject: [PATCH] Add repl support for `PYTHON_COLORS`. (#2545) This is new CPython env var knob in Python 3.13. --- pex/repl/custom.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pex/repl/custom.py b/pex/repl/custom.py index e5572d95c..35a429999 100644 --- a/pex/repl/custom.py +++ b/pex/repl/custom.py @@ -84,6 +84,11 @@ def _try_enable_readline( def _use_color(): # type: () -> bool + # Used in Python 3.13+ + python_colors = os.environ.get("PYTHON_COLORS") + if python_colors in ("0", "1"): + return python_colors == "1" + # A common convention; see: https://no-color.org/ if "NO_COLOR" in os.environ: return False @@ -92,7 +97,7 @@ def _use_color(): if "FORCE_COLOR" in os.environ: return True - return sys.stdout.isatty() and "dumb" != os.environ.get("TERM") + return sys.stderr.isatty() and "dumb" != os.environ.get("TERM") def repl_loop(