Loaders
docforge.loaders
Loader Layer
The docforge.loaders package is responsible for discovering Python source files
and extracting their documentation using static analysis.
Core Features
- Discovery: Automatically find all modules and packages in a project directory.
- Introspection: Uses
griffeto parse docstrings, signatures, and hierarchical relationships without executing the code. - Filtering: Automatically excludes private members (prefixed with
_) to ensure clean public documentation.
GriffeLoader
GriffeLoader()
Loads Python modules and extracts documentation using the Griffe introspection engine.
Initialize the GriffeLoader.
load_module
load_module(path: str) -> Module
Load a single module and convert its introspection data into the docforge models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The dotted path of the module to load. |
required |
Returns:
| Type | Description |
|---|---|
Module
|
A Module instance. |
load_project
load_project(module_paths: List[str], project_name: Optional[str] = None, skip_import_errors: bool = None) -> Project
Load multiple modules and combine them into a single Project models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_paths |
List[str]
|
A list of dotted paths to the modules to load. |
required |
project_name |
Optional[str]
|
Optional name for the project. Defaults to the first module name. |
None
|
skip_import_errors |
bool
|
If True, modules that fail to import will be skipped. |
None
|
Returns:
| Type | Description |
|---|---|
Project
|
A Project instance containing the loaded modules. |
discover_module_paths
discover_module_paths(module_name: str, project_root: Path | None = None) -> List[str]
Discover all Python modules under a package via filesystem traversal.
Rules: - Directory with init.py is treated as a package. - Any .py file is treated as a module. - All paths are converted to dotted module paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name |
str
|
The name of the package to discover. |
required |
project_root |
Path | None
|
The root directory of the project. Defaults to current working directory. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A sorted list of dotted module paths. |