views:

99

answers:

3

I'm writing a setup.py file for a Python project so that I can distribute it. The aim is to eventually create a .egg file, but I'm trying to get it to work first with distutils and a regular .zip.

This is an eclipse pydev project and my file structure is something like this:

ProjectName
   src
      somePackage
         module1.py
         module2.py
         ...
   config
      propsFile1.ini
      propsFile2.ini
      propsFile3.ini
   setup.py

Here's my setup.py code so far:

from distutils.core import setup

setup(name='ProjectName', 
      version='1.0', 
      packages=['somePackage'],
      data_files = [('config', ['..\config\propsFile1.ini', 
                                '..\config\propsFile2.ini', 
                                '..\config\propsFile3.ini'])]
      )

When I run this (with sdist as a command line parameter), a .zip file gets generated with all the python files - but the config files are not included. I thought that this code:

 data_files = [('config', ['..\config\propsFile1.ini', 
                                    '..\config\propsFile2.ini', 
                                    '..\config\propsFile3.ini'])]

indicates that those 3 specified config files should be copied to a "config" directory in the zip distribution. Why is this code not accomplishing anything? What am I doing wrong?

(I have also tried playing around with the paths of the config files... But nothing seems to help. Would Python throw an error or warning if the path was incorrect / file was not found?)

+1  A: 

Create a MANIFEST.in file like this:

include config\*

(EDIT) Look here for more information: http://docs.python.org/distutils/sourcedist.html#specifying-the-files-to-distribute

Umang
Thanks. I get the following error: `warning: no files found matching 'config\ *'`. I've tried changing to ..\config\ * but that doesn't help either... any ideas?
froadie
There's a space between '\' and '*'. Try removing that? Otherwise trying using the forward slash. I've used the forward slash, but because you seemed to have used the backslash, I replaced '/' with '\' here. However, I've found that using / does NOT really cause any problems on Windows.If nothing works, just check whether you are on the right track by hardcoding file names into it, like: include config/propsFile1.ini include config/propsFile2.ini # etc...
Umang
The space was only because of SO formatting - when I put them together it hid the slash for some reason. Changing to forward slash doesn't make a difference... Python seems to automatically convert it back, same error message. Get the same error on individual files... :( any clue what's wrong? is it a path problem?
froadie
Sorry for the delay. Are you sure you've gone to as low a sub-directory as you can? I don't think * matches sub-directories. I've been doing this for a while now, so I'm surprised that this isn't working. (http://bazaar.launchpad.net/~umang/pynagram/trunk/files is an example). I am sure the MANIFEST.in file was the file that got the files in the tarball.
Umang
A: 

I guess you have to escape the backslashes in the filenames; e.g., instead of '..\config\whatever', write '..\\config\\whatever', or use the raw string syntax: r'..\config\whatever'.

Tamás
I tried that (that's one of the things I meant by "I have also tried playing around with the paths of the config files") and it didn't seem to make a difference...
froadie
A: 

I finally got this to work by moving the entire config directory into the src folder. This must mean that my paths are off... but as I couldn't seem to find a way to back up a directory ("..\" didn't make a difference), I'm going to stick with this solution for now.

froadie