distutils setup

This is a distutils setup that handles hardcoded contants as in Make. I created it for LiliBoggie but it can be adapted for allmost all Python programs.

distutils setup usage

# Just extend user_options.extend if you need more install options:
user_options.extend([('dict-dir=', None, 'dictionaries directory'),
                     ('root-dest=', None, 'destination root')])

[...]

# Initialize it in initialize_options:
def initialize_options(self):
    self.root = None
    self.root_dest = None
    self.install_data = None
    self.dict_dir = ''
    _install.initialize_options(self)

[...]

# Declare it to substitute to the hardcoded value in consts array:
consts = [['DATADIR', self.install_data],
          ['DICTDIR', self.dict_dir],
          ['LIBDIR',  self.install_lib]]

[...]

# Run setup.py with install values you need as argument:

$ ./setup.py install --root=/ --root-dest=/ --install-lib=/usr/lib/ \
   --install-data=/usr/share/ --dict-dir=/usr/share/dict


distutils setup program exemple

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')

import re, os, gtk, gc, time, pango, gobject, \
       locale, sys, ossaudiodev, gettext, string
from gtk import glade
from random import randrange

### CONSTANTS BEGIN ###
DATADIR = '../data'
DICTDIR = '/usr/share/dict'
LIBDIR  = ''
#### CONSTANTS END ####

APPNAME='liliboggie'

if DATADIR.find('share') != -1:
    DATADIRBOGGIE = os.path.join(DATADIR, 'liliboggie')
else: 
    DATADIRBOGGIE = DATADIR

LOCALEDIR = os.path.join(DATADIR, 'locale')

USERBOGGIE = os.path.expanduser(os.path.join('~', '.liliboggie'))

if not os.path.isdir(USERBOGGIE):
    os.makedirs(USERBOGGIE)

sys.path.append(LIBDIR)
from liliboggie.Funcs import *

[...]
été 2005