Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 951
froadie Avatar asked Jun 03 '10 13:06

froadie


People also ask

How do you include data in a python package?

Place the files that you want to include in the package directory (in our case, the data has to reside in the roman/ directory). Add the field include_package_data=True in setup.py. Add the field package_data={'': [... patterns for files you want to include, relative to package dir...]} in setup.py .

What is Distutils in Python?

The distutils package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.


1 Answers

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

like image 149
Umang Avatar answered Sep 22 '22 10:09

Umang