From 46ffcd6c44cd275157235bf4e891dd99ce43b930 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Fri, 13 Sep 2019 11:06:18 +1000 Subject: [PATCH] ansible-galaxy - add config to control the display wheel (#61902) * ansible-galaxy - add config to control the display wheel * Fix changelog and make test more stable * Don't use display thread at all if progress wheel isn't being shown --- changelogs/fragments/ansible-galaxy-progress.yaml | 2 ++ lib/ansible/config/base.yml | 12 ++++++++++++ lib/ansible/galaxy/collection.py | 8 ++++++++ test/units/galaxy/test_collection_install.py | 6 +++--- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/ansible-galaxy-progress.yaml diff --git a/changelogs/fragments/ansible-galaxy-progress.yaml b/changelogs/fragments/ansible-galaxy-progress.yaml new file mode 100644 index 00000000000..759ab80a8d3 --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-progress.yaml @@ -0,0 +1,2 @@ +minor_changes: +- ansible-galaxy - Added the ability to display the progress wheel through the C.GALAXY_DISPLAY_PROGRESS config option. Also this now defaults to displaying the progress wheel if stdout has a tty. diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 5de0f5c9bc2..b00105090d5 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1396,6 +1396,18 @@ GALAXY_TOKEN_PATH: - {key: token_path, section: galaxy} type: path version_added: "2.9" +GALAXY_DISPLAY_PROGRESS: + default: ~ + description: + - Some steps in ``ansible-galaxy`` display a progress wheel which can cause issues on certain displays or when + outputing the stdout to a file. + - This config option controls whether the display wheel is shown or not. + - The default is to show the display wheel if stdout has a tty. + env: [{name: ANSIBLE_GALAXY_DISPLAY_PROGRESS}] + ini: + - {key: display_progress, section: galaxy} + type: bool + version_added: "2.10" HOST_KEY_CHECKING: name: Check host keys default: True diff --git a/lib/ansible/galaxy/collection.py b/lib/ansible/galaxy/collection.py index 9bcea253190..980df228d15 100644 --- a/lib/ansible/galaxy/collection.py +++ b/lib/ansible/galaxy/collection.py @@ -9,6 +9,7 @@ import json import operator import os import shutil +import sys import tarfile import tempfile import threading @@ -456,6 +457,13 @@ def _tarfile_extract(tar, member): @contextmanager def _display_progress(): + config_display = C.GALAXY_DISPLAY_PROGRESS + display_wheel = sys.stdout.isatty() if config_display is None else config_display + + if not display_wheel: + yield + return + def progress(display_queue, actual_display): actual_display.debug("Starting display_progress display thread") t = threading.current_thread() diff --git a/test/units/galaxy/test_collection_install.py b/test/units/galaxy/test_collection_install.py index 658c54a69c1..e2d72084a75 100644 --- a/test/units/galaxy/test_collection_install.py +++ b/test/units/galaxy/test_collection_install.py @@ -661,7 +661,7 @@ def test_install_collections_from_tar(collection_artifact, monkeypatch): assert actual_manifest['collection_info']['version'] == '0.1.0' # Filter out the progress cursor display calls. - display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2]] + display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1] assert len(display_msgs) == 3 assert display_msgs[0] == "Process install dependency map" assert display_msgs[1] == "Starting collection install process" @@ -686,7 +686,7 @@ def test_install_collections_existing_without_force(collection_artifact, monkeyp assert actual_files == [b'README.md', b'docs', b'galaxy.yml', b'playbooks', b'plugins', b'roles'] # Filter out the progress cursor display calls. - display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2]] + display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1] assert len(display_msgs) == 4 # Msg1 is the warning about not MANIFEST.json, cannot really check message as it has line breaks which varies based # on the path size @@ -724,7 +724,7 @@ def test_install_collection_with_circular_dependency(collection_artifact, monkey assert actual_manifest['collection_info']['version'] == '0.1.0' # Filter out the progress cursor display calls. - display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2]] + display_msgs = [m[1][0] for m in mock_display.mock_calls if 'newline' not in m[2] and len(m[1]) == 1] assert len(display_msgs) == 3 assert display_msgs[0] == "Process install dependency map" assert display_msgs[1] == "Starting collection install process"