Python setuptools:如何包括配置文件以分发到 /等等
我setup.py
该如何写:
- 二进制蛋分发(
bdist_egg
)包括示例配置文件和 - 安装后将其放入
{prefix}/etc
目录?
示例项目源目录如下所示:
bin/
myapp
etc/
myapp.cfg
myapp/
__init__.py
[...]
setup.py
setup.py看起来像这样:
from distutils.command.install_data import install_data
packages = ['myapp', ]
scripts = ['bin/myapp',]
cmdclasses = {'install_data': install_data}
data_files = [('etc', ['etc/myapp.cfg'])]
setup_args = {
'name': 'MyApp',
'version': '0.1',
'packages': packages,
'cmdclass': cmdclasses,
'data_files': data_files,
'scripts': scripts,
# 'include_package_data': True,
'test_suite': 'nose.collector'
}
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(**setup_args)
setuptools安装在构建环境和安装环境中。
该'include_package_data'
注释掉与否没有帮助。
-
我正在对此问题进行一些研究,我认为答案在setuptools文档中:http ://peak.telecommunity.com/DevCenter/setuptools#non-
package-data-files接下来,我引用我认为有答案的摘录:
非包装数据文件
The distutils normally install general “data files” to a platform-specific
location (e.g. /usr/share). This feature intended to be used for things like
documentation, example configuration files , and the like. setuptools
does not install these data files in a separate location, however. They are
bundled inside the egg file or directory, alongside the Python modules and
packages. The data files can also be accessed using the Resource Management
API […]注意,顺便说一句,数据文件的这种封装意味着 您实际上不能将数据文件安装到用户计算机上的任意位置
。这是一个功能,而不是错误。您始终可以在自己的发行版中包含一个脚本,该脚本可以自行决定将文档或数据文件提取并复制到用户指定的位置。如果将相关数据文件放在单个目录中,则可以将resource_filename()与目录名一起使用,以获取文件系统目录,然后可以使用shutil模块将其复制。[…]