Skip to content

Commit cb9872b

Browse files
committed
Fixed linting
1 parent 4c28452 commit cb9872b

File tree

5 files changed

+227
-203
lines changed

5 files changed

+227
-203
lines changed

src/docs2llm/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"""
77

88
from docs2llm.main import (
9-
extract_documentation,
10-
setup_logging,
11-
is_documentation_file,
12-
markdown_to_text,
13-
clone_repository,
14-
find_documentation_files,
15-
process_documentation_files
9+
extract_documentation, # noqa: F401
10+
setup_logging, # noqa: F401
11+
is_documentation_file, # noqa: F401
12+
markdown_to_text, # noqa: F401
13+
clone_repository, # noqa: F401
14+
find_documentation_files, # noqa: F401
15+
process_documentation_files, # noqa: F401
1616
)
1717

1818
__version__ = "0.1.0"

src/docs2llm/cli.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,37 @@
33
import click
44
from docs2llm.main import extract_documentation, console
55

6+
67
@click.command()
78
@click.argument("path", required=False)
8-
@click.option("--git", help="GitHub repository URL (e.g., https://github.com/owner/repo.git)")
9+
@click.option(
10+
"--git", help="GitHub repository URL (e.g., https://github.com/owner/repo.git)"
11+
)
912
@click.option("--output", default="llm_context.txt", help="Output file name")
10-
@click.option("--max-depth", type=int, default=3, help="Maximum directory depth to search")
13+
@click.option(
14+
"--max-depth", type=int, default=3, help="Maximum directory depth to search"
15+
)
1116
@click.option("--branch", help="Specific branch to clone (only used with --git)")
1217
@click.option("--verbose", "-v", is_flag=True, help="Enable verbose logging")
1318
@click.option("--log-file", help="Log to this file in addition to console")
1419
def main(path, git, output, max_depth, branch, verbose, log_file):
1520
"""Generate LLM context from documentation in a directory or GitHub repository.
16-
21+
1722
PATH: Local directory path containing documentation files
18-
23+
1924
You can either provide a local path or use --git with a GitHub repository URL.
2025
Example: --git https://github.com/owner/repo.git
2126
"""
2227
if not path and not git:
23-
console.print("[bold red]Error: Either a local path or --git option must be provided.[/bold red]")
28+
console.print(
29+
"[bold red]Error: Either a local path or --git option must be provided.[/bold red]"
30+
)
2431
sys.exit(1)
25-
32+
2633
if path and git:
27-
console.print("[bold red]Error: Cannot specify both a local path and --git. Choose one input source.[/bold red]")
34+
console.print(
35+
"[bold red]Error: Cannot specify both a local path and --git. Choose one input source.[/bold red]"
36+
)
2837
sys.exit(1)
2938

3039
success = extract_documentation(
@@ -34,12 +43,12 @@ def main(path, git, output, max_depth, branch, verbose, log_file):
3443
max_depth=max_depth,
3544
branch=branch,
3645
verbose=verbose,
37-
log_file=log_file
46+
log_file=log_file,
3847
)
39-
48+
4049
# Exit without any success/failure message
4150
sys.exit(0 if success else 1)
4251

4352

4453
if __name__ == "__main__":
45-
main()
54+
main()

src/docs2llm/main.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def setup_logging(verbose=False, log_file=None, use_rich=True):
3232

3333
# Create console handler, using Rich if available
3434
if use_rich:
35-
console_handler = RichHandler(console=console, rich_tracebacks=True,
36-
show_time=False, show_path=False)
35+
console_handler = RichHandler(
36+
console=console, rich_tracebacks=True, show_time=False, show_path=False
37+
)
3738
root_logger.addHandler(console_handler)
3839
else:
3940
console_handler = logging.StreamHandler(sys.stdout)
@@ -126,7 +127,7 @@ def markdown_to_text(markdown_content):
126127

127128
def clone_repository(repo_path, temp_dir, branch=None):
128129
"""Clone a GitHub repository to a local directory.
129-
130+
130131
Args:
131132
repo_path: GitHub repository URL or owner/repo format
132133
temp_dir: Directory to clone the repository into
@@ -149,7 +150,7 @@ def clone_repository(repo_path, temp_dir, branch=None):
149150
# Traditional owner/repo format (for backward compatibility)
150151
clone_url = f"https://github.com/{repo_path}.git"
151152
owner_repo = repo_path
152-
153+
153154
logging.info(f"Cloning repository {clone_url} to temporary directory")
154155

155156
start_time = time.time()
@@ -207,7 +208,7 @@ def find_documentation_files(repo_dir, max_depth=3):
207208
logging.info(f"Searching for documentation files (max depth: {max_depth})")
208209

