Skip to content

Commit 7858b9a

Browse files
Merge pull request #43 from corticalstack/bugfix/31-runner-kernel-output
fix(ci): keep the notebook kernel's stdout/stderr out of the runner log (#31)
2 parents bb03479 + 16169d3 commit 7858b9a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎scripts/run_notebooks.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
manifest. Nothing is written back unless --save is given, and then only for notebooks that
1010
passed and already keep outputs. Output printed here is safe for public CI logs: notebook,
1111
status, seconds, failing cell index and exception type, never the exception message or any
12-
cell output (--verbose adds the message for local debugging). --check fails if a tracked
12+
cell output, and the kernel's own stdout/stderr is discarded (--verbose adds the message
13+
and lets the kernel's stdout/stderr through, for local debugging). --check fails if a tracked
1314
notebook is missing from the manifest. Exit code 1 if any notebook fails.
1415
"""
1516

@@ -97,8 +98,12 @@ def run(entry, save, verbose):
9798
start = time.time()
9899
result = {"notebook": entry["path"], "status": "pass", "failed_cell": None, "error_type": None}
99100
message = ""
101+
# The kernel inherits this process's stdout/stderr, so anything a cell writes there
102+
# directly (subprocess.run without capture, logging to sys.__stderr__, native CLIs)
103+
# would land in the log. Discard it unless --verbose.
104+
quiet = {} if verbose else {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
100105
try:
101-
client.execute()
106+
client.execute(**quiet)
102107
except CellExecutionError as e:
103108
result.update(status="fail", error_type=getattr(e, "ename", None) or "CellExecutionError")
104109
message = str(getattr(e, "evalue", ""))
@@ -138,7 +143,8 @@ def main():
138143
parser.add_argument("--only", nargs="+", metavar="PATH", help="run just these manifest paths")
139144
parser.add_argument("--results", type=Path, help="write a JSON list of results here")
140145
parser.add_argument("--save", action="store_true", help="write outputs back for notebooks that pass")
141-
parser.add_argument("--verbose", action="store_true", help="also print exception messages (not for CI)")
146+
parser.add_argument("--verbose", action="store_true",
147+
help="also print exception messages and kernel stdout/stderr (not for CI)")
142148
parser.add_argument("--list", action="store_true", help="print the selection without running it")
143149
parser.add_argument("--check", action="store_true", help="verify the manifest lists every notebook")
144150
parser.add_argument("--before-each", metavar="COMMAND",

0 commit comments

Comments
 (0)