Organising a python project

B

baoilleach

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
 
B

bruno modulix

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...
 
S

Scott David Daniels

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
(e-mail address removed)
 
R

Ron Adam

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
 
B

beza1e1

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top