enrichment.py

clew/enrichment.py

Optional architecture-topics enrichment from a YAML curriculum file.

enrich_database

None clew.enrichment.enrich_database(Path db_path, Path yaml_path)

Populate architecture_topics table from a YAML curriculum file.

clew/enrichment.py:75

Show on the map →

Called by _build_stages, _enrich

Tested by

2 teststest_enrich_is_idempotent, test_enrich_rejects_non_list_yaml

Calls _create_topics_table, _insert_topics

Source · 31 lines
def enrich_database(db_path: Path, yaml_path: Path) -> None:
    """Populate architecture_topics table from a YAML curriculum file.

    The YAML file should contain a list of topic entries with fields:
    topic, title, summary, key_files, key_concepts, prerequisite_topics,
    difficulty. Existing rows in architecture_topics are deleted before
    insert so re-running the build idempotently overwrites the table.

    @brief Add architecture_topics table from YAML enrichment file.
    @version 2
    """
    try:
        import yaml
    except ImportError:
        logger.error("PyYAML required for enrichment: pip install pyyaml")
        sys.exit(1)

    topics = yaml.safe_load(yaml_path.read_text())
    if not isinstance(topics, list):
        logger.error("Expected a YAML list in %s", yaml_path)
        sys.exit(1)

    conn = sqlite3.connect(str(db_path))
    _create_topics_table(conn)
    _insert_topics(conn, topics)
    conn.close()
    logger.info(
        "Enriched database with %d topics from %s",
        len(topics),
        yaml_path,
    )

1 more lines, not shown

Activity · 14 steps
lines 86–86trylines 87–87import yamllines 88–88except ImportErrorlines 89–89logger.error("PyYAML required for enrichment: pip install pyyaml")lines 90–90sys.exit(1)lines 92–92topics = yaml.safe_load(yaml_path.read_text())lines 93–93◇ if not isinstance(topics, list)lines 94–94logger.error("Expected a YAML list in %s", yaml_path)lines 95–95sys.exit(1)lines 97–97conn = sqlite3.connect(str(db_path))lines 98–98_create_topics_table(conn)lines 99–99_insert_topics(conn, topics)lines 100–100conn.close()lines 101–105logger.info( "Enriched database with %d topics from %s", len(topics), yaml_path, )

Requirements

REQ-DDB-PIPE-001