from pathlib import Path
from pdm_polylith_workspace.polylith import toml
from pdm_polylith_workspace.polylith.pdm import core

def build_initialize(config_data: dict, build_dir: Path) -> None:
    bricks = toml.get_project_packages_from_polylith_section(config_data)
    top_ns = toml.get_custom_top_namespace_from_polylith_section(config_data)
    work_dir = core.get_work_dir(config_data)
    if not bricks:
        print('No bricks found.')
        return
    if not top_ns:
        core.copy_bricks_as_is(bricks, build_dir)
    else:
        core.copy_and_rewrite_bricks(bricks, top_ns, work_dir, build_dir)
        core.cleanup(work_dir)