setuptools.package-data在Docker容器内无效
我有一个小项目,叫做 RecordEcos
,它是基于 pyproject.toml 的,主要用来进行多摄像头录制,界面很简洁(使用了 PySimpleGUI)。当摄像头没有连接时,界面会显示一个占位图像。
为了确保这个图像能正确嵌入到生成的包里,我在 pyproject.toml 文件中添加了以下部分。
[tool.setuptools.package-data]
RecordEcos = ["*.png"]
实际上,在我的笔记本上,一切都运行得非常顺利:
$ python -m build | grep Placeholder
copying RecordEcos/gui/img/Placeholder.png -> RecordEcos-0.4.5/RecordEcos/gui/img
copying RecordEcos/gui/img/Placeholder.png -> build/lib/RecordEcos/gui/img
copying build/lib/RecordEcos/gui/img/Placeholder.png -> build/bdist.linux-x86_64/wheel/RecordEcos/gui/img
adding 'RecordEcos/gui/img/Placeholder.png'
其实,即使我没有添加 setuptools 的 package-data
选项,程序在我的笔记本上也能正常工作。这似乎和 setuptools 的文档是相符的。
我把项目推送到了 gitlab,CI(持续集成)也被触发了……但是生成的包里没有包含那个图像。
为了确认,我在一个 docker 镜像中测试了一下:
laptop $ docker run -it python:3.11 /bin/bash
python-container $ pip install build
python-container $ git clone <repository>
python-container $ cd <repository>
python-container & python -m build | grep Placeholder
图像没有被复制!
有没有人知道这是怎么回事?
我尝试了 python:3.11
的 alpine、slim 和 bookworm 版本。
其他信息
笔记本电脑使用 ArchLinux
Python 和包信息
Python: 3.11.8
build: 1.1.1
setuptools: 65.6.0
gitlab-ci.yml
build:
stage: build
image: python:3.11-alpine
script:
- pip install build
- python -m build
artifacts:
untracked: false
when: on_success
expire_in: "30 days"
paths:
- dist/
1 个回答
1
我不太确定,但我觉得你要么需要明确地提到package_data这个参数,要么就得准备一个Manifest文件。
https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html#using-manifest-in