in terranova/commands/binds.py [0:0]
def docs(docs_dir: Path) -> None:
"""Generate documentation for all resources."""
# Find all resources manifests
jobs = []
for path, _, files in os.walk(SharedContext.resources_dir().as_posix()):
for file in files:
if os.path.basename(file) == Constants.MANIFEST_FILE_NAME:
jobs.append(
(
Path(path),
docs_dir.joinpath(
os.path.relpath(
path, SharedContext.resources_dir().as_posix()
)
),
)
)
# Clean docs dir
if docs_dir.exists():
shutil.rmtree(docs_dir.as_posix())
# Generate docs
env = Environment(loader=PackageLoader("terranova", "templates"))
tmpl = env.get_template("resources.md")
for resources_path, target_path in jobs:
target_path.parent.mkdir(parents=True, exist_ok=True)
# Read resources manifest and find all resources
manifest = read_manifest(resources_path)
resources = discover_resources(resources_path)
# Write documentation file
rendering = tmpl.render({"manifest": manifest, "resources": resources})
formatted = mdformat.text(rendering)
target_path.with_suffix(".md").write_text(
data=formatted, encoding=Constants.ENCODING_UTF_8
)