Files
doc-forge/docforge/models/project.py
Vishesh 'ironeagle' Bangotra 582b6809a0 docs: bring docforge docstrings and wiki to GSDFC standard
- fix GSDFC spec contradictions in __init__ docstring (parenthesized types, fenced-block rule) and sync generated README
- rewrite docstrings across loaders, models, nav, servers, renderers, cli; sync .pyi stubs
- add pydoclint (google style) gate to dev extras and pyproject config
- fix mcp nav resources doc:// -> docs://
- refresh docs/lib and docs/mcp, drop stale docforge/ duplicate group
- update wiki pages and add GSDFC + MCP guides under 05_development
2026-09-12 13:12:51 +05:30

105 lines
2.6 KiB
Python

"""
# Summary
Documentation model representing a project.
This module defines the `Project` class, the top-level container used by
doc-forge to represent a documented codebase. A `Project` aggregates multiple
modules and provides access to them through a unified interface.
---
Notes:
- Modules are keyed by their dotted import path.
- Objects are renderer-agnostic; the same model feeds every renderer.
---
"""
from collections.abc import Iterable
from docforge.models.module import Module
class Project:
"""
Representation of a documentation project.
A `Project` serves as the root container for all modules discovered during
introspection. Each module is stored by its dotted import path.
Attributes:
name (str):
Name of the project.
modules (dict[str, Module]):
Mapping of module paths to `Module` instances.
"""
def __init__(self, name: str) -> None:
"""
Initialize a Project instance.
Args:
name (str):
Name used to identify the documentation project.
Example:
Create a project and register a module:
```python
project = Project("mypackage")
project.add_module(module)
```
"""
self.name = name
self.modules: dict[str, Module] = {}
def add_module(self, module: Module) -> None:
"""
Register a module in the project.
Args:
module (Module):
Module instance to add to the project.
"""
self.modules[module.path] = module
def get_module(self, path: str) -> Module:
"""
Retrieve a module by its dotted path.
Args:
path (str):
Fully qualified dotted module path (for example `pkg.module`).
Returns:
Module:
The corresponding `Module` instance.
Raises:
KeyError:
If the module does not exist in the project.
"""
return self.modules[path]
def get_all_modules(self) -> Iterable[Module]:
"""
Return all modules contained in the project.
Returns:
Iterable[Module]:
An iterable of `Module` instances.
"""
return self.modules.values()
def get_module_list(self) -> list[str]:
"""
Return the list of module import paths.
Returns:
list[str]:
A list containing the dotted paths of all modules in the project.
"""
return list(self.modules.keys())