跳转到主要内容

Hatch构建钩子插件,用于注入自动运行的代码

项目描述

hatch-autorun

CI/CD CI - Test CD - Build
PyPI - Version PyPI - Python Version
元数据 code style - black types - Mypy imports - isort License - MIT GitHub Sponsors

这为构建钩子插件提供了Hatch,该插件会在第一次导入之前将代码注入到安装中。

目录

配置

构建钩子插件的名称为autorun

  • pyproject.toml

    [tool.hatch.build.targets.wheel.hooks.autorun]
    dependencies = ["hatch-autorun"]
    
  • hatch.toml

    [build.targets.wheel.hooks.autorun]
    dependencies = ["hatch-autorun"]
    

文件

您可以使用file选项选择包含代码的文件的相对路径

[tool.hatch.build.targets.wheel.hooks.autorun]
file = "resources/code.emded"

代码

您可以使用code选项定义代码本身

[tool.hatch.build.targets.wheel.hooks.autorun]
code = """
print('Starting coverage collection')
coverage.process_startup()
"""

模板

当前实现使用.pth文件来执行代码。因此,任何必需的导入都必须在那里定义,而不是在代码本身中。

您可以使用template选项设置.pth文件模板,该模板将使用表示code选项的code变量或由file选项定义的文件内容进行格式化。以下显示默认模板

[tool.hatch.build.targets.wheel.hooks.autorun]
template = "import os, sys;exec({code!r})"

条件执行

有时您可能只想在特定情况下安装时触发自动运行行为,例如在测试中。在这种情况下,将enable-by-default 选项设置为false

[tool.hatch.build.targets.wheel.hooks.autorun]
enable-by-default = false

然后当满足所需的构建条件时,将HATCH_BUILD_HOOK_ENABLE_AUTORUN 环境变量设置为true1

许可

hatch-autorun遵循MIT许可协议。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

hatch_autorun-1.1.0.tar.gz (7.8 kB 查看哈希)

上传时间

构建分布

hatch_autorun-1.1.0-py3-none-any.whl (5.3 kB 查看哈希)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面