def copy_schemas()

in mozilla_schema_generator/validate_bigquery.py [0:0]


def copy_schemas(head: str, repository: Path, artifact: Path) -> Path:
    """Copy BigQuery schemas to a directory as an intermediary step for schema
    evolution checks."""
    src = Path(repository)
    repo = Repo(repository)
    dst = Path(artifact) / repo.rev_parse(head).name_rev.replace(" ", "_")
    dst.mkdir(parents=True, exist_ok=True)
    schemas = sorted(src.glob("**/*.bq"))
    if not schemas:
        raise ValueError("no schemas found")
    for path in schemas:
        namespace = path.parts[-3]
        doc = path.parts[-1]
        qualified = f"{namespace}.{doc}"
        click.echo(qualified)
        copyfile(path, dst / qualified)

        # also generate something easy to diff
        cols = compute_compact_columns(json.loads(path.read_text()))
        compact_filename = ".".join(qualified.split(".")[:-1]) + ".txt"
        (dst / compact_filename).write_text("\n".join(cols))
    return dst