Commit 98b324ad authored by Matthias Bernt's avatar Matthias Bernt
Browse files

refactor: do not store intermediate lists

parent c01f9d47
Loading
Loading
Loading
Loading
+21 −18
Original line number Diff line number Diff line
@@ -512,8 +512,9 @@ def walk_over_extra_files(target_dir, extra_file_collector, job_working_director
    match the given collector's match criteria. If the collector has the
    recurse flag enabled, will also recursively descend into child folders.
    """
    matches = []
    parent_paths = parent_paths or []

    def _walk(target_dir, extra_file_collector, job_working_directory, matchable, parent_paths):
        directory = discover_target_directory(target_dir, job_working_directory)
        if os.path.isdir(directory):
            for filename in os.listdir(directory):
@@ -523,15 +524,17 @@ def walk_over_extra_files(target_dir, extra_file_collector, job_working_director
                        new_parent_paths = parent_paths[:]
                        new_parent_paths.append(filename)
                        # The current directory is already validated, so use that as the next job_working_directory when recursing
                    matches.extend(walk_over_extra_files(
                        yield from _walk(
                            filename, extra_file_collector, directory, matchable, parent_paths=new_parent_paths
                    ))
                        )
                else:
                    match = extra_file_collector.match(matchable, filename, path=path, parent_paths=parent_paths)
                    if match:
                    matches.append(match)
                        yield match

    for match in extra_file_collector.sort(matches):
    for match in extra_file_collector.sort(
        _walk(target_dir, extra_file_collector, job_working_directory, matchable, parent_paths)
    ):
        yield match