@@ -139,8 +139,11 @@ def _redundant(filename, defined):
139
139
filename .replace ('.png' , '.svg' ) in defined
140
140
141
141
content = get_all_docs (language )
142
- used = _match_lines (content , r'{%\s+include\s+figure.html[^%]+src=".+/figures/([^"]+)"' )
143
- defined = {f for f in os .listdir (FIGURE_DIR ) if not _ignore (f )}
142
+ by_doc = _match_lines_by_doc (content , r'{%\s+include\s+figure.html[^%]+src="([^"]+)"' )
143
+ used = set ()
144
+ for slug in by_doc :
145
+ used |= {os .path .join (FIGURE_DIR , slug , filename ) for filename in by_doc [slug ]}
146
+ defined = {f for f in glob .glob (os .path .join (FIGURE_DIR , '**/*.*' )) if not _ignore (f )}
144
147
defined -= {f for f in defined if _redundant (f , defined )}
145
148
report ('Figures' , 'unused' , defined - used )
146
149
report ('Figures' , 'missing' , used - defined )
@@ -279,15 +282,29 @@ def _match_lines(content, pattern, splitter=None):
279
282
'''
280
283
Find all matches in all lines, splitting and flattening if asked to do so.
281
284
'''
282
- pat = re . compile ( pattern )
285
+ by_doc = _match_lines_by_doc ( content , pattern , splitter = splitter )
283
286
result = set ()
287
+ for doc in by_doc :
288
+ result |= by_doc [doc ]
289
+ return result
290
+
291
+
292
+ def _match_lines_by_doc (content , pattern , splitter = None ):
293
+ '''
294
+ Find all matches in all lines, splitting and flattening if asked to do so.
295
+ Return a dictionary of doc:match_set.
296
+ '''
297
+ pat = re .compile (pattern )
298
+ result = {}
284
299
for (slug , filename , body , lines ) in content :
300
+ temp = set ()
285
301
for line in lines :
286
- result |= set (pat .findall (line ))
287
- if splitter is not None :
288
- result = {individual
289
- for group in result
290
- for individual in group .split (splitter )}
302
+ temp |= set (pat .findall (line ))
303
+ if splitter is not None :
304
+ temp = {individual
305
+ for group in temp
306
+ for individual in group .split (splitter )}
307
+ result [slug ] = temp
291
308
return result
292
309
293
310
0 commit comments