11import os
2-
3-
42import subprocess
5- import tempfile
6-
73import nbformat
84
95_TEST_DIR = os .path .dirname (__file__ )
@@ -16,19 +12,23 @@ def _notebook_run(path):
1612 """
1713 dirname , __ = os .path .split (path )
1814 os .chdir (dirname )
19- with tempfile .NamedTemporaryFile (suffix = ".ipynb" ) as fout :
20- args = ["jupyter" , "nbconvert" , "--to" , "notebook" , "--execute" ,
21- "--ExecutePreprocessor.kernel_name=python" ,
22- "--ExecutePreprocessor.timeout=None" ,
23- "--output" , fout .name , path ]
24- subprocess .check_call (args )
2515
26- fout .seek (0 )
27- nb = nbformat .read (fout , nbformat .current_nbformat )
16+ in_fn = os .path .split (path )[- 1 ].split ('.' )[0 ]
17+ temp_file_prefix = 'output_' + in_fn
18+ temp_file_out = temp_file_prefix + '.ipynb'
19+
20+ args = ["jupyter" , "nbconvert" , "--to" , "notebook" , "--execute" ,
21+ "--ExecutePreprocessor.kernel_name=python" ,
22+ "--ExecutePreprocessor.timeout=None" ,
23+ "--output" , temp_file_prefix , path ]
24+ subprocess .check_call (args )
25+
26+ nb = nbformat .read (temp_file_out , nbformat .current_nbformat , encoding = 'UTF-8' )
2827
2928 errors = [output for cell in nb .cells if "outputs" in cell
3029 for output in cell ["outputs" ]\
3130 if output .output_type == "error" ]
31+ os .remove (temp_file_out )
3232
3333 return nb , errors
3434
0 commit comments