added docs strings
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
2026-01-21 01:00:12 +05:30
parent 81e8a8cd49
commit b6e5114532
17 changed files with 563 additions and 25 deletions

View File

@@ -1,3 +1,19 @@
"""
# Loader Layer
The `docforge.loader` 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 `griffe` to parse docstrings, signatures, and
hierarchical relationships without executing the code.
- **Filtering**: Automatically excludes private members (prefixed with `_`) to
ensure clean public documentation.
"""
from .griffe_loader import GriffeLoader, discover_module_paths
__all__ = [

View File

@@ -1,3 +1,8 @@
"""
This module provides the GriffeLoader, which uses the 'griffe' library to
introspect Python source code and populate the doc-forge Project model.
"""
import logging
from pathlib import Path
from typing import List, Optional
@@ -23,9 +28,16 @@ def discover_module_paths(
Discover all Python modules under a package via filesystem traversal.
Rules:
- Directory with __init__.py => package
- .py file => module
- Paths converted to dotted module paths
- 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.
Args:
module_name: The name of the package to discover.
project_root: The root directory of the project. Defaults to current working directory.
Returns:
A sorted list of dotted module paths.
"""
if project_root is None:
@@ -51,9 +63,14 @@ def discover_module_paths(
class GriffeLoader:
"""Loads Python modules using Griffe introspection."""
"""
Loads Python modules and extracts documentation using the Griffe introspection engine.
"""
def __init__(self) -> None:
"""
Initialize the GriffeLoader.
"""
self._loader = _GriffeLoader(
modules_collection=ModulesCollection(),
lines_collection=LinesCollection(),
@@ -65,6 +82,17 @@ class GriffeLoader:
project_name: Optional[str] = None,
skip_import_errors: bool = None,
) -> Project:
"""
Load multiple modules and combine them into a single Project model.
Args:
module_paths: A list of dotted paths to the modules to load.
project_name: Optional name for the project. Defaults to the first module name.
skip_import_errors: If True, modules that fail to import will be skipped.
Returns:
A Project instance containing the loaded modules.
"""
if not module_paths:
raise ValueError("At least one module path must be provided")
@@ -87,6 +115,15 @@ class GriffeLoader:
return project
def load_module(self, path: str) -> Module:
"""
Load a single module and convert its introspection data into the docforge model.
Args:
path: The dotted path of the module to load.
Returns:
A Module instance.
"""
self._loader.load(path)
griffe_module = self._loader.modules_collection[path]