Skip to content

Commit 3a11a36

Browse files
authored
Harmonise run() and run_with_logging() (#213)
1 parent 566ca52 commit 3a11a36

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

build_docs.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from datetime import datetime as dt, timezone
4242
from pathlib import Path
4343
from string import Template
44-
from textwrap import indent
4544
from time import perf_counter, sleep
4645
from typing import Iterable, Literal
4746
from urllib.parse import urljoin
@@ -217,7 +216,7 @@ def filter(languages, language_tags=None):
217216

218217
def run(cmd, cwd=None) -> subprocess.CompletedProcess:
219218
"""Like subprocess.run, with logging before and after the command execution."""
220-
cmd = [str(arg) for arg in cmd]
219+
cmd = list(map(str, cmd))
221220
cmdstring = shlex.join(cmd)
222221
logging.debug("Run: '%s'", cmdstring)
223222
result = subprocess.run(
@@ -233,9 +232,9 @@ def run(cmd, cwd=None) -> subprocess.CompletedProcess:
233232
if result.returncode:
234233
# Log last 20 lines, those are likely the interesting ones.
235234
logging.error(
236-
"Run: %r KO:\n%s",
235+
"Run: '%s' KO:\n%s",
237236
cmdstring,
238-
indent("\n".join(result.stdout.split("\n")[-20:]), " "),
237+
"\n".join(f" {line}" for line in result.stdout.split("\n")[-20:]),
239238
)
240239
result.check_returncode()
241240
return result
@@ -244,7 +243,7 @@ def run(cmd, cwd=None) -> subprocess.CompletedProcess:
244243
def run_with_logging(cmd, cwd=None):
245244
"""Like subprocess.check_call, with logging before the command execution."""
246245
cmd = list(map(str, cmd))
247-
logging.debug("Run: %s", shlex.join(cmd))
246+
logging.debug("Run: '%s'", shlex.join(cmd))
248247
with subprocess.Popen(
249248
cmd,
250249
cwd=cwd,
@@ -255,7 +254,7 @@ def run_with_logging(cmd, cwd=None):
255254
) as p:
256255
try:
257256
for line in p.stdout or ():
258-
logging.debug(">>>> %s", line.rstrip())
257+
logging.debug(">>>> %s", line.rstrip())
259258
except:
260259
p.kill()
261260
raise

0 commit comments

Comments
 (0)