Skip to content

Commit 8534c2c

Browse files
committed
šŸ‘Œ IMPROVE: Store error log path in env.nb_execution_data
1 parent f7260f4 commit 8534c2c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

ā€Žmyst_nb/cache.pyā€Ž

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ def generate_notebook_outputs(
134134
allow_errors=env.config["execution_allow_errors"],
135135
)
136136

137+
report_path = None
137138
if result.err:
138-
message = _report_exec_fail(
139+
report_path, message = _report_exec_fail(
139140
env,
140141
Path(file_path).name,
141142
result.exc_string,
@@ -152,15 +153,19 @@ def generate_notebook_outputs(
152153
"method": execution_method,
153154
"succeeded": False if result.err else True,
154155
}
156+
if report_path:
157+
env.nb_execution_data[env.docname]["error_log"] = report_path
155158

156159
return ntbk
157160

158161
cache_base = get_cache(path_to_cache)
159162
# Use relpath here in case Sphinx is building from a non-parent folder
160163
r_file_path = Path(os.path.relpath(file_path, Path().resolve()))
161164

165+
# default execution data
162166
runtime = None
163167
succeeded = False
168+
report_path = None
164169

165170
try:
166171
pk, ntbk = cache_base.merge_match_into_notebook(ntbk)
@@ -174,13 +179,14 @@ def generate_notebook_outputs(
174179
except KeyError:
175180
stage_record = None
176181
if stage_record and stage_record.traceback:
177-
message += _report_exec_fail(
182+
report_path, suffix = _report_exec_fail(
178183
env,
179184
r_file_path.name,
180185
stage_record.traceback,
181186
show_traceback,
182187
"\n Last execution failed with traceback saved in {}",
183188
)
189+
message += suffix
184190

185191
LOGGER.error(message)
186192

@@ -207,6 +213,8 @@ def generate_notebook_outputs(
207213
"method": execution_method,
208214
"succeeded": succeeded,
209215
}
216+
if report_path:
217+
env.nb_execution_data[env.docname]["error_log"] = report_path
210218

211219
return ntbk
212220

@@ -233,7 +241,7 @@ def _report_exec_fail(
233241
message = template.format(full_path)
234242
if show_traceback:
235243
message += "\n" + traceback
236-
return message
244+
return str(full_path), message
237245

238246

239247
def _stage_and_execute(

ā€Žtests/test_execute.pyā€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_basic_failing_cache(sphinx_run, file_regression, check_nbs):
9696
assert "basic_failing" in sphinx_run.env.nb_execution_data
9797
assert sphinx_run.env.nb_execution_data["basic_failing"]["method"] == "cache"
9898
assert sphinx_run.env.nb_execution_data["basic_failing"]["succeeded"] is False
99+
assert "error_log" in sphinx_run.env.nb_execution_data["basic_failing"]
99100

100101

101102
@pytest.mark.sphinx_params(
@@ -113,6 +114,7 @@ def test_basic_failing_auto(sphinx_run, file_regression, check_nbs):
113114
assert "basic_failing" in sphinx_run.env.nb_execution_data
114115
assert sphinx_run.env.nb_execution_data["basic_failing"]["method"] == "auto"
115116
assert sphinx_run.env.nb_execution_data["basic_failing"]["succeeded"] is False
117+
assert "error_log" in sphinx_run.env.nb_execution_data["basic_failing"]
116118

117119

118120
@pytest.mark.sphinx_params(

0 commit comments

Comments
Ā (0)
⚔