diff --git a/docs_generator/runner.py b/docs_generator/runner.py index 91ec555e..32a15191 100644 --- a/docs_generator/runner.py +++ b/docs_generator/runner.py @@ -8,10 +8,22 @@ from docs_generator.markdown_writer import generate_markdown import logging import ast +import yaml logger = logging.getLogger(__name__) +def get_brick_id_from_yaml(yaml_path): + try: + with open(yaml_path + "/brick_config.yaml", "r", encoding="utf-8") as f: + config = yaml.safe_load(f) + id = config.get("id", None) + return id.split(":")[1] if id and ":" in id else None + except Exception as e: + logger.warning("unable to get brick id from yaml: %s", e) + return None + + def process_app_bricks(src_root: str, output_dir: str): """Generate markdown API reference and example documentation for each brick in the app_bricks directory. @@ -107,6 +119,9 @@ def process_app_bricks(src_root: str, output_dir: str): else: all_docstrings = list(docstrings_by_name.values()) # Create output folder for this brick + brick_id = get_brick_id_from_yaml(folder_path) + if brick_id: + folder = brick_id brick_output_dir = os.path.join(output_dir, "arduino", "app_bricks", folder) os.makedirs(brick_output_dir, exist_ok=True) if all_docstrings: diff --git a/pyproject.toml b/pyproject.toml index 477f8080..b2f6f565 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=77,<81", "wheel", "setuptools_scm>=8", "docstring_parser>=0.16", "msgpack>=1.0.0", "watchdog", "requests", "Pillow", "numpy"] +requires = ["setuptools>=77,<81", "wheel", "setuptools_scm>=8", "docstring_parser>=0.16", "msgpack>=1.0.0", "watchdog", "requests", "Pillow", "numpy", "pyyaml"] build-backend = "builder" backend-path = ["src/arduino/app_tools"]