Skip to content

Commit c81ab26

Browse files
authored
Merge pull request #11593 from pfmoore/vendoring_test
Vendoring updates (except rich)
2 parents 72a5b08 + bbe83b0 commit c81ab26

21 files changed

+1010
-77
lines changed

news/colorama.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade colorama to 0.4.6

news/distro.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade distro to 1.8.0

news/platformdirs.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade platformdirs to 2.5.3

src/pip/_vendor/colorama/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
2-
from .initialise import init, deinit, reinit, colorama_text
2+
from .initialise import init, deinit, reinit, colorama_text, just_fix_windows_console
33
from .ansi import Fore, Back, Style, Cursor
44
from .ansitowin32 import AnsiToWin32
55

6-
__version__ = '0.4.5'
6+
__version__ = '0.4.6'
7+

src/pip/_vendor/colorama/ansitowin32.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
from .ansi import AnsiFore, AnsiBack, AnsiStyle, Style, BEL
7-
from .winterm import WinTerm, WinColor, WinStyle
7+
from .winterm import enable_vt_processing, WinTerm, WinColor, WinStyle
88
from .win32 import windll, winapi_test
99

1010

@@ -94,15 +94,22 @@ def __init__(self, wrapped, convert=None, strip=None, autoreset=False):
9494
# (e.g. Cygwin Terminal). In this case it's up to the terminal
9595
# to support the ANSI codes.
9696
conversion_supported = on_windows and winapi_test()
97+
try:
98+
fd = wrapped.fileno()
99+
except Exception:
100+
fd = -1
101+
system_has_native_ansi = not on_windows or enable_vt_processing(fd)
102+
have_tty = not self.stream.closed and self.stream.isatty()
103+
need_conversion = conversion_supported and not system_has_native_ansi
97104

98105
# should we strip ANSI sequences from our output?
99106
if strip is None:
100-
strip = conversion_supported or (not self.stream.closed and not self.stream.isatty())
107+
strip = need_conversion or not have_tty
101108
self.strip = strip
102109

103110
# should we should convert ANSI sequences into win32 calls?
104111
if convert is None:
105-
convert = conversion_supported and not self.stream.closed and self.stream.isatty()
112+
convert = need_conversion and have_tty
106113
self.convert = convert
107114

108115
# dict of ansi codes to win32 functions and parameters
@@ -264,3 +271,7 @@ def convert_osc(self, text):
264271
if params[0] in '02':
265272
winterm.set_title(params[1])
266273
return text
274+
275+
276+
def flush(self):
277+
self.wrapped.flush()

src/pip/_vendor/colorama/initialise.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@
66
from .ansitowin32 import AnsiToWin32
77

88

9-
orig_stdout = None
10-
orig_stderr = None
9+
def _wipe_internal_state_for_tests():
10+
global orig_stdout, orig_stderr
11+
orig_stdout = None
12+
orig_stderr = None
13+
14+
global wrapped_stdout, wrapped_stderr
15+
wrapped_stdout = None
16+
wrapped_stderr = None
1117

12-
wrapped_stdout = None
13-
wrapped_stderr = None
18+
global atexit_done
19+
atexit_done = False
20+
21+
global fixed_windows_console
22+
fixed_windows_console = False
1423

15-
atexit_done = False
24+
try:
25+
# no-op if it wasn't registered
26+
atexit.unregister(reset_all)
27+
except AttributeError:
28+
# python 2: no atexit.unregister. Oh well, we did our best.
29+
pass
1630

1731

1832
def reset_all():
@@ -55,6 +69,29 @@ def deinit():
5569
sys.stderr = orig_stderr
5670

5771

