Skip to content

Commit

Permalink
Add repl support for PYTHON_COLORS. (#2545)
Browse files Browse the repository at this point in the history
This is new CPython env var knob in Python 3.13.
  • Loading branch information
jsirois authored Sep 30, 2024
1 parent 713fb0b commit 3f96d54
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pex/repl/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 3f96d54

Please sign in to comment.