14

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?

froadie
  • 79,995
  • 75
  • 166
  • 235

1 Answers1

30

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

Ian Bicking
  • 9,762
  • 6
  • 33
  • 32
  • 5
    Note that files listed in data_files or package_data are not automatically included in the sdist in any Python version prior to the upcoming 2.7 release (this is a distutils bug that was fixed within the last release cycle). So in actual fact, for currently released Python versions, if you need files to be installed, you must list them BOTH in data_files/package_data AND in MANIFEST.in. – Carl Meyer Jun 10 '10 at 19:19
  • 1
    I notice [the 3.2 docs](http://docs.python.org/py3k/distutils/setupscript.html#distutils-additional-files) say "Changed in 3.1: files matching package_data (or data_files) are automatically put into MANIFEST, if no template is provided." However, this is not true for me, on 3.2 on WinXP: I have to put them in there manually by creating a MANIFEST.in and adding them to it. – Jonathan Hartley May 09 '11 at 07:51
  • 1
    That’s strange. Could you open a bug report? – merwok Dec 21 '11 at 16:29
  • 1
    Oops, I never filed that report - just saw this again now. I'll try to reproduce and will file it if I can. I still don't understand though: If files in the MANIFEST.in won't be installed, what's the point of having them in the sdist? – Jonathan Hartley Feb 12 '12 at 11:42