setuptools sdist 忽略 data_files
setuptools sdist ignore data_files
根据文档 https://packaging.python.org/en/latest/distributing/#data-files
setuptools 将支持在 setup.py 中配置的 data_files
。但我无法让它发挥作用。这是我的 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'])
],
这是项目的文件树:
.
├── booking_order
│ ├── __init__.py
│ ├── tests
│ │ ├── __init__.py
├── etc
│ ├── 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': doesn't exist or not a regular file"。
我检查了 python setup.py sdist
根本不包含 etc 中的文件。
编辑:
自己回答。
根据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."
如果需要将文件安装到 /etc 等位置,例如 /usr/share,那么 he/she 可能会使用来自 distutils 的 data_files 标志,该功能并未从中完全清除安装工具。 "Not totally cleaned up" 意味着您需要手动将这些文件添加到 MANIFEST.in,这与在 distutils 中不同。
当然,如果能用rpm或者deb包系统管理这些配置文件就更好了。对我来说,这里使用 pip 只是一个临时解决方案。
根据文档 https://packaging.python.org/en/latest/distributing/#data-files
setuptools 将支持在 setup.py 中配置的 data_files
。但我无法让它发挥作用。这是我的 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'])
],
这是项目的文件树:
.
├── booking_order
│ ├── __init__.py
│ ├── tests
│ │ ├── __init__.py
├── etc
│ ├── 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': doesn't exist or not a regular file"。
我检查了 python setup.py sdist
根本不包含 etc 中的文件。
编辑:
自己回答。
根据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."
如果需要将文件安装到 /etc 等位置,例如 /usr/share,那么 he/she 可能会使用来自 distutils 的 data_files 标志,该功能并未从中完全清除安装工具。 "Not totally cleaned up" 意味着您需要手动将这些文件添加到 MANIFEST.in,这与在 distutils 中不同。
当然,如果能用rpm或者deb包系统管理这些配置文件就更好了。对我来说,这里使用 pip 只是一个临时解决方案。