@@ -17,22 +17,24 @@ import subprocess
17
17
18
18
import os
19
19
20
- cache_file = 'cache_nbrun'
20
+ cache_file = 'cache_nbrun'
21
+
22
+ path_doc = 'source/auto_examples/'
23
+ path_nb = '../notebooks/'
21
24
22
- path_doc = 'source/auto_examples/'
23
- path_nb = '../notebooks/'
24
25
25
26
def load_json (fname ):
26
27
try :
27
- f = open (fname )
28
- nb = json .load (f )
28
+ f = open (fname )
29
+ nb = json .load (f )
29
30
f .close ()
30
- except (OSError , IOError ) :
31
- nb = {}
31
+ except (OSError , IOError ):
32
+ nb = {}
32
33
return nb
33
34
34
- def save_json (fname ,nb ):
35
- f = open (fname ,'w' )
35
+
36
+ def save_json (fname , nb ):
37
+ f = open (fname , 'w' )
36
38
f .write (json .dumps (nb ))
37
39
f .close ()
38
40
@@ -44,39 +46,36 @@ def md5(fname):
44
46
hash_md5 .update (chunk )
45
47
return hash_md5 .hexdigest ()
46
48
47
- def to_update (fname ,cache ):
49
+
50
+ def to_update (fname , cache ):
48
51
if fname in cache :
49
- if md5 (path_doc + fname )== cache [fname ]:
50
- res = False
52
+ if md5 (path_doc + fname ) == cache [fname ]:
53
+ res = False
51
54
else :
52
- res = True
55
+ res = True
53
56
else :
54
- res = True
55
-
57
+ res = True
58
+
56
59
return res
57
60
58
- def update (fname ,cache ):
59
-
61
+
62
+ def update (fname , cache ):
63
+
60
64
# jupyter nbconvert --to notebook --execute mynotebook.ipynb --output targte
61
- subprocess .check_call (['cp' ,path_doc + fname ,path_nb ])
62
- print (' ' .join (['jupyter' ,'nbconvert' ,'--to' ,'notebook' ,'--ExecutePreprocessor.timeout=600' ,'--execute' ,path_nb + fname ,'--inplace' ]))
63
- subprocess .check_call (['jupyter' ,'nbconvert' ,'--to' ,'notebook' ,'--ExecutePreprocessor.timeout=600' ,'--execute' ,path_nb + fname ,'--inplace' ])
64
- cache [fname ]= md5 (path_doc + fname )
65
-
65
+ subprocess .check_call (['cp' , path_doc + fname , path_nb ])
66
+ print (' ' .join (['jupyter' , 'nbconvert' , '--to' , 'notebook' , '--ExecutePreprocessor.timeout=600' , '--execute' , path_nb + fname , '--inplace' ]))
67
+ subprocess .check_call (['jupyter' , 'nbconvert' , '--to' , 'notebook' , '--ExecutePreprocessor.timeout=600' , '--execute' , path_nb + fname , '--inplace' ])
68
+ cache [fname ] = md5 (path_doc + fname )
66
69
67
70
68
- cache = load_json (cache_file )
71
+ cache = load_json (cache_file )
69
72
70
- lst_file = glob .glob (path_doc + '*.ipynb' )
73
+ lst_file = glob .glob (path_doc + '*.ipynb' )
71
74
72
- lst_file = [os .path .basename (name ) for name in lst_file ]
75
+ lst_file = [os .path .basename (name ) for name in lst_file ]
73
76
74
77
for fname in lst_file :
75
- if to_update (fname ,cache ):
78
+ if to_update (fname , cache ):
76
79
print ('Updating file: {}' .format (fname ))
77
- update (fname ,cache )
78
- save_json (cache_file ,cache )
79
-
80
-
81
-
82
-
80
+ update (fname , cache )
81
+ save_json (cache_file , cache )
0 commit comments