buildroot: set PYTHONUNBUFFERED env variable

This disables buffering for the standard output stream for python
executables spawn within the build root. This should help with
the ordering of text output in stages: when stdout is buffered,
debug messages via `print` will be end up in that buffer. When
executables are run in the stage, via `subprocess.run` their 
stdout has its own buffering, which will be flushed at the end 
of the run. If stdout was not manually flushed before invoking
the executable, the output of the tool will be emitted before
anything in the buffer. For example:
  print("stage")
  subprocess.run(["echo", "tool"])
Will lead have the following ordering:
  "tool"
  "stage"
To avoid this, without having to manually flush the stdout
buffer before every `subprocess.run`, disable buffering for
python binaries run inside the build root.
This commit is contained in:
Christian Kellner 2021-05-18 15:39:26 +00:00 committed by Tom Gundersen
parent 7f50d2b57f
commit acfc5f6d71

View file

@ -221,6 +221,7 @@ class BuildRoot(contextlib.AbstractContextManager):
"--new-session",
"--setenv", "PATH", "/usr/sbin:/usr/bin",
"--setenv", "PYTHONPATH", "/run/osbuild/lib",
"--setenv", "PYTHONUNBUFFERED", "1",
"--unshare-ipc",
"--unshare-pid",
"--unshare-net"