From c58c5c58eccd8b303d9a8ad1f7aa64f542bf964f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 8 Jun 2026 18:13:44 +0530 Subject: [PATCH] Drop use of `Unbuffered` wrapper class (#2894) --- cibuildwheel/__main__.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index c25d8bc5..2a3287ef 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -4,6 +4,7 @@ import argparse import contextlib import dataclasses import functools +import io import os import shutil import sys @@ -30,7 +31,7 @@ from cibuildwheel.util.resources import read_all_configs TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Generator, Iterable, Sequence - from typing import Any, Literal, TextIO + from typing import Literal @dataclasses.dataclass @@ -44,23 +45,6 @@ class FileReport: size: str -# Taken from https://stackoverflow.com/a/107717 -class Unbuffered: - def __init__(self, stream: TextIO) -> None: - self.stream = stream - - def write(self, data: str) -> None: - self.stream.write(data) - self.stream.flush() - - def writelines(self, data: Iterable[str]) -> None: - self.stream.writelines(data) - self.stream.flush() - - def __getattr__(self, attr: str) -> Any: # noqa: ANN401 - return getattr(self.stream, attr) - - def main() -> None: global_options = GlobalOptions() try: @@ -360,10 +344,11 @@ def build_in_directory(args: CommandLineArguments) -> None: # Add CIBUILDWHEEL environment variable os.environ["CIBUILDWHEEL"] = "1" - # Python is buffering by default when running on the CI platforms, giving - # problems interleaving subprocess call output with unflushed calls to - # 'print' - sys.stdout = Unbuffered(sys.stdout) + # Python block-buffers stdout when it isn't a tty, which de-interleaves + # `print` output and direct fd-1 writes from subprocesses sharing this + # stdout. line_buffering allows each newline to flush all the way to fd-1. + if isinstance(sys.stdout, io.TextIOWrapper): + sys.stdout.reconfigure(line_buffering=True) # create the cache dir before it gets printed & builds performed CIBW_CACHE_PATH.mkdir(parents=True, exist_ok=True)