Skip to content

Commit

Permalink
Make file processing order deterministic
Browse files Browse the repository at this point in the history
By using `set` for specifying files in queue
we loose the order in which the files will be processed
(in `missing_files` var).
  • Loading branch information
slafs committed Aug 13, 2023
1 parent dda0b55 commit 13bfe61
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions bump_pydantic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand Down

0 comments on commit 13bfe61

Please sign in to comment.