setuptools sdist 忽略 data_files [英] setuptools sdist ignore data_files

查看:66
本文介绍了setuptools sdist 忽略 data_files的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档 https://packaging.python.org/en/最新/分发/#data-files

setuptools 将遵守 setup.py 中配置的 data_files.但我不能让它工作.这是我的 setup.py:

设置(name='booking_order',版本=版本,包=find_packages(),包数据={'booking_order': ['fake_backends/static/*','脚本/*','*.样本'],},数据文件=[('/etc/booking', ['etc/booking.conf'])],

这是项目的文件树:

<预><代码>.├── 预订订单│ ├── __init__.py│ ├──测试│ │ ├── __init__.py├── 等│ ├──booking.conf├── README.md├── setup.py

行为是,如果我运行 python setup.py install,文件 etc/booking.conf 将被安装到 /etc/booking>.但是如果我先python setup.py sdist upload,然后pip install booking_order,就会出现错误error: can't copy 'etc/booking.conf':不存在或不是常规文件".我检查了 python setup.py sdist 根本不包含 etc 中的文件.

看来这就是答案:https://github.com/pypa/setuptools/issues/521

解决方案

自己回答.

根据 pypanon-package-data-files."setuptools 不支持将数据文件安装到任意用户机器上的位置;这是一项功能,而不是错误."

如果需要将文件安装到/etc、/usr/share 等位置,例如,那么他/她可以使用来自 distutils 的 data_files 标志,该功能并未从 setuptools 中完全清除.未完全清理"意味着您需要手动将这些文件添加到 MANIFEST.in,这与在 distutils 中不同.

当然,如果能用rpm或deb包系统管理这些配置文件就更好了.对我来说,这里使用 pip 只是一个临时解决方案.

According to docs https://packaging.python.org/en/latest/distributing/#data-files

setuptools will honor data_files configed in setup.py. But i can't make it work. This is my setup.py:

setup(
    name='booking_order',
    version=version,
    packages=find_packages(),
    package_data={
        'booking_order': ['fake_backends/static/*',
                          'scripts/*',
                          '*.sample'],
    },
    data_files=[
        ('/etc/booking', ['etc/booking.conf'])
    ],

This is the project's file tree:

.
├── booking_order
│   ├── __init__.py
│   ├── tests
│   │   ├── __init__.py
├── etc
│   ├── booking.conf
├── README.md
├── setup.py

The behavior is, if i run python setup.py install, file etc/booking.conf will got installed to /etc/booking. But if i first python setup.py sdist upload, then pip install booking_order, there will be an error "error: can't copy 'etc/booking.conf': doesn't exist or not a regular file". I checked python setup.py sdist doesn't include files in etc at all.

EDIT:

it seems this is the answer: https://github.com/pypa/setuptools/issues/521

解决方案

Answer it myself.

According to pypa, and non-package-data-files。"Setuptools doesn't support installing data files to some arbitrary location on a user’s machine; this is a feature, not a bug."

If one need to install files to locations like /etc, /usr/share, eg, then he/she may use data_files flag from distutils, which feature is not totally cleaned up from setuptools. "Not totally cleaned up" means you need to add those files to MANIFEST.in manually, which is different as in distutils.

Of course, it will be better if one can manage these configuration files with rpm or deb package system. For me it's just a temporary solution to use pip here.

这篇关于setuptools sdist 忽略 data_files的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