FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-148766: Add colour to Python help by hugovk · Pull Request #148767 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.15.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ Other language changes

(Contributed by Adam Turner in :gh:`133711`; PEP 686 written by Inada Naoki.)

* The interpreter help (such as ``python --help``) is now in color.
This can be controlled by :ref:`environment variables
<using-on-controlling-color>`.
(Contributed by Hugo van Kemenade in :gh:`148766`.)

* Unraisable exceptions are now highlighted with color by default. This can be
controlled by :ref:`environment variables <using-on-controlling-color>`.
(Contributed by Peter Bierma in :gh:`134170`.)
Expand Down
24 changes: 24 additions & 0 deletions Lib/test/test_cmd_line.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def verify_valid_flag(self, cmd_line):
return out

@support.cpython_only
@support.force_not_colorized
def test_help(self):
self.verify_valid_flag('-h')
self.verify_valid_flag('-?')
Expand All @@ -68,6 +69,7 @@ def test_help(self):
self.assertLess(len(lines), 50)

@support.cpython_only
@support.force_not_colorized
def test_help_env(self):
out = self.verify_valid_flag('--help-env')
self.assertIn(b'PYTHONHOME', out)
Expand All @@ -81,6 +83,7 @@ def test_help_env(self):
"env vars should be sorted alphabetically")

@support.cpython_only
@support.force_not_colorized
def test_help_xoptions(self):
out = self.verify_valid_flag('--help-xoptions')
self.assertIn(b'-X dev', out)
Expand All @@ -89,6 +92,7 @@ def test_help_xoptions(self):
"options should be sorted alphabetically")

@support.cpython_only
@support.force_not_colorized
def test_help_all(self):
out = self.verify_valid_flag('--help-all')
lines = out.splitlines()
Expand All @@ -100,6 +104,25 @@ def test_help_all(self):
# but the rest should be ASCII-only
b''.join(lines[1:]).decode('ascii')

@support.cpython_only
@support.force_colorized
def test_help_colorized(self):
rc, out, err = assert_python_ok("--help", FORCE_COLOR="1")
# Check ANSI color codes are present
self.assertIn(b"\x1b[", out)
# Check that key text elements are still present
self.assertIn(b"usage:", out)
self.assertIn(b"-h", out)
self.assertIn(b"--help-all", out)
self.assertIn(b"cmd", out)
self.assertIn(b"Arguments:", out)

@support.cpython_only
@support.force_not_colorized
def test_help_not_colorized(self):
rc, out, err = assert_python_ok("--help")
self.assertNotIn(b"\x1b[", out)

def test_optimize(self):
self.verify_valid_flag('-O')
self.verify_valid_flag('-OO')
Expand Down Expand Up @@ -1063,6 +1086,7 @@ def test_argv0_normalization(self):
self.assertEqual(proc.stdout.strip(), b'0')

@support.cpython_only
@support.force_not_colorized
def test_parsing_error(self):
args = [sys.executable, '-I', '--unknown-option']
proc = subprocess.run(args,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The interpreter help (such as ``python --help``) is now in color. Patch by
Hugo van Kemenade.
Loading
Loading

Back | FazBrowse Home | New Git URL