Why can't I include these data files in a Python distribution using distutils?
Asked Answered
F

4

5

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

Football answered 3/6, 2010 at 13:39 Comment(0)
F
1

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.

Football answered 3/6, 2010 at 18:10 Comment(0)
C
6

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

Christopher answered 3/6, 2010 at 14:56 Comment(5)
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?Football
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...Christopher
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?Football
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. (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.Christopher
Shouldn’t the line read recursive-include instead of include?Electrolier
E
3

Try with this in the MANIFEST.in:

recursive-include config *

It worked for me

Emanuelemanuela answered 29/6, 2021 at 6:38 Comment(1)
This should be the accepted answer...Tantamount
F
1

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.

Football answered 3/6, 2010 at 18:10 Comment(0)
S
0

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

Seedcase answered 3/6, 2010 at 15:58 Comment(2)
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...Football
Distutils always uses forward slashes.Electrolier

© 2022 - 2024 — McMap. All rights reserved.