@@ -230,6 +230,21 @@ def _link_objs(value):
230
230
231
231
# Strip off the extra "\ "
232
232
return result [:- 2 ]
233
+
234
+ def _path_matches_patterns (path , patterns ):
235
+ """Check if a path matches one of multiple patterns
236
+
237
+ Args:
238
+ path (str): path to a file or directory to check
239
+ patterns (list): list of patterns for fnmatch
240
+
241
+ Returns:
242
+ bool: Whether or not the path matches a pattern in patterns
243
+ """
244
+ for pattern in patterns :
245
+ if fnmatch .fnmatch (path , pattern ):
246
+ return True
247
+ return False
233
248
234
249
235
250
class Mapper :
@@ -307,32 +322,37 @@ def find_files(patterns, dirs, ignore):
307
322
regex = re .compile (fnmatch .translate (pattern ).replace (".*" , "(.*)" ))
308
323
pattern_regexes .append ((pattern , regex ))
309
324
310
- for _dir in dirs :
311
- for root , _ , filenames in os .walk (_dir ):
325
+ for _dir in dirs : # iterate autoapi_dirs
326
+ for root , subdirectories , filenames in os .walk (_dir ):
327
+ # skip directories if needed
328
+ for sub_dir in subdirectories .copy ():
329
+ # iterate copy as we adapt subdirectories during loop
330
+ if _path_matches_patterns (os .path .join (root , sub_dir ), ignore ) == True :
331
+ LOGGER .info (
332
+ colorize ("bold" , "[AutoAPI] " )
333
+ + colorize (
334
+ "darkgreen" , f"Ignoring directory: { root } /{ sub_dir } /" )
335
+ )
336
+ # adapt original subdirectories inplace
337
+ subdirectories .remove (sub_dir )
338
+ # recurse into remaining directories
312
339
seen = set ()
313
340
for pattern , pattern_re in pattern_regexes :
314
341
for filename in fnmatch .filter (filenames , pattern ):
315
- skip = False
342
+ skip_file = False
316
343
317
344
match = re .match (pattern_re , filename )
318
345
norm_name = match .groups ()
319
346
if norm_name in seen :
320
347
continue
321
348
322
349
# Skip ignored files
323
- for ignore_pattern in ignore :
324
- if fnmatch .fnmatch (
325
- os .path .join (root , filename ), ignore_pattern
326
- ):
327
- LOGGER .info (
328
- colorize ("bold" , "[AutoAPI] " )
329
- + colorize (
330
- "darkgreen" , f"Ignoring { root } /{ filename } "
331
- )
332
- )
333
- skip = True
334
-
335
- if skip :
350
+ if _path_matches_patterns (os .path .join (root , filename ), ignore ):
351
+ LOGGER .info (
352
+ colorize ("bold" , "[AutoAPI] " )
353
+ + colorize (
354
+ "darkgreen" , f"Ignoring file: { root } /{ filename } " )
355
+ )
336
356
continue
337
357
338
358
# Make sure the path is full
0 commit comments