Skip to content

Commit

Permalink
🐛 Make file processing with ClassDefVisitor deterministic (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
slafs committed Aug 14, 2023
1 parent dda0b55 commit b08f445
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 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 @@ -66,7 +67,7 @@ def main(
all_files = [path]
else:
package = path
all_files = list(package.glob("**/*.py"))
all_files = sorted(package.glob("**/*.py"))

filtered_files = [file for file in all_files if not any(match_glob(file, pattern) for pattern in ignore)]
files = [str(file.relative_to(".")) for file in filtered_files]
Expand All @@ -84,12 +85,12 @@ 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:
# Queue logic
filename = queue.pop()
filename = queue.popleft()
visited.add(filename)
progress.advance(task)

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 b08f445

Please sign in to comment.