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,9 @@
"""
This module contains the logic for resolving a NavSpec against the physical
filesystem. It expands globs and validates that all referenced documents
actually exist on disk.
"""
from pathlib import Path
from typing import Dict, Iterable, List
@@ -7,17 +13,40 @@ from docforge.nav.spec import NavSpec
class ResolvedNav:
"""
Represents a navigation structure where all patterns and paths have been
resolved against the actual filesystem contents.
Attributes:
home: Resolved relative path to the home page.
groups: Mapping of group titles to lists of absolute or relative Path objects.
"""
def __init__(
self,
home: str | None,
groups: Dict[str, List[Path]],
docs_root: Path | None = None,
) -> None:
"""
Initialize a ResolvedNav instance.
Args:
home: The relative path to the project home page.
groups: A mapping of group names to their resolved filesystem paths.
docs_root: The root documentation directory.
"""
self.home = home
self.groups = groups
self._docs_root = docs_root
def all_files(self) -> Iterable[Path]:
"""
Get an iterable of all resolved files in the navigation structure.
Returns:
An iterable of Path objects.
"""
if self.home:
if self._docs_root is None:
raise RuntimeError("docs_root is required to resolve home path")
@@ -31,6 +60,20 @@ def resolve_nav(
spec: NavSpec,
docs_root: Path,
) -> ResolvedNav:
"""
Create a ResolvedNav by processing a NavSpec against the filesystem.
This expands globs and validates the existence of referenced files.
Args:
spec: The navigation specification to resolve.
docs_root: The root directory for documentation files.
Returns:
A ResolvedNav instance.
Raises:
FileNotFoundError: If a pattern doesn't match any files or the docs_root doesn't exist.
"""
if not docs_root.exists():
raise FileNotFoundError(docs_root)