@@ -230,6 +230,21 @@ def _link_objs(value):
230230
231231    # Strip off the extra "\ " 
232232    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 
233248
234249
235250class  Mapper :
@@ -307,32 +322,37 @@ def find_files(patterns, dirs, ignore):
307322            regex  =  re .compile (fnmatch .translate (pattern ).replace (".*" , "(.*)" ))
308323            pattern_regexes .append ((pattern , regex ))
309324
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 
312339                seen  =  set ()
313340                for  pattern , pattern_re  in  pattern_regexes :
314341                    for  filename  in  fnmatch .filter (filenames , pattern ):
315-                         skip  =  False 
342+                         skip_file  =  False 
316343
317344                        match  =  re .match (pattern_re , filename )
318345                        norm_name  =  match .groups ()
319346                        if  norm_name  in  seen :
320347                            continue 
321348
322349                        # 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+                             )
336356                            continue 
337357
338358                        # Make sure the path is full 
0 commit comments