Autolegal/engine/registry.py

37 lines
869 B
Python
Raw Permalink Normal View History

from __future__ import annotations
from pathlib import Path
def project_root() -> Path:
return Path(__file__).resolve().parent.parent
def documents_root() -> Path:
return project_root() / "documents"
def list_docs() -> list[str]:
"""
Return a list of available documents type names.
Document type is a dir in /documents (e.g. documents/services_lite/)
"""
root = documents_root()
# print(documents_root())
if not root.exists():
return []
return sorted(
p.name
for p in root.iterdir()
if p.is_dir() and (p / "schema.py").exists()
# use schema.py to check and not __init__.py (doc is valid if schema exists
)
def doc_dir(doc_name: str) -> Path:
"""
Return directory path for document type (e.g. documents/services_lite/).
"""
return documents_root() / doc_name