72+
def just_fix_windows_console():
73+
global fixed_windows_console
74+
75+
if sys.platform != "win32":
76+
return
77+
if fixed_windows_console:
78+
return
79+
if wrapped_stdout is not None or wrapped_stderr is not None:
80+
# Someone already ran init() and it did stuff, so we won't second-guess them
81+
return
82+
83+
# On newer versions of Windows, AnsiToWin32.__init__ will implicitly enable the
84+
# native ANSI support in the console as a side-effect. We only need to actually
85+
# replace sys.stdout/stderr if we're in the old-style conversion mode.
86+
new_stdout = AnsiToWin32(sys.stdout, convert=None, strip=None, autoreset=False)
87+
if new_stdout.convert:
88+
sys.stdout = new_stdout
89+
new_stderr = AnsiToWin32(sys.stderr, convert=None, strip=None, autoreset=False)
90+
if new_stderr.convert:
91+
sys.stderr = new_stderr
92+
93+
fixed_windows_console = True
94+
5895
@contextlib.contextmanager
5996
def colorama_text(*args, **kwargs):
6097
init(*args, **kwargs)
@@ -78,3 +115,7 @@ def wrap_stream(stream, convert, strip, autoreset, wrap):
78115
if wrapper.should_wrap():
79116
stream = wrapper.stream
80117
return stream
118+
119+
120+
# Use this for initial setup as well, to reduce code duplication
121+
_wipe_internal_state_for_tests()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
2+
import sys
3+
from unittest import TestCase, main
4+
5+
from ..ansi import Back, Fore, Style
6+
from ..ansitowin32 import AnsiToWin32
7+
8+
stdout_orig = sys.stdout
9+
stderr_orig = sys.stderr
10+
11+
12+
class AnsiTest(TestCase):
13+
14+
def setUp(self):
15+
# sanity check: stdout should be a file or StringIO object.
16+
# It will only be AnsiToWin32 if init() has previously wrapped it
17+
self.assertNotEqual(type(sys.stdout), AnsiToWin32)
18+
self.assertNotEqual(type(sys.stderr), AnsiToWin32)
19+
20+
def tearDown(self):
21+
sys.stdout = stdout_orig
22+
sys.stderr = stderr_orig
23+
24+
25+
def testForeAttributes(self):
26+
self.assertEqual(Fore.BLACK, '\033[30m')
27+
self.assertEqual(Fore.RED, '\033[31m')
28+
self.assertEqual(Fore.GREEN, '\033[32m')
29+
self.assertEqual(Fore.YELLOW, '\033[33m')
30+
self.assertEqual(Fore.BLUE, '\033[34m')
31+
self.assertEqual(Fore.MAGENTA, '\033[35m')
32+
self.assertEqual(Fore.CYAN, '\033[36m')
33+
self.assertEqual(Fore.WHITE, '\033[37m')
34+
self.assertEqual(Fore.RESET, '\033[39m')
35+
36+
# Check the light, extended versions.
37+
self.assertEqual(Fore.LIGHTBLACK_EX, '\033[90m')
38+
self.assertEqual(Fore.LIGHTRED_EX, '\033[91m')
39+
self.assertEqual(Fore.LIGHTGREEN_EX, '\033[92m')
40+
self.assertEqual(Fore.LIGHTYELLOW_EX, '\033[93m')
41+
self.assertEqual(Fore.LIGHTBLUE_EX, '\033[94m')
42+
self.assertEqual(Fore.LIGHTMAGENTA_EX, '\033[95m')
43+
self.assertEqual(Fore.LIGHTCYAN_EX, '\033[96m')
44+
self.assertEqual(Fore.LIGHTWHITE_EX, '\033[97m')
45+
46+
47+
def testBackAttributes(self):
48+
self.assertEqual(Back.BLACK, '\033[40m')
49+
self.assertEqual(Back.RED, '\033[41m')
50+
self.assertEqual(Back.GREEN, '\033[42m')
51+
self.assertEqual(Back.YELLOW, '\033[43m')
52+
self.assertEqual(Back.BLUE, '\033[44m')
53+
self.assertEqual(Back.MAGENTA, '\033[45m')
54+
self.assertEqual(Back.CYAN, '\033[46m')
55+
self.assertEqual(Back.WHITE, '\033[47m')
56+
self.assertEqual(Back.RESET, '\033[49m')
57+
58+
# Check the light, extended versions.
59+
self.assertEqual(Back.LIGHTBLACK_EX, '\033[100m')
60+
self.assertEqual(Back.LIGHTRED_EX, '\033[101m')
61+
self.assertEqual(Back.LIGHTGREEN_EX, '\033[102m')
62+
self.assertEqual(Back.LIGHTYELLOW_EX, '\033[103m')
63+
self.assertEqual(Back.LIGHTBLUE_EX, '\033[104m')
64+
self.assertEqual(Back.LIGHTMAGENTA_EX, '\033[105m')
65+
self.assertEqual(Back.LIGHTCYAN_EX, '\033[106m')
66+
self.assertEqual(Back.LIGHTWHITE_EX, '\033[107m')
67+
68+
69+
def testStyleAttributes(self):
70+
self.assertEqual(Style.DIM, '\033[2m')
71+
self.assertEqual(Style.NORMAL, '\033[22m')
72+
self.assertEqual(Style.BRIGHT, '\033[1m')
73+
74+
75+
if __name__ == '__main__':
76+
main()

0 commit comments

Comments
 (0)