From 13bfe61c4d5df9e31559d7e6a11d9b2e66e4657d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awek=20Ehlert?= Date: Sun, 13 Aug 2023 12:04:05 +0200 Subject: [PATCH] Make file processing order deterministic By using `set` for specifying files in queue we loose the order in which the files will be processed (in `missing_files` var). --- bump_pydantic/main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bump_pydantic/main.py b/bump_pydantic/main.py index 62259ff..eda6c61 100644 --- a/bump_pydantic/main.py +++ b/bump_pydantic/main.py @@ -4,6 +4,7 @@ import os import time import traceback +from collections import deque from pathlib import Path from typing import Any, Dict, Iterable, List, Set, Tuple, Type, TypeVar, Union @@ -84,7 +85,7 @@ def main( scratch: dict[str, Any] = {} with Progress(*Progress.get_default_columns(), transient=True) as progress: task = progress.add_task(description="Looking for Pydantic Models...", total=len(files)) - queue: List[str] = [files[0]] + queue = deque(files) visited: Set[str] = set() while queue: @@ -111,11 +112,7 @@ def main( # Queue logic next_file = visitor.next_file(visited) if next_file is not None: - queue.append(next_file) - - missing_files = set(files) - visited - if not queue and missing_files: - queue.append(next(iter(missing_files))) + queue.appendleft(next_file) start_time = time.time()