setup.py的sdist,bdist和install关于data_files的行为有所不同 [英] setup.py's sdist, bdist and install behaving differently regarding data_files
问题描述
我正在尝试分发网络资产以及我要打包的网络应用程序,但我失败了。我不明白为什么我在运行bdist,sdist或install时安装了不同的文件或软件包列表。
I'm trying to distribute web assets along with a web app that I'm trying to package, but I'm failing miserably. I don't understand why I have a different list of files installed or packages when I run bdist, sdist, or install.
该项目在Arch上使用python 3运行。结果与Raspbian上的Py3相同。
为了简化起见,我做了一个非常精简的版本。
The project runs with python 3 on Arch. The results are the same with Py3 on Raspbian. I've done a very trimmed down version to make things simpler, which I describe here.
文件布局如下:
data/index.html
MANIFEST.in
mylib.py
setup.py
MANIFEST.in
文件为:
recursive-include data *
setup.py
是:
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='mylib',
version='0.1.2',
url='http://www.example.org',
author='Foo',
packages=find_packages(),
data_files = [ ('share/mylib', ['data/index.html']) ]
)
我的目标是在 PREFIX / share / mylib / index.html
中安装 index.html
。
My goal is to install index.html
in PREFIX/share/mylib/index.html
.
现在, bdist
包含位于s非常正确的位置,而 sdist
和 install
只是忽略它:
Now, bdist
includes the file at the seemingly right location, while sdist
and install
just ignore it :
- bdist
- bdist
使用bdist,我在以下文件中生成的tar:
Using bdist, I have the following files in the resulting tar :
./usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg-info/SOURCES.txt
./usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg-info/top_level.txt
./usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg-info/dependency_links.txt
./usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg-info/PKG-INFO
./usr/share/mylib/index.html
这正是我想要安装的东西,非常完美。但是,我确实希望 sdist
和 install
可以正常工作,因为我想在PyPI上分发此东西,并且能够
This is exactly what I want to be installed, perfect. However, I really want sdist
and install
to work, since I want to distribute this thing on PyPI and be able to install from source checkouts.
- sdist
- sdist
当我解压缩sdist文件时,一切似乎正常,并且包含数据:
When I untar the sdist file, everything seems ok and data is included :
...
mylib-0.1.2/data/
mylib-0.1.2/data/index.html
...
但是,如果我 sudo python setup.py install --record = log.txt
放在未压缩的目录中,日志中列出的唯一文件是 /usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg
。在任何地方('/ usr / local / share','/ usr / share')都没有 data / index.html
的踪迹
However, if I sudo python setup.py install --record=log.txt
in the directory where it is untarred, the only file listed in the log is /usr/lib/python3.3/site-packages/mylib-0.1.2-py3.3.egg
. No trace of data/index.html
anywhere ('/usr/local/share', '/usr/share')
- 安装
- install
与sdist问题相同(我猜这是是期待)。在任何地方('/ usr / local / share','/ usr / share')都没有 data / index.html
的踪迹。
Same issue as sdist (I suppose this is expected). No trace of data/index.html
anywhere ('/usr/local/share', '/usr/share').
我还试图添加一个setup.cfg,如下所示:
I also tried to add a setup.cfg like this :
[install]
install-data=/usr/local/share/mylib/
install_data=/usr/local/share/mylib/
(由于docs声明要使用后者,因此我同时添加了install-data和install_data,而我看到其他项目则使用了后者)。没运气。
(I've added both install-data and install_data since docs state to use the later, while I saw other projects using the former). No luck.
现在,我是python的新手,这是环境,我可能会丢失有些明显的东西或误解了setuptools是如何工作的。我一直来回阅读文档,在data_files中阅读了很长的stackoverflow的Q& A,但没有取得任何进展。
Now, I quite new to python and it's environment, I'm probably missing something obvious or misunderstanding how setuptools works. I've been reading the doc back an forth, reading stackoverflow's Q&A in data_files at great length, but didn't make any progress.
如果有人可以指点我向正确的方向解决这个问题,这将是非常好的。链接到分配资产的简单项目也很不错。我只是找不到一个给我啊啊!的东西。
If someone could point me to the right direction to solve this, this would be great. A link to a simple project distributing assets would be a good read too. I just couldn't find one that gave me that "Ah ah!" moment.
感谢阅读。
推荐答案
我不喜欢知道这是否有帮助,因为我总是将我的数据文件包含在与之配套的python包中。除了 MANIFFEST.in
中,您还将在 setup.py中有一个
: package_data
键。
I don't know whether this helps, as I always include my data files relative to the python packages they go with. Additionally to the MANIFFEST.in
, you'd have a package_data
key in setup.py
:
setup(name='mylib',
version='0.1.2',
url='http://www.example.org',
author='Foo',
packages=find_packages(),
package_data={'package_name': 'package_dir/data/*'}
)
数据到 site-packages / mylib-0.1.2 / data
这篇关于setup.py的sdist,bdist和install关于data_files的行为有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!