209210
# Skip .git directory
210-
with console.status(f"[bold blue]Scanning repository...", spinner="dots") as status:
211+
with console.status("[bold blue]Scanning repository...", spinner="dots") as status:
211212
# Walk the directory tree
212213
for root, dirs, files in os.walk(repo_dir):
213214
# Remove .git directory from traversal
@@ -269,14 +270,18 @@ def process_documentation_files(repo_dir, doc_files):
269270

270271
logging.info(f"Processing {len(doc_files)} documentation files")
271272

272-
with console.status(f"[bold blue]Processing documentation files...", spinner="dots") as status:
273+
with console.status(
274+
"[bold blue]Processing documentation files...", spinner="dots"
275+
) as status:
273276
file_count = 0
274-
277+
275278
for file_path in sorted_files:
276279
full_path = os.path.join(repo_dir, file_path)
277280
try:
278281
file_count += 1
279-
status.update(f"[cyan]Processing: {file_path} ({file_count}/{len(doc_files)})")
282+
status.update(
283+
f"[cyan]Processing: {file_path} ({file_count}/{len(doc_files)})"
284+
)
280285
logging.debug(f"Processing {file_path}...")
281286

282287
# Read file content
@@ -302,7 +307,7 @@ def process_documentation_files(repo_dir, doc_files):
302307

303308
except Exception as e:
304309
logging.error(f"Error processing {file_path}: {e}", exc_info=True)
305-
310+
306311
status.update("[bold green]Processing complete")
307312

308313
total_length = sum(len(text) for text in docs_text)
@@ -311,16 +316,16 @@ def process_documentation_files(repo_dir, doc_files):
311316

312317

313318
def extract_documentation(
314-
local_path=None,
315-
git_repo=None,
316-
output_file="llm_context.txt",
317-
max_depth=3,
318-
branch=None,
319-
verbose=False,
320-
log_file=None
319+
local_path=None,
320+
git_repo=None,
321+
output_file="llm_context.txt",
322+
max_depth=3,
323+
branch=None,
324+
verbose=False,
325+
log_file=None,
321326
):
322327
"""Extract documentation from a local directory or a GitHub repository.
323-
328+
324329
Args:
325330
local_path: Path to a local directory containing documentation
326331
git_repo: GitHub repository in the format 'owner/repo'
@@ -329,40 +334,39 @@ def extract_documentation(
329334
branch: Specific branch to clone (only used with git_repo)
330335
verbose: Enable verbose logging
331336
log_file: Path to a file where logs will be written in addition to the console
332-
337+
333338
Returns:
334339
bool: True if the extraction was successful, False otherwise
335340
"""
336341
# Setup logging
337342
setup_logging(verbose=verbose, log_file=log_file)
338-
343+
339344
# Determine if we're using a local path or git repo
340345
is_local = local_path is not None
341-
source_path = local_path if is_local else git_repo
342-
346+
343347
try:
344348
if is_local:
345349
# Using local directory
346350
if not exists(local_path):
347351
logging.error(f"Local path does not exist: {local_path}")
348352
return False
349-
353+
350354
if not isdir(local_path):
351355
logging.error(f"Path is not a directory: {local_path}")
352356
return False
353-
357+
354358
logging.info(f"Using local directory: {local_path}")
355-
359+
356360
# Process the local directory
357361
doc_files = find_documentation_files(local_path, max_depth)
358-
362+
359363
if not doc_files:
360364
logging.warning("No documentation files found in the directory.")
361365
return False
362-
366+
363367
# Process the documentation files
364368
docs_text = process_documentation_files(local_path, doc_files)
365-
369+
366370
# Create header for local directory
367371
dir_name = os.path.basename(os.path.abspath(local_path))
368372
header = f"""# Documentation from local directory: {local_path}
@@ -421,7 +425,7 @@ def extract_documentation(
421425
return False
422426

423427
file_size_kb = os.path.getsize(output_file) / 1024
424-
428+
425429
console.print(f"[bold green]Documentation saved to [blue]{output_file}[/blue]")
426430
console.print(f"[bold green]Total size: [yellow]{file_size_kb:.1f}[/yellow] KB")
427431

@@ -430,9 +434,9 @@ def extract_documentation(
430434
f"[bold yellow]Warning: The output file is large ({file_size_kb:.1f} KB). "
431435
f"This may exceed context limits for some LLMs.[/bold yellow]"
432436
)
433-
437+
434438
return True
435439

436440
except Exception as e:
437441
logging.error(f"An error occurred: {e}", exc_info=True)
438-
return False
442+
return False

0 commit comments

Comments
 (0)