Organising a python project

Ron Adam rrr at ronadam.com
Tue Sep 20 13:52:51 EDT 2005


baoilleach at gmail.com wrote:

> Dear all,
> 
> Can anyone point me to a resource that describes the best way of
> organising a python project? My project (gausssum.sf.net) is based
> around a class, and has a GUI that allows 'easy-access' to the methods
> of the class. What is the best or typical directory structure that
> allows the easy creation of binary packages for linux and windows,
> source distributions, etc.
> 
> Rather than make up my own way, I'd prefer to know if there is a
> typical python way...
> 
> Regards,
> baoilleach


Here's what I've settled on for windows. This also keeps my src dir 
clean and separate form all the additional install files needed. I don't 
use automatic version control or CVS yet,  but this seems to work well 
enough for me.  You could probably just add the neccisary script to 
create linux distribution as well.

projectname             <- main project directory

    projectname1         <- version dir
        dist             <- py2exe output dir
        docs             <- addition documents, license, etc, dir
        icons            <- icons file(s) for exe file dir
        src              <- stand alone python source dir
        notes            <- addition development notes dir
        Output           <- inno setup output dir
        makeexe.py       <- py2exe script
        pack.iss         <- inno setup script

    projectname2         <- next version...
        ...              #  copy the previous version to start.
        ...


Below is my basic py2exe script. You'll need to change it to suite your 
own needs of course.  The rmtree is my own module to remove directories 
and contents.  The newest version of py2exe I think does a better job of 
cleaning up I think.

Cheers,
Ron



# makeexe.py
"""
     Create a stand alone distribution using py2exe.
"""

from distutils.core import setup
import py2exe
import sys
import os
from mytools import rmtree

sys.path += ['.\\src']

try: rmtree.rmtree('dist')
except OSError: pass

try: rmtree.rmtree('build')
except OSError: pass

# Avoid having to use the command line.
# If run without args, build executables, in quiet mode.
if len(sys.argv) == 1:
     #sys.argv.append("-h")  # show options
     sys.argv.append("py2exe")

opts = {
     "py2exe": {
         "optimize": "2",
         }
     }

setup(
     options = opts,
     name = 'Aztec',
     windows = [{
         "script": "src\\aztec.py",
         "icon_resources": [(1, "icons\\aztec.ico")],
         }]
     )

os.rename('dist\\aztec.exe', 'dist\\aztec.scr')

try: rmtree.rmtree('build')
except OSError: pass








More information about the Python-list mailing list