Skip to content

Commit 09471ef

Browse files
committed
run-task: clean up subprocess usage in _clean_git_checkout
This was copied from `run_command` in 8d7d8b1, but some stuff doesn't make sense here: - we don't stream the output to our log so we don't need to disable buffering or go through a TextIOWrapper - we don't want to pass our stdin to the command Instead we can use subprocess.run and let it capture stdout and check the returncode.
1 parent 8f23f5f commit 09471ef

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/taskgraph/run-task/run-task

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -597,26 +597,18 @@ def _clean_git_checkout(destination_path):
597597
"-nxdff",
598598
]
599599
print_line(b"vcs", b"executing %r\n" % args)
600-
p = subprocess.Popen(
600+
p = subprocess.run(
601601
args,
602-
# Disable buffering because we want to receive output
603-
# as it is generated so timestamps in logs are
604-
# accurate.
605-
bufsize=0,
606602
stdout=subprocess.PIPE,
607-
stdin=sys.stdin.fileno(),
603+
encoding="latin1",
608604
cwd=destination_path,
609605
env=os.environ,
606+
check=True,
610607
)
611-
stdout = io.TextIOWrapper(p.stdout, encoding="latin1")
612-
ret = p.wait()
613-
if ret:
614-
sys.exit(ret)
615-
data = stdout.read()
616608
prefix = "Would remove "
617609
filenames = [
618610
os.path.join(destination_path, line[len(prefix) :])
619-
for line in data.splitlines()
611+
for line in p.stdout.splitlines()
620612
]
621613
print_line(b"vcs", b"removing %r\n" % filenames)
622614
for filename in filenames:

0 commit comments

Comments
 (0)