Squash-merge lib-standardisation: adopt repo standards across packaging, tooling, docs, and CI. - standardize pyproject.toml (canonical packaging, lint config, extras, GSDFC pydoclint) - add py.typed marker, modernize type hints and Google-style docstrings - nest generated docs under docs/lib and docs/mcp; add hand-written wiki - adopt standard Type A PyPI CI pipeline (tag==version guard + quality gate) - promote generated CHANGELOG.md; bump version to 0.0.7
105 lines
2.6 KiB
Python
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())
|