Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions repo2readme/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
from repo2readme.utils.tree import generate_tree
from repo2readme.utils.detect_language import detect_lang
from concurrent.futures import ThreadPoolExecutor, as_completed
import threading


@click.group()
Expand Down Expand Up @@ -133,13 +131,9 @@ def format_size(size_bytes):

summaries = []
errors = []

# Skip summarization if there are no documents
if total_documents > 0:
summaries_lock = threading.Lock()
errors_lock = threading.Lock()

def process_document(doc):
with Progress() as progress:
task = progress.add_task("[cyan]Generating summaries...[/cyan]", total=total_documents)
for doc in documents:
meta = doc["metadata"]
try:
lang = detect_lang(meta.get("file_type", "text"))
Expand All @@ -148,23 +142,11 @@ def process_document(doc):
language=lang,
content=doc["content"]
)
with summaries_lock:
summaries.append(summary)
except Exception as e:
with errors_lock:
errors.append(f"Error processing {meta.get('file_path')}: {e}")

with Progress() as progress:
task = progress.add_task("[cyan]Generating summaries...[/cyan]", total=total_documents)

# Limit concurrent workers to avoid overwhelming API providers
max_workers = min(2, total_documents)

with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {executor.submit(process_document, doc): doc for doc in documents}

for future in as_completed(futures):
progress.update(task, advance=1)
summaries.append(summary)
except Exception as e:
errors.append(f"Error processing {meta.get('file_path')}: {e}")
progress.update(task, advance=1)

rprint("[cyan]Generating README...[/cyan]")

Expand Down