Exemplo n.º 1
0
def lectern(
    ctx: click.Context,
    path: Tuple[str],
    data_pack: Optional[str],
    resource_pack: Optional[str],
    external_files: Optional[str],
    prefetch_urls: Optional[str],
    flat: bool,
    overwrite: bool,
):
    """Literate Minecraft data packs and resource packs."""
    config: Any

    if prefetch_urls:
        if len(path) > 1:
            echo(ctx.get_usage())
            echo("\nError: expected a single output path")
            ctx.exit(1)

        prefetcher = MarkdownPrefetcher()
        prefetcher.process_file(
            prefetch_urls,
            path[0] if path else prefetch_urls,
            external_files=external_files,
        )
        return

    if data_pack or resource_pack:
        config = {
            "pipeline": ["lectern"],
            "meta": {
                "lectern": {"load": list(path)},
            },
        }
    else:
        try:
            *packs, dest = path
        except ValueError:
            echo(ctx.get_help())
            ctx.exit(1)
        config = {
            "data_pack": {"load": packs},
            "resource_pack": {"load": packs},
            "pipeline": ["lectern"],
            "meta": {
                "lectern": {
                    "snapshot": dest,
                    "snapshot_flat": flat,
                    "external_files": external_files,
                },
            },
        }

    with run_beet(config) as beet_ctx:
        try:
            if data_pack:
                beet_ctx.data.save(path=data_pack, overwrite=overwrite)
            if resource_pack:
                beet_ctx.assets.save(path=resource_pack, overwrite=overwrite)
        except FileExistsError as exc:
            raise ErrorMessage(f"{exc} (run again with --overwrite)") from exc
Exemplo n.º 2
0
def test_build(snapshot: Any, directory: str):
    with run_beet(directory=f"tests/examples/{directory}") as ctx:
        assert snapshot("data_pack") == ctx.data
        assert snapshot("resource_pack") == ctx.assets
Exemplo n.º 3
0
def test_beet_project(snapshot: Any):
    with run_beet(directory="examples/with_beet") as ctx:
        ctx.data.name = None
        ctx.assets.name = None
        assert snapshot("pack.md") == ctx.inject(Document)