示例#1
0
    def bootstrap(self, ctx: Context):
        """Plugin that handles the project configuration."""
        plugins = (self.autoload or []) + self.config.require

        for plugin in plugins:
            ctx.require(plugin)

        pack_configs = [self.config.resource_pack, self.config.data_pack]
        pack_suffixes = ["_resource_pack", "_data_pack"]

        for config, pack in zip(pack_configs, ctx.packs):
            for path in config.load:
                pack.load(path)

        ctx.require(
            render(
                resource_pack=self.config.resource_pack.render,
                data_pack=self.config.data_pack.render,
            ))

        yield

        description_parts = [
            ctx.project_description
            if isinstance(ctx.project_description, str) else "",
            ctx.project_author and f"Author: {ctx.project_author}",
            ctx.project_version and f"Version: {ctx.project_version}",
        ]

        description = "\n".join(filter(None, description_parts))
        if not isinstance(ctx.project_description, str):
            description = list(
                intersperse(
                    filter(None, [ctx.project_description, description]),
                    "\n"))

        for config, suffix, pack in zip(pack_configs, pack_suffixes,
                                        ctx.packs):
            default_name = ctx.project_name
            if ctx.project_version:
                default_name += "_" + ctx.project_version
            default_name += suffix

            config = config.with_defaults(
                PackConfig(
                    name=default_name,
                    description=pack.description or description,
                    pack_format=pack.pack_format,
                    zipped=pack.zipped,
                ))

            pack.name = config.name
            pack.description = config.description
            pack.pack_format = config.pack_format
            pack.zipped = bool(config.zipped)

            if pack and ctx.output_directory:
                pack.save(ctx.output_directory, overwrite=True)
示例#2
0
def render_functions(ctx: Context):
    ctx.require(render(data_pack={"functions": ["*"]}))
示例#3
0
def beet_default(ctx: Context):
    ctx.data["demo:foo"] = Function(["say {{ message }}"])

    ctx.require(render(data_pack={"functions": ["*"]}))
示例#4
0
    def bootstrap(self, ctx: Context):
        """Plugin that handles the project configuration."""
        autosave = ctx.inject(Autosave)
        autosave.add_output(output(directory=ctx.output_directory))
        autosave.add_link(ctx.inject(LinkManager).autosave_handler)

        plugins = (self.autoload or []) + self.config.require

        for plugin in plugins:
            ctx.require(plugin)

        pack_configs = [self.config.resource_pack, self.config.data_pack]
        pack_suffixes = ["_resource_pack", "_data_pack"]

        ctx.require(
            load(
                resource_pack=self.config.resource_pack.load,
                data_pack=self.config.data_pack.load,
            ))

        ctx.require(
            render(
                resource_pack=self.config.resource_pack.render,
                data_pack=self.config.data_pack.render,
            ))

        with log_time("Run pipeline."):
            yield

        description_parts = [
            ctx.project_description
            if isinstance(ctx.project_description, str) else "",
            ctx.project_author and f"Author: {ctx.project_author}",
            ctx.project_version and f"Version: {ctx.project_version}",
        ]

        description = "\n".join(filter(None, description_parts))
        if not isinstance(ctx.project_description, str):
            description = list(
                intersperse(
                    filter(None, [ctx.project_description, description]),
                    "\n"))

        for config, suffix, pack in zip(pack_configs, pack_suffixes,
                                        ctx.packs):
            default_name = ctx.project_id
            if ctx.project_version:
                default_name += "_" + ctx.project_version
            default_name += suffix

            config = config.with_defaults(
                PackConfig(
                    name=default_name,
                    description=pack.description or description,
                    pack_format=pack.pack_format,
                    zipped=pack.zipped,
                    compression=pack.compression,
                    compression_level=pack.compression_level,
                ))

            pack.name = ctx.template.render_string(config.name)
            pack.description = ctx.template.render_json(config.description)
            pack.pack_format = config.pack_format
            pack.zipped = bool(config.zipped)
            pack.compression = config.compression
            pack.compression_level = config.compression_level