introspection

This commit is contained in:
2026-01-20 20:24:22 +05:30
parent c910da9d14
commit 102ea4e215
26 changed files with 525 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
"""
Core documentation model for doc-forge.
These classes form the renderer-agnostic, introspection-derived
representation of Python documentation.
"""
from .project import Project
from .module import Module
from .object import DocObject
__all__ = [
"Project",
"Module",
"DocObject",
]

View File

@@ -0,0 +1,5 @@
from .project import Project
from .module import Module
from .object import DocObject
__all__ = ["Project", "Module", "DocObject"]

27
docforge/model/module.py Normal file
View File

@@ -0,0 +1,27 @@
from __future__ import annotations
from typing import Dict, Iterable, Optional
from docforge.model.object import DocObject
class Module:
"""Represents a documented Python module."""
def __init__(
self,
path: str,
docstring: Optional[str] = None,
) -> None:
self.path = path
self.docstring = docstring
self.members: Dict[str, DocObject] = {}
def add_object(self, obj: DocObject) -> None:
self.members[obj.name] = obj
def get_object(self, name: str) -> DocObject:
return self.members[name]
def get_all_objects(self) -> Iterable[DocObject]:
return self.members.values()

23
docforge/model/module.pyi Normal file
View File

@@ -0,0 +1,23 @@
from typing import Dict, Iterable, Optional
from docforge.model.object import DocObject
class Module:
"""Represents a documented Python module."""
path: str
docstring: Optional[str]
members: Dict[str, DocObject]
def __init__(
self,
path: str,
docstring: Optional[str] = ...,
) -> None: ...
def add_object(self, obj: DocObject) -> None: ...
def get_object(self, name: str) -> DocObject: ...
def get_all_objects(self) -> Iterable[DocObject]: ...

31
docforge/model/object.py Normal file
View File

@@ -0,0 +1,31 @@
from __future__ import annotations
from typing import Dict, Iterable, Optional
class DocObject:
"""Represents a documented Python object."""
def __init__(
self,
name: str,
kind: str,
path: str,
signature: Optional[str] = None,
docstring: Optional[str] = None,
) -> None:
self.name = name
self.kind = kind
self.path = path
self.signature = signature
self.docstring = docstring
self.members: Dict[str, DocObject] = {}
def add_member(self, obj: DocObject) -> None:
self.members[obj.name] = obj
def get_member(self, name: str) -> DocObject:
return self.members[name]
def get_all_members(self) -> Iterable[DocObject]:
return self.members.values()

27
docforge/model/object.pyi Normal file
View File

@@ -0,0 +1,27 @@
from typing import Dict, Iterable, Optional
class DocObject:
"""Represents a documented Python object."""
name: str
kind: str
path: str
signature: Optional[str]
docstring: Optional[str]
members: Dict[str, "DocObject"]
def __init__(
self,
name: str,
kind: str,
path: str,
signature: Optional[str] = ...,
docstring: Optional[str] = ...,
) -> None: ...
def add_member(self, obj: "DocObject") -> None: ...
def get_member(self, name: str) -> "DocObject": ...
def get_all_members(self) -> Iterable["DocObject"]: ...

25
docforge/model/project.py Normal file
View File

@@ -0,0 +1,25 @@
from __future__ import annotations
from typing import Dict, Iterable
from docforge.model.module import Module
class Project:
"""Represents a documentation project."""
def __init__(self, name: str) -> None:
self.name = name
self.modules: Dict[str, Module] = {}
def add_module(self, module: Module) -> None:
self.modules[module.path] = module
def get_module(self, path: str) -> Module:
return self.modules[path]
def get_all_modules(self) -> Iterable[Module]:
return self.modules.values()
def get_module_list(self) -> list[str]:
return list(self.modules.keys())

View File

@@ -0,0 +1,20 @@
from typing import Dict, Iterable
from docforge.model.module import Module
class Project:
"""Represents a documentation project."""
name: str
modules: Dict[str, Module]
def __init__(self, name: str) -> None: ...
def add_module(self, module: Module) -> None: ...
def get_module(self, path: str) -> Module: ...
def get_all_modules(self) -> Iterable[Module]: ...
def get_module_list(self) -> list[str]: ...