[Distutils] How do you get data_files and bdist_wininst to cooperate?

Jason Sibre jsibre at chironsys.com
Fri Jul 25 13:06:40 EDT 2003

Hi folks,

I'm very new to this list and to distutils (this is my first stab at using
it), so don't be afraid to point out the obvious...

I'm trying to make a setup.py that will work on Linux and Win32, and be able
to produce sdists and bdists for both platforms (I understand that I should
use the targeted platform to build the bdist).

The package I'm trying to distribute is actually a Quixote application,
which (for those unfamiliar with Quixote) means it's a web application.  I'd
like to install it as a package in site-packages anyway, because that makes
it easier to run multiple instances of the application (with different
configuration data) on a machine without having multiple copies of it.  As a
web application, it has a few images, and a style.css file to distribute,
and it also has a misc directory in the package (which perhaps shouldn't go
there, but that's the way I'm trying to do it for now...) which includes a
sample *.cgi file, *.conf file, and a python script intended to be run as a
script (rather than imported as a module/package).

I'm using the data_files argument to pass in those files, and I determine
the directory to install to by extrapolating from the value of
distutils.sysconfig.get_python_lib(), but that doesn't work right when I do
a bdist_wininst (I haven't tried to do an RPM, yet, so I don't know if that
works)...  The files end up in "c:\python23\python23\projectTasks...."
instead of "c:\python23\Lib\site-packages\projectTasks....".

I've figured out a hack to do to the data_files (in code below) to make it
work, but then the sdist doesn't work right, on Linux or Win32.

Is there a way to achieve what I'm attempting, or do I just need to figure
out at run time what the user is trying to do (build a bdist, or run an
sdist), and decide then whether to apply my hack or not?


Jason Sibre

Here's my setup.py file:

import os, os.path
from distutils.core import setup
from distutils.sysconfig import get_python_lib
from quixote.qx_distutils import qx_build_py

def getFiles(path):
    fullFiles = []
    files = os.listdir(path)

    for f in files:
        if f == "CVS": continue
    return fullFiles

webdir = os.path.join(get_python_lib(),'projectTasks','web')
miscFiles = getFiles('web/misc')
staticFiles = getFiles('web/staticFiles')

#I think this is the 'right' way to do it,
#and creates sdists that play nicely
data_files = [
    (os.path.join(webdir, 'misc'),        miscFiles),
    (os.path.join(webdir, 'staticFiles'), staticFiles),

#This works (as a hack) to get a win binary to install nicely
#But of course makes a mess if you install from an sdist
#data_files = [
#    ('../PURELIB/projectTasks/web/misc',        miscFiles),
#    ('../PURELIB/projectTasks/web/staticFiles', staticFiles),
#    ]

    name = 'projectTasks',
    version = "0.1.0",
    description = "Project Task manager app for Quixote framework.",
    author = "Jason Sibre",
    author_email = "jsibre at chironsys.com",
    package_dir = {'projectTasks':'.'},
    packages = ['projectTasks','projectTasks.web'],
    data_files = data_files,
    cmdclass = {'build_py': qx_build_py},

More information about the Distutils-SIG mailing list