Skip to content

Commit fe79372

Browse files
committed
Fix a couple spinner edge cases.
1 parent ffefa91 commit fe79372

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

news/6312.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The spinner no longer displays a completion message after subprocess calls
2+
not needing a spinner. It also no longer incorrectly reports an error after
3+
certain subprocess calls to Git that succeeded.

src/pip/_internal/utils/misc.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,10 @@ def call_subprocess(
705705
stdout = None
706706
else:
707707
stdout = subprocess.PIPE
708+
709+
# Only use the spinner when we're capturing stdout and we have one.
710+
use_spinner = not show_stdout and spinner is not None
711+
708712
if command_desc is None:
709713
command_desc = format_command_args(cmd)
710714

@@ -738,19 +742,22 @@ def call_subprocess(
738742
logger.debug(line)
739743
else:
740744
# Update the spinner
741-
if spinner is not None:
745+
if use_spinner:
742746
spinner.spin()
743747
try:
744748
proc.wait()
745749
finally:
746750
if proc.stdout:
747751
proc.stdout.close()
748-
if spinner is not None:
749-
if proc.returncode:
752+
proc_had_error = (
753+
proc.returncode and proc.returncode not in extra_ok_returncodes
754+
)
755+
if use_spinner:
756+
if proc_had_error:
750757
spinner.finish("error")
751758
else:
752759
spinner.finish("done")
753-
if proc.returncode and proc.returncode not in extra_ok_returncodes:
760+
if proc_had_error:
754761
if on_returncode == 'raise':
755762
if (logger.getEffectiveLevel() > std_logging.DEBUG and
756763
not show_stdout):

tests/unit/test_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def test_info_logging_with_show_stdout_true(self, capfd, caplog):
925925
# output is already being written to the console.
926926
self.check_result(
927927
capfd, caplog, log_level, spinner, result, expected,
928-
expected_spinner=(0, 'done'),
928+
expected_spinner=(0, None),
929929
)
930930

931931
@pytest.mark.parametrize((
@@ -936,13 +936,13 @@ def test_info_logging_with_show_stdout_true(self, capfd, caplog):
936936
# Test some cases that should result in show_spinner false.
937937
(0, False, None, logging.DEBUG, (None, 'done', 0)),
938938
# Test show_stdout=True.
939-
(0, True, None, logging.DEBUG, (None, 'done', 0)),
940-
(0, True, None, logging.INFO, (None, 'done', 0)),
941-
(0, True, None, logging.WARNING, (None, 'done', 0)),
939+
(0, True, None, logging.DEBUG, (None, None, 0)),
940+
(0, True, None, logging.INFO, (None, None, 0)),
941+
(0, True, None, logging.WARNING, (None, None, 0)),
942942
# Test a non-zero exit status.
943943
(3, False, None, logging.INFO, (InstallationError, 'error', 2)),
944944
# Test a non-zero exit status also in extra_ok_returncodes.
945-
(3, False, (3, ), logging.INFO, (None, 'error', 2)),
945+
(3, False, (3, ), logging.INFO, (None, 'done', 2)),
946946
])
947947
def test_spinner_finish(
948948
self, exit_status, show_stdout, extra_ok_returncodes, log_level,

0 commit comments

Comments
 (0)