Skip to content

Commit b2e5a83

Browse files
Work around bug in capturing output on windows.
On Windows with Python >= 3.6.0, the console handling seems to have changed and this seems to break our capturing the file descriptor to suppress the compilation messages on the console. pytest has a fix here: pytest-dev/pytest#2462 but we essentially do not do any capturing on windows for these Python versions as this fix doesn't seem to help us here. Hopefully this will be resolved in Python itself at some point but for now this error was breaking any compilation using compyle on Windows.
1 parent 79cba2f commit b2e5a83

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compyle/capture_stream.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ def __init__(self, stream=sys.stderr):
3434
self._cached_output = None
3535

3636
def __enter__(self):
37+
if sys.platform.startswith('win32') and sys.version_info[:2] > (3, 5):
38+
return self
3739
self.orig_stream = os.dup(self.fileno)
3840
self.tmp_path = mktemp()
3941
self.tmp_stream = open(self.tmp_path, 'w+')
4042
os.dup2(self.tmp_stream.fileno(), self.fileno)
4143
return self
4244

4345
def __exit__(self, type, value, tb):
46+
if sys.platform.startswith('win32') and sys.version_info[:2] > (3, 5):
47+
return
4448
if self.orig_stream is not None:
4549
os.dup2(self.orig_stream, self.fileno)
4650
if self.tmp_stream is not None:
@@ -66,19 +70,23 @@ def get_output(self):
6670
self._cache_output()
6771
return self._cached_output
6872

73+
6974
class CaptureMultipleStreams(object):
7075
"""This lets one capture multiple streams together.
7176
"""
7277
def __init__(self, streams=None):
7378
streams = (sys.stdout, sys.stderr) if streams is None else streams
7479
self.streams = streams
7580
self.captures = [CaptureStream(x) for x in streams]
81+
7682
def __enter__(self):
7783
for capture in self.captures:
7884
capture.__enter__()
7985
return self
86+
8087
def __exit__(self, type, value, tb):
8188
for capture in self.captures:
8289
capture.__exit__(type, value, tb)
90+
8391
def get_output(self):
8492
return tuple(x.get_output() for x in self.captures)

0 commit comments

Comments
 (0)