@@ -34,6 +34,8 @@ def parse_args() -> argparse.Namespace:
34
34
35
35
def process_repo (repo , destination_directory ):
36
36
"""Process a tutorial repository to copy its rendered tutorial(s) into `destination_directory`."""
37
+ os .makedirs (destination_directory , exist_ok = True )
38
+
37
39
repo_name = repo ["full_name" ]
38
40
if not repo_name .split ("/" )[1 ].startswith ("tutorial--" ):
39
41
return
@@ -53,6 +55,7 @@ def process_repo(repo, destination_directory):
53
55
return
54
56
55
57
repo = Path (tmp )
58
+ # os.system(f'tree {repo}')
56
59
tutorials = glob .glob (f"{ repo } /_sources/*.ipynb" )
57
60
for t in tutorials :
58
61
tname = os .path .splitext (os .path .basename (t ))[0 ]
@@ -67,9 +70,14 @@ def process_repo(repo, destination_directory):
67
70
print (f"More than 1 tutorial found; also copying index file { index } " )
68
71
shutil .copy (index , destination_directory )
69
72
# copy images (plots) in notebook for faster page loading
70
- try :
71
- shutil .copy (f"{ repo } /_images/*.png" , f"{ destination_directory } /nboutput" )
72
- except FileNotFoundError :
73
+ images = glob .glob (f"{ repo } /_images/*.png" )
74
+ if len (images ) > 0 :
75
+ print ("Copying notebook cell output images" )
76
+ image_dir = f"{ destination_directory } /nboutput"
77
+ os .makedirs (image_dir , exist_ok = True )
78
+ for i in images :
79
+ shutil .copy (i , image_dir )
80
+ else :
73
81
print ("No notebook cell output images found to copy" )
74
82
75
83
0 commit comments