How to organize Python files in a (relatively) big project

Micah Elliott mde at micah.elliott.name
Wed Oct 19 23:37:47 EDT 2005


On Oct 19, Jarek Zgoda wrote:
> Micah Elliott napisał(a):
> 
> >>How to install this structure eg. on Linux? What layout do you
> >>recommend? It's tempting to use /opt hierarchy for installation
> >>target (as it gives relatively much freedom within application
> >>directory), but many administrators are reluctant to use this
> >>hierarchy and prefer more standarized targets, such as /usr or
> >>/usr/local.
> > 
> > Read about (and use) the Python-provided distutils, and let it do the
> > work for you.  In particular,
> > <http://www.python.org/doc/2.4.2/inst/alt-install-windows.html>
> > discusses installation location.  The file name is a misnomer; it's
> > equally applicable to linux.
> 
> I think that installing *application* (not misc. library) modules in
> site-packages is at least stupid idea...

They're not.

> ...as it makes a special filesystem inside other, much more
> standarized filesystem (Windows, FHS, etc.). Why not to do this
> usual way: libraries to $prefix/lib/$appname-$version, binary to
> $prefix/bin, shared files to $prefix/share/$appname, etc -- and
> appropriately on Windows.

It is done more the FHS way than you might realize.  Assuming
sys.prefix is '/usr', then using distutils my manpages go to
'/usr/share/man', my tools/scripts that I want my users to access go
to '/usr/bin' (and I could even put my config files in '/usr/../etc'
or maybe just '/etc' but I haven't had to do that).  So only your
modules end up in '/usr/lib/python', but that seems appropriate
anyway.  It is the simplest way for '/usr/bin/python' to locate your
modules, since it already knows to look in '/usr/lib/python' for
modules.  If you put your modules in say /usr/lib/fooapp then how
would python know where to look for your modules?  You would have
users messing with something called PYTHONPATH or you would end up
with boilerplate or custom install logic to set sys.path according to
special user needs.  But why go through the trouble?  Just let
distutils do the work for you.

I don't want my users to know anything about my *modules* that end up
in /usr/lib/python or that such a thing as PYTHONPATH even exists.

If you prefer the /opt route (or /tmp or $HOME or whatever), then
distutils can create your filesystem structure beneath that
accordingly.

-- 
_ _     ___
|V|icah |- lliott  http://micah.elliott.name  mde at micah.elliott.name
" "     """



More information about the Python-list mailing list