From 92304597bd06531c0139db9dd8766562f38cf19e Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Thu, 17 Aug 2017 21:54:08 +0200 Subject: [PATCH] Replacing unbuffered 'os.fdopen' by proxy object to have a unbuffered stdout solution for Windows and AppVeyor that works on Python 3 --- cibuildwheel/util.py | 17 +++++++++++++++++ cibuildwheel/windows.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index d20f986a..d860beeb 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -22,3 +22,20 @@ class BuildSkipper(object): def __repr__(self): return 'BuildSkipper(%r)' % ' '.join(self.patterns) + + +# Taken from https://stackoverflow.com/a/107717 +class Unbuffered(object): + def __init__(self, stream): + self.stream = stream + + def write(self, data): + self.stream.write(data) + self.stream.flush() + + def writelines(self, datas): + self.stream.writelines(datas) + self.stream.flush() + + def __getattr__(self, attr): + return getattr(self.stream, attr) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index feaf12be..f0a1eaba 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -7,13 +7,13 @@ except ImportError: from collections import namedtuple from glob import glob -from .util import prepare_command +from .util import prepare_command, Unbuffered def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, skip): # Python under AppVeyor/Windows seems to be buffering by default, giving problems interleaving subprocess call output with unflushed calls to 'print' sys.stdout.flush() - sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) + sys.stdout = Unbuffered(sys.stdout) # run_with_env is a cmd file that sets the right environment variables to run_with_env = os.path.join(tempfile.gettempdir(), 'appveyor_run_with_env.cmd')