Skip to content

Commit

Permalink
MINOR: [CI] Improve conda-clean output on error
Browse files Browse the repository at this point in the history
When a subprocess errors, display its stderr instead of just complaining about the exit status.
  • Loading branch information
pitrou committed Mar 28, 2022
1 parent 68164c8 commit c10a97c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions dev/tasks/conda-recipes/clean.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from subprocess import check_output, check_call
import subprocess
from typing import Set

import json
Expand All @@ -20,8 +20,26 @@
]


def run_command(cmdline, **kwargs):
kwargs.setdefault('capture_output', True)
p = subprocess.run(cmdline, **kwargs)
if p.returncode != 0:
print(f"Command {cmdline} returned non-zero exit status "
f"{p.returncode}", file=sys.stderr)
if p.stdout:
print("Stdout was:\n" + "-" * 70, file=sys.stderr)
print(p.stdout.decode().rstrip())
print("-" * 70, file=sys.stderr)
if p.stderr:
print("Stderr was:\n" + "-" * 70, file=sys.stderr)
print(p.stderr.decode().rstrip())
print("-" * 70, file=sys.stderr)
sys.exit(1)
return p.stdout


def builds_to_delete(platform: str, to_delete: Set[str]) -> int:
pkgs_json = check_output(
pkgs_json = run_command(
[
"conda",
"search",
Expand Down Expand Up @@ -93,4 +111,4 @@ def builds_to_delete(platform: str, to_delete: Set[str]) -> int:

if "FORCE" in sys.argv and len(to_delete) > 0:
print("Deleting ...")
check_call(["anaconda", "remove", "-f"] + to_delete)
run_command(["anaconda", "remove", "-f"] + to_delete)

0 comments on commit c10a97c

Please sign in to comment.