refactor: move file-finding and chunking utilities to helpers.py

This commit is contained in:
2025-08-04 09:24:39 +02:00
parent 5690fcdcaf
commit 5705d88092

View File

@@ -1,7 +1,7 @@
import os
import re
from pathlib import Path
from typing import Optional
from typing import Optional, List
def find_matching_hk_file(pbp_path: str) -> Optional[str]:
@@ -28,3 +28,23 @@ def extract_base_filename(file_path: str) -> str:
if len(parts) >= 2:
return f"{parts[-2]}_{parts[-1]}"
return Path(file_path).stem
def find_files(directory: str, pattern: str) -> List[str]:
"""
Recursively find all files in `directory` containing `pattern`.
"""
matches = []
for root, _, files in os.walk(directory):
for f in files:
if pattern in f:
matches.append(str(Path(root) / f))
return sorted(matches)
def chunks(lst: List[str], n: int):
"""
Yield successive `n`-sized chunks from list `lst`.
"""
for i in range(0, len(lst), n):
yield lst[i : i + n]