33# Parse ImageJ tutorials into documents for
44# use with their own searchable collection.
55
6- import logging , os , traceback
6+ import logging , traceback
77import yaml
88from parseutil import first_sentence
99
1212
1313
1414def is_imagej_tutorials (root ):
15- java = os . path . join (root , 'java' )
16- notebooks = os . path . join (root , 'notebooks' )
17- return os . path . isdir (java ) and os . path . isdir (notebooks )
15+ java = Path (root ) / 'java'
16+ notebooks = Path (root ) / 'notebooks'
17+ return java . isdir () and notebooks . isdir ()
1818
1919
20- def parse_java_source (root , path ):
20+ def parse_java_source (path ):
2121 logger .debug (f'Parsing Java source file { path } ...' )
2222
2323 with open (path ) as f :
@@ -30,7 +30,7 @@ def parse_java_source(root, path):
3030 return doc
3131
3232
33- def parse_notebook (root , path ):
33+ def parse_notebook (path ):
3434 logger .debug (f'Parsing notebook { path } ...' )
3535
3636 with open (path ) as f :
@@ -45,37 +45,32 @@ def parse_notebook(root, path):
4545 return doc
4646
4747
48- def find_resources (root , suffix ):
49- # TODO: use pathlib to find all .java or .ipynb (based on suffix) inside root.
50- pass
51-
52-
5348def load_imagej_tutorials (root ):
5449 """
5550 Loads the content from the given imagej/tutorials folder.
5651 See: https://github.com/imagej/tutorials
5752 """
58- java = os . path . join ( siteroot , 'java' )
59- notebooks = os . path . join ( siteroot , 'notebooks' )
60- if not os . path . isdir (java ) or not os . path . isdir (notebooks ):
53+ java = Path ( root ) / 'java'
54+ notebooks = Path ( root ) / 'notebooks'
55+ if not java . isdir () or not notebooks . isdir ():
6156 raise ValueError (f'The path { siteroot } does not appear to be a Jekyll site.' )
6257
6358 logger .info ('Loading content...' )
6459 documents = []
6560
66- for javafile in find_resources ( java , '. java' ):
61+ for javafile in java . rglob ( "**/*. java" ):
6762 try :
68- doc = parse_java_source (root , path )
63+ doc = parse_java_source (javafile )
6964 if doc :
7065 documents .append (doc )
7166 except :
7267 logger .error (f'Failed to parse { path } :' )
7368 traceback .print_exc ()
7469 logger .info (f'Loaded { len (documents )} documents from Java source files' )
7570
76- for nbfile in find_resources ( notebooks , '. ipynb' ):
71+ for nbfile in notebooks . rglob ( "**/*. ipynb" ):
7772 try :
78- doc = parse_notebook (root , path )
73+ doc = parse_notebook (nbfile )
7974 if doc :
8075 documents .append (doc )
8176 except :
0 commit comments