Allow verbose/quiet level to be specified via config file and env var by McSinyx · Pull Request #8578 · pypa/pip (original) (raw)

FYI writing newline doesn't write to disk (at least not by default), but thanks for raising this up. The best source I can refer to is ISO C99 7.19.3.3 which states:

When a stream is unbuffered, characters are intended to appear from the source or at the destination as soon as possible. Otherwise characters may be accumulated and transmitted to or from the host environment as a block.

When a stream is fully buffered, characters are intended to be transmitted to or from the host environment as a block when a buffer is filled.

When a stream is line buffered, characters are intended to be transmitted to or from the host environment as a block when a new-line character is encountered.

I dig down CPython docs again and found (NamedTemporaryFile passes buffering to open):

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size in bytes of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

So if we set buffering=1 the file would be flushed upon newline, otherwise after a few KiB. However, TextIOWrapper.flush does not seem warranty to flush the filesystem file (or maybe I interpret the comment incorrectly, please don't ask me what the code actually does).

That being said, I'm pretty sure on most platforms it is safe to assume flush would do the job and would not object someone else applying the patch above. Personally I just do know enough to be responsible for such change.