@@ -388,19 +388,30 @@ def is_ignored(self, path: str) -> Optional[bool]:
388388 return matches [- 1 ].is_exclude
389389 return None
390390
391- def walk (self , ** kwargs ) -> Generator [tuple [str , list [str ], list [str ]], None , None ]:
392- """Wrap os.walk() without ignored files and subdirectories and kwargs are passed to walk."""
391+ def walk_with_ignored (
392+ self , ** kwargs
393+ ) -> Generator [tuple [str , list [str ], list [str ], list [str ], list [str ]], None , None ]:
394+ """Wrap os.walk() and also return lists of ignored directories and files.
395+
396+ Yields tuples: (dirpath, included_dirnames, included_filenames, ignored_dirnames, ignored_filenames)
397+ """
393398 for dirpath , dirnames , filenames in os .walk (self .path , topdown = True , ** kwargs ):
394399 rel_dirpath = '' if dirpath == self .path else os .path .relpath (dirpath , self .path )
395400
401+ original_dirnames = list (dirnames )
402+ included_dirnames = [d for d in original_dirnames if not self .is_ignored (os .path .join (rel_dirpath , d ))]
403+
396404 # decrease recursion depth of os.walk() by ignoring subdirectories because of topdown=True
397405 # slicing ([:]) is mandatory to change dict in-place!
398- dirnames [:] = [d for d in dirnames if not self .is_ignored (os .path .join (rel_dirpath , d ))]
406+ dirnames [:] = included_dirnames
407+
408+ ignored_dirnames = [d for d in original_dirnames if d not in included_dirnames ]
399409
400- # remove ignored files
401- filenames = [f for f in filenames if not self .is_ignored (os .path .join (rel_dirpath , f ))]
410+ original_filenames = list (filenames )
411+ included_filenames = [f for f in original_filenames if not self .is_ignored (os .path .join (rel_dirpath , f ))]
412+ ignored_filenames = [f for f in original_filenames if f not in included_filenames ]
402413
403- yield dirpath , dirnames , filenames
414+ yield dirpath , dirnames , included_filenames , ignored_dirnames , ignored_filenames
404415
405416 @classmethod
406417 def build (
0 commit comments