3

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.

leucos
  • 17,661
  • 1
  • 44
  • 34
  • Using `zip_safe=False` prevents the egg file from being zipped and might reveal your files in the filesystem when using the form `python setup.py install` – Traveler Mar 28 '18 at 14:10

1 Answers1

2

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

knitti
  • 6,817
  • 31
  • 42
  • Thanks for your answer @knitti, but I'd really like to have them in data_files instead, and put them in a sensible place on the filesystem. – leucos Jan 24 '14 at 15:10