使用Poetry 1.6.1为Python库添加SQL文件以支持Pip安装后访问
如何用Poetry 1.6.1在Python库中包含SQL文件
问题场景
我开发了一个包含SQL文件的Python库,希望用户通过Pip安装该库后能够访问这些文件,当前使用Poetry 1.6.1构建该库。
尝试了以下配置但未生效:
[tool.poetry.include] # Include the SQL files in the package include = [ "my_library/queries/*.sql" ]
出现错误:
The Poetry configuration is invalid: - [include] {'include': ['my_library/queries/*.sql']} is not of type 'array'
解决方法
错误源于[tool.poetry.include]区块的语法错误,Poetry要求该区块直接使用数组格式,无需嵌套include键。以下是两种正确的配置方式:
方式一:键值对格式
[tool.poetry.include] "my_library/queries/*.sql" = "*"
方式二:数组列表格式
[tool.poetry.include] - "my_library/queries/*.sql"
验证步骤
配置完成后,运行poetry build命令生成包,然后检查生成的wheel或sdist文件,确认SQL文件已被正确包含在内。若需要更精细的包数据配置,也可添加以下可选内容:
[tool.poetry.package.data] "my_library.queries" = ["*.sql"]
内容的提问来源于stack exchange,提问作者David Masip
相关产品推荐
相关产品推荐

