TemporaryPipInstallResolver: Prevent pip install
from polluting stdout
#361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed this while playing around with
--install-deps
and--json
, andat the same time piping the JSON output into
jq
for filtering/colors:The
pip install
that is triggered by--install-deps
will print statusmessages to both stdout and stderr, and since these are not handled by
our
subprocess.run()
call, they will appear directly on ourstdout/stderr. When piping our stdout to
jq
this causesjq
to getthose status messages (preceding the JSON output) on its stdin, and it
predictably aborts with an error message.
This commit fixes the issue in two ways:
First, we pass
--quiet
and--disable-pip-version-check
topip install
,to silence some common/unnecesary output. This seems sufficient to make
pip install
silent when everything works as expected. However, whenwarnings and errors might still be printed in exceptional cases.
Next, we capture the stdout + stderr from
pip install
and only printthem in case the
pip install
command failed.With both of these fixes, we ensure that
pip install
only makes noisewhen it fails, and that noise only appears on our stderr (in the shape
of a warning log message). For example, if I try to
--install-deps
withan intentional typo (
pyyamll
):