从 setup.py 安装时未复制 yaml 文件

yaml file not getting copied when installing from setup.py

对于我的 distutils 包,yaml 文件和 python 文件没有被复制

setup.py

from distutils.core import setup

files = ["*.yaml", "package/*"]

setup(name = "mypackage",
    version = "0.1",
    description = "description",
    author = "Ciasto",
    author_email = "me@email.com",
    packages = ['package'],
    package_data = {'package' : files },
    scripts = ["scripts/runner"],
) 

这是项目目录结构:

$ tree package/
|____
| |______init__.py
| |____command.py
| |____constants.py
| |____controller.py
| |____utils.py
| |____model.py
| |____products.yaml

package_data 用于将包的数据添加到鸡蛋(放弃)和轮子(不适用于 distutils)。您可能正在生成源代码分发 (sdist)。

对于 sdist,您需要文件 MANIFEST.in(在 setup.py 之外创建它)。在你的情况下,其中一行就足够了:

include package/*.yaml

请参阅 https://docs.python.org/3/distutils/sourcedist.html#specifying-the-files-to-distribute

中的文档

https://packaging.python.org/guides/using-manifest-in/#using-manifest-in

如果您不打算创建轮子,您可以安全地从 setup.py.

中删除 filespackage_data