跳转至

自定义构建钩子(Custom build hook)


这是一个在指定 Python 文件中定义的自定义类,该类继承自 BuildHookInterface

配置(Configuration)

构建钩子插件名称为 custom

[tool.hatch.build.hooks.custom]
[tool.hatch.build.targets.<TARGET_NAME>.hooks.custom]
[build.hooks.custom]
[build.targets.<TARGET_NAME>.hooks.custom]

选项(Options)

选项 默认值 描述
path hatch_build.py Python 文件的路径

示例(Example)

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomBuildHook(BuildHookInterface):
    ...

如果找到多个子类,必须定义一个名为 get_build_hook 的函数,该函数返回所需的构建钩子。

Note

任何已定义的 PLUGIN_NAME 都会被忽略,并始终默认为 custom