Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 techniques for including files in a Python distribution: which is better?

I'm working on packaging a small Python project as a zip or egg file so that it can be distributed. I've come across 2 ways to include the project's config files, both of which seem to produce identical results.

Method 1:

Include this code in setup.py:

from distutils.core import setup

setup(name='ProjectName', 
      version='1.0', 
      packages=['somePackage'],
      data_files = [('config', ['config\propFiles1.ini', 
                                'config\propFiles2.ini', 
                                'config\propFiles3.ini'])]
      )

Method 2:

Include this code in setup.py:

from distutils.core import setup

setup(name='ProjectName', 
      version='1.0', 
      packages=['somePackage']
      )

Then, create a MANIFEST.in file with this line in it:

include config\* 

Is there any difference between the methods? Which one is preferred? I tend to lean towards the first because then no MANIFEST.in file is necessary at all. However, in the first method you have to specify each file individually while in the second you can just include the whole folder. Is there anything else I should be taking into consideration? What's the standard practice?

like image 718
froadie Avatar asked Jun 03 '10 18:06

froadie


1 Answers

MANIFEST.in controls what files are put into the distribution zip file when you call python setup.py sdist. It does not control what is installed. data_files (or better package_data) controls what files are installed (and I think also makes sure files are included in the zip file). Use MANIFEST.in for files you won't install, like documentation, and package_data for files you use that aren't Python code (like an image or template).

like image 55
Ian Bicking Avatar answered Sep 24 '22 23:09

Ian Bicking