Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58ce57a

Browse files
committed
Add more docs
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
1 parentff19eec commit58ce57a

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

‎Doc/using/cmdline.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,26 @@ Miscellaneous options
612612
..versionadded::3.13
613613
The ``-X presite`` option.
614614

615+
Controlling Color
616+
~~~~~~~~~~~~~~~~~
617+
618+
The Python interpreter is configured by default to use colors to highlight
619+
output in certain situations such as when displaying tracebacks. This
620+
behavior can be controlled by setting different environment variables.
621+
622+
Setting the environment variable ``TERM`` to ``dumb`` will disable color.
623+
624+
If the environment variable ``FORCE_COLOR`` is set, then color will be
625+
enabled regardless of the value of TERM. This is useful on CI systems which
626+
aren’t terminals but can none-the-less display ANSI escape sequences.
627+
628+
If the environment variable ``NO_COLOR`` is set, Python will disable all color
629+
in the output. This takes precedence over ``FORCE_COLOR``.
630+
631+
All these environment variables are used also by other tools to control color
632+
output. To control the color output only in the Python interpreter, the
633+
:envvar:`PY_COLORS` environment variable can be used. This variable takes
634+
less precedence than ``NO_COLOR`` and ``FORCE_COLOR``.
615635

616636
Options you shouldn't use
617637
~~~~~~~~~~~~~~~~~~~~~~~~~

‎Lib/test/test_traceback.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4314,24 +4314,25 @@ def foo():
43144314
self.assertEqual(actual,expected)
43154315

43164316
deftest_colorized_detection_checks_for_environment_variables(self):
4317-
withunittest.mock.patch("os.isatty")asisatty_mock:
4318-
isatty_mock.return_value=True
4319-
withunittest.mock.patch("os.environ", {'TERM':'dumb'}):
4317+
withunittest.mock.patch("nt._supports_virtual_terminal",return_value=True):
4318+
withunittest.mock.patch("os.isatty")asisatty_mock:
4319+
isatty_mock.return_value=True
4320+
withunittest.mock.patch("os.environ", {'TERM':'dumb'}):
4321+
self.assertEqual(traceback._can_colorize(),False)
4322+
withunittest.mock.patch("os.environ", {'PY_COLORS':'1'}):
4323+
self.assertEqual(traceback._can_colorize(),True)
4324+
withunittest.mock.patch("os.environ", {'PY_COLORS':'0'}):
4325+
self.assertEqual(traceback._can_colorize(),False)
4326+
withunittest.mock.patch("os.environ", {'NO_COLOR':'1'}):
4327+
self.assertEqual(traceback._can_colorize(),False)
4328+
withunittest.mock.patch("os.environ", {'NO_COLOR':'1',"PY_COLORS":'1'}):
4329+
self.assertEqual(traceback._can_colorize(),False)
4330+
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1'}):
4331+
self.assertEqual(traceback._can_colorize(),True)
4332+
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1','NO_COLOR':'1'}):
4333+
self.assertEqual(traceback._can_colorize(),False)
4334+
isatty_mock.return_value=False
43204335
self.assertEqual(traceback._can_colorize(),False)
4321-
withunittest.mock.patch("os.environ", {'PY_COLORS':'1'}):
4322-
self.assertEqual(traceback._can_colorize(),True)
4323-
withunittest.mock.patch("os.environ", {'PY_COLORS':'0'}):
4324-
self.assertEqual(traceback._can_colorize(),False)
4325-
withunittest.mock.patch("os.environ", {'NO_COLOR':'1'}):
4326-
self.assertEqual(traceback._can_colorize(),False)
4327-
withunittest.mock.patch("os.environ", {'NO_COLOR':'1',"PY_COLORS":'1'}):
4328-
self.assertEqual(traceback._can_colorize(),False)
4329-
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1'}):
4330-
self.assertEqual(traceback._can_colorize(),True)
4331-
withunittest.mock.patch("os.environ", {'FORCE_COLOR':'1','NO_COLOR':'1'}):
4332-
self.assertEqual(traceback._can_colorize(),False)
4333-
isatty_mock.return_value=False
4334-
self.assertEqual(traceback._can_colorize(),False)
43354336

43364337
if__name__=="__main__":
43374338
unittest.main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp