Skip to content

Commit

Permalink
fix: patch also stdout.flush() from colorama for pypa#4170
Browse files Browse the repository at this point in the history
bc on Windows it breaks with OSError(errno.EINVAL) after pip has broken.
+ Fix a bit the TC according to PY2 behavior.
  • Loading branch information
ankostis committed Aug 23, 2018
1 parent 8f11b96 commit 080a7ab
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pip/_vendor/colorama/ansitowin32.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
import errno
import re
import sys
import os
Expand Down Expand Up @@ -136,12 +137,25 @@ def get_win32_calls(self):
}
return dict()

def _flush(self):
"""Ignore `BrokenPipeErrors` eg. when piped in `head` UNIX cmd."""
try:
self.wrapped.flush()
except (IOError, OSError) as ex: # Python-2 has no `BrokenPipeError`
# Windows also fails with:
# File "pip\_vendor\colorama\ansitowin32.py", line 143, in _flush
# self.wrapped.flush()
# OSError: [Errno 22] Invalid argument
#
if ex.errno not in (errno.EPIPE, errno.EINVAL):
raise

def write(self, text):
if self.strip or self.convert:
self.write_and_convert(text)
else:
self.wrapped.write(text)
self.wrapped.flush()
self._flush()
if self.autoreset:
self.reset_all()

Expand Down Expand Up @@ -172,7 +186,7 @@ def write_and_convert(self, text):
def write_plain_text(self, text, start, end):
if start < end:
self.wrapped.write(text[start:end])
self.wrapped.flush()
self._flush()


def convert_ansi(self, paramstring, command):
Expand Down

0 comments on commit 080a7ab

Please sign in to comment.