You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Hatch构建后端时pyproject.toml无法引入项目外文件的问题

Hatchling force-include相对路径不生效问题

文件夹结构

-folder1
    -folder2
        -folder3
            -a.py
        -pyproject.toml
    -xyz.txt

pyproject.toml配置

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "folder2"
version = "0.0.1"
description = "asd"

[tool.hatch.build.targets.wheel.force-include]
"../xyz.txt" = "folder3/xyz.txt"

问题详情

进入folder2目录执行python -m build,按照Hatch官方文档中force-include选项的说明,该选项可从文件系统任意位置选择文件并映射到指定分发路径,因此预期生成的wheel包应包含folder2下的a.py,以及被映射到folder3目录下的xyz.txt,但实际构建后xyz.txt并未被包含在wheel包中。

测试发现,将../xyz.txt替换为绝对路径时,xyz.txt可以正常被打包进wheel。而Hatch文档中给出的示例就使用了"../artifacts" = "pkg"这样的相对路径写法,说明相对路径理应支持,但当前场景下却不生效。

内容的提问来源于stack exchange,提问作者Ereghard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:52:04