From 5cd8c7f6cbd51a783f273b62947034f071d6e2da Mon Sep 17 00:00:00 2001 From: "Nathaniel J. Smith" Date: Mon, 1 Feb 2016 12:36:49 -0800 Subject: [PATCH] Make install --quiet really quiet Commit 5bb989993 added some code for hiding/showing the cursor when running on the terminal, but accidentally made it so that it always printed the invisible control codes, even when not on a tty or when --quiet was specified. This turns out to be surprisingly bad (e.g. it breaks the official docker python builds). So, let's not do that. Fixes gh-3418 --- pip/utils/ui.py | 6 ++++++ tests/functional/test_install.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pip/utils/ui.py b/pip/utils/ui.py index 973bc64ec92..0b13d741493 100644 --- a/pip/utils/ui.py +++ b/pip/utils/ui.py @@ -215,10 +215,16 @@ def update(self): @contextlib.contextmanager def hidden_cursor(file): + magic_bytes = (HIDE_CURSOR, SHOW_CURSOR) # The Windows terminal does not support the hide/show cursor ANSI codes, # even via colorama. So don't even try. if WINDOWS: yield + # We don't want to clutter the output with control characters if we're + # writing to a file, or if the user is running with --quiet. + # See https://github.com/pypa/pip/issues/3418 + elif not file.isatty() or logger.getEffectiveLevel() > logging.INFO: + yield else: file.write(HIDE_CURSOR) try: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index bf224aef1d0..85eeba7920e 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -235,6 +235,19 @@ def test_install_from_local_directory(script, data): assert egg_info_folder in result.files_created, str(result) +def test_install_quiet(script, data): + """ + Test that install -q is actually quiet. + """ + # Apparently if pip install -q is not actually quiet, then it breaks + # everything. See: + # https://github.com/pypa/pip/issues/3418 + # https://github.com/docker-library/python/issues/83 + to_install = data.packages.join("FSPkg") + result = script.pip('install', '-q', to_install, expect_error=False) + assert result.stdout == "" + assert result.stderr == "" + def test_hashed_install_success(script, data, tmpdir): """ Test that installing various sorts of requirements with correct hashes