1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/usr/bin/env python3
import glob
import os
import pathlib
import yaml
RST_DIR = pathlib.Path().joinpath("rst").absolute()
def check_usage(names):
# check if each toc item has a corresponding rst file
for name in names:
if not os.path.exists(f"{RST_DIR}/{name}.rst"):
print(f"toc item={name}: no rst file found!")
# check if rest file has a corresponding toc item
for fname in glob.glob(f"{RST_DIR}/*.rst"):
name = os.path.basename(fname)
if name[0].isupper():
name, _, _ = name.rpartition(".")
if name not in names:
print(f"file={fname}: no toc item found!")
def build_toc():
title = "Python API"
t = f"""
.. _python_api:
{title}
{"*" * len(title)}
"""
names = set()
with open("categories.yaml", "r") as f:
conf = yaml.load(f, Loader=yaml.FullLoader)
for category in conf:
title = category["title"]
t += f"""
{title}
{"=" * len(title)}
"""
for name in category["items"]:
t += f""" - :py:class:`ecflow.{name}`\n"""
names.add(name)
t += """
Api
===
.. toctree::
:maxdepth: 1
:glob:
*
.. contents::
:depth: 2
:local:
:backlinks: top
"""
with open("python_api.rst", "w") as f:
f.write(t)
check_usage(names)
build_toc()
|