@@ -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
127128def 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
313318def 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