Skip to content

Commit

Permalink
Merge pull request #203 from AA-Turner/log-run
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Sep 27, 2024
2 parents 3bda3f4 + c422c3c commit 2172d33
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def run(cmd, cwd=None) -> subprocess.CompletedProcess:
"""Like subprocess.run, with logging before and after the command execution."""
cmd = [str(arg) for arg in cmd]
cmdstring = shlex.join(cmd)
logging.debug("Run: %r", cmdstring)
logging.debug("Run: '%s'", cmdstring)
result = subprocess.run(
cmd,
cwd=cwd,
Expand All @@ -242,6 +242,21 @@ def run(cmd, cwd=None) -> subprocess.CompletedProcess:
return result


def run_with_logging(cmd, cwd=None):
"""Like subprocess.check_call, with logging before the command execution."""
cmd = list(map(str, cmd))
logging.debug("Run: %s", shlex.join(cmd))
with subprocess.Popen(cmd, cwd=cwd, encoding="utf-8") as p:
try:
for line in p.stdout:
logging.debug(">>>> %s", line.rstrip())
except:
p.kill()
raise
if return_code := p.poll():
raise subprocess.CalledProcessError(return_code, cmd[0])


def changed_files(left, right):
"""Compute a list of different files between left and right, recursively.
Resulting paths are relative to left.
Expand Down Expand Up @@ -728,7 +743,7 @@ def is_mac():
self.versions,
self.checkout / "Doc" / "tools" / "templates" / "indexsidebar.html",
)
run(
run_with_logging(
[
"make",
"-C",
Expand Down

0 comments on commit 2172d33

Please sign in to comment.