setup.py's sdist, bdist and install behaving differently regarding data_files

☆樱花仙子☆ 提交于 2019-12-12 15:22:09

问题


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.

Project Layout

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.

The files layout is as follow :

data/index.html  
MANIFEST.in
mylib.py
setup.py

The MANIFEST.in file is :

recursive-include data *

The setup.py is :

#!/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']) ]
)

My goal is to install index.html in PREFIX/share/mylib/index.html.

Running setup.py

Now, bdist includes the file at the seemingly right location, while sdist and install just ignore it :

  • bdist

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

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

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
...

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

Same issue as sdist (I suppose this is expected). No trace of data/index.html anywhere ('/usr/local/share', '/usr/share').

I also tried to add a setup.cfg like this :

[install]
install-data=/usr/local/share/mylib/
install_data=/usr/local/share/mylib/

(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.

Epilogue

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.

Thanks for reading.


回答1:


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/*'}

)

this would put the data to site-packages/mylib-0.1.2/data



来源:https://stackoverflow.com/questions/21305338/setup-pys-sdist-bdist-and-install-behaving-differently-regarding-data-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!