Skip to content

Commit 708be04

Browse files
committed
Unify logging so we see what's wrong on stderr.
It's usefull to debug, and also usefull if we use docsbuild-scripts in python-docs-theme CI.
1 parent c09fecb commit 708be04

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

build_docs.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@
2323
2424
"""
2525

26-
from bisect import bisect_left as bisect
27-
from collections import namedtuple, OrderedDict
28-
from contextlib import contextmanager, suppress
2926
import filecmp
3027
import json
3128
import logging
3229
import logging.handlers
3330
import os
34-
from pathlib import Path
3531
import re
3632
import shlex
3733
import shutil
38-
from string import Template
3934
import subprocess
4035
import sys
41-
from datetime import datetime
36+
from bisect import bisect_left as bisect
37+
from collections import OrderedDict, namedtuple
38+
from contextlib import contextmanager, suppress
39+
from pathlib import Path
40+
from string import Template
41+
from textwrap import indent
4242

4343
import jinja2
4444

@@ -150,9 +150,9 @@ def title(self):
150150
}
151151

152152

153-
def shell_out(cmd, shell=False, logfile=None):
154-
logging.debug("Running command %s", cmd if shell else shlex.join(cmd))
155-
now = str(datetime.now())
153+
def shell_out(cmd, shell=False):
154+
cmdstring = cmd if shell else shlex.join(cmd)
155+
logging.debug("Running command: %s", cmdstring)
156156
try:
157157
output = subprocess.check_output(
158158
cmd,
@@ -162,33 +162,22 @@ def shell_out(cmd, shell=False, logfile=None):
162162
encoding="utf-8",
163163
errors="backslashreplace",
164164
)
165-
if logfile:
166-
with open(logfile, "a+") as log:
167-
log.write("# " + now + "\n")
168-
log.write(
169-
"# Command {} ran successfully:".format(
170-
cmd if shell else shlex.join(cmd)
171-
)
172-
)
173-
log.write(output)
174-
log.write("\n\n")
165+
if output:
166+
logging.debug(
167+
"Command executed successfully: %s\n%s",
168+
cmdstring,
169+
indent(output, " "),
170+
)
175171
return output
176172
except subprocess.CalledProcessError as e:
177173
if sentry_sdk:
178174
with sentry_sdk.push_scope() as scope:
179175
scope.fingerprint = ["{{ default }}", str(cmd)]
180176
sentry_sdk.capture_exception(e)
181-
if logfile:
182-
with open(logfile, "a+") as log:
183-
log.write("# " + now + "\n")
184-
log.write(
185-
"# Command {} failed:".format(cmd if shell else shlex.join(cmd))
186-
)
187-
log.write(e.output)
188-
log.write("\n\n")
189-
logging.error("Command failed (see %s at %s)", logfile, now)
177+
if e.output:
178+
logging.error("Command %s failed:\n%s", cmdstring, indent(e.output, " "))
190179
else:
191-
logging.error("Command failed with output %r", e.output)
180+
logging.error("Command %s failed.", cmdstring)
192181

193182

194183
def changed_files(left, right):
@@ -430,9 +419,6 @@ def build_one(
430419
+ ("-html" if quick else "")
431420
)
432421
logging.info("Running make %s", maketarget)
433-
logname = "cpython-{lang}-{version}.log".format(
434-
lang=language.tag, version=version.name
435-
)
436422
python = os.path.join(venv, "bin/python")
437423
sphinxbuild = os.path.join(venv, "bin/sphinx-build")
438424
blurb = os.path.join(venv, "bin/blurb")
@@ -460,8 +446,7 @@ def build_one(
460446
"SPHINXOPTS=" + " ".join(sphinxopts),
461447
"SPHINXERRORHANDLING=",
462448
maketarget,
463-
],
464-
logfile=os.path.join(log_directory, logname),
449+
]
465450
)
466451
shell_out(["chgrp", "-R", group, log_directory])
467452
setup_switchers(os.path.join(checkout, "Doc", "build", "html"))

0 commit comments

Comments
 (0)