By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

Organising a python project

P: n/a
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

Sep 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ba********@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.
Err... Unless it's a *very* simple project, having the project based on
a *single* class smells of GodClassAntipattern (I can't say for sure
without seeing the source of course, so this is most a a priori than a
judgement !-).
What is the best or typical directory structure that
allows the easy creation of binary packages
'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...


Usually, a program project is made of one or more library modules,
eventually organized in packages, and a 'main' script that's the entry
point for the program [1]. Most Python projects being OSS, you can
examine existing projects.
[1] Note that this not Python specific. You'll find the same overall
organisation in C, C++, Java, etc...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Sep 20 '05 #2

P: n/a
bruno modulix wrote:
ba********@gmail.com wrote:
What is the best or typical directory structure that
allows the easy creation of binary packages


somedir:
test/
test_product.py # Really do include tests
product.py
setup.py

Look at distutils documentation. Also read up on "Python Eggs."

You might consider doing it as a package under a you-specific name:

somedir:
yourname:
test/
test_product.py # See unittest module
__init__.py # can be empty (and often is), also might have a
# doc string, author, copyright, and license info
# and a line like: __version__ = "0.2"
product.py
setup.py

--Scott David Daniels
Sc***********@Acm.Org
Sep 20 '05 #3

P: n/a
ba********@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

Sep 20 '05 #4

P: n/a
Thanks for the info, guys. Noel

Sep 21 '05 #5

P: n/a
Thanks for the info, guys. Noel

Sep 21 '05 #6

P: n/a
I don't know about a typical python way, but i'd like to know as well
;)

Personally i have a project for my project foo, which has
foo/__init__.py # with all the other modules
doc/ # documentation is always a good idea
script/ # everything executable, which later goes into 'bin'
directories by installing
setup.py
README, INSTALL, ... and other standard stuff

Of course often there is other stuff floating around in the base
directory, like some quick test scripts or sketches. And then my
version control system has an additional directory.

My tests are mostly within the modules.

def test():
return True
if __name__ == "__main__":
test()

My __init__.py tests every module, if executed directly. So far my
system works. It probably would be good to seperate tests, if they get
bigger.

Sep 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.