file_utils.py


Overview

The `file_utils.py` module provides utility functions to discover and read files within specified directories. Its primary purpose is to facilitate file system operations related to source code and documentation files by:

This module is particularly useful in projects where automated processing or analysis of source code and documentation files is required, such as code documentation generation, static analysis, or project indexing.


Detailed Description of Functions

discover_files(code_dir: str, docs_dir: str) -> Tuple[List[str], List[str]]

Purpose

Discovers source code files within a given code directory and markdown documentation files within a documentation directory.

Parameters

Returns

Behavior and Implementation Details

Usage Example

from file_utils import discover_files

code_files, doc_files = discover_files('/path/to/source', '/path/to/docs')

print("Source code files found:")
for file_path in code_files:
    print(file_path)

print("Documentation files found:")
for doc_path in doc_files:
    print(doc_path)

read_text_file(path: str) -> str

Purpose

Reads the entire content of a text file and returns it as a string.

Parameters

Returns

Behavior and Implementation Details

Usage Example

from file_utils import read_text_file

content = read_text_file('/path/to/some/file.md')
print(content)

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram - Flowchart of Main Functions and Their Relationships

flowchart TD
    A[Start] --> B[discover_files(code_dir, docs_dir)]
    B --> C{Traverse code_dir}
    C -->|For each file| D[Check file extension in EXT_LANG_MAP]
    D -- Yes --> E[Add file path to code_paths]
    D -- No --> F[Skip file]
    C --> G{Traverse docs_dir}
    G -->|For each file| H[Check if file ends with .md]
    H -- Yes --> I[Add file path to doc_paths]
    H -- No --> J[Skip file]
    E & I --> K[Sort code_paths and doc_paths]
    K --> L[Return (code_paths, doc_paths)]
    
    M[read_text_file(path)] --> N[Open file with UTF-8 encoding]
    N --> O[Read entire content]
    O --> P[Return content as string]

Summary

The `file_utils.py` module is a concise and focused utility for discovering source code and markdown documentation files within specified directories and reading text file contents safely. Its reliance on a configurable extension map allows adaptability to different programming languages and project structures. This module acts as a foundational component in systems that require organized access to project files for processing or documentation purposes.