I won't get into licensing discussion here, but it's typical to include LICENSE file at the root of your package source code, along with other customary things like README, etc.
I usually organize packages the same way they will be installed on the target system. The standard package layout convention is explained here.
For example if my package is 'torrent' and it has a couple sub-packages such as 'tests' and 'util', here's the source tree would look like:
workspace/torrent/setup.py
workspace/torrent/torrent/__init__.py
workspace/torrent/torrent/foo.py
workspace/torrent/torrent/bar.py
workspace/torrent/torrent/...
workspace/torrent/torrent/tests/__init__.py
workspace/torrent/torrent/tests/test.py
workspace/torrent/torrent/tests/...
workspace/torrent/torrent/util/__init__.py
workspace/torrent/torrent/util/helper1.py
workspace/torrent/torrent/util/...
This 'torrent/torrent' bit seems redundant, but this is the side-effect of this standard convention and of how Python imports work.
Here's the very minimalist setup.py
(more info on how to write the setup script):
#!/usr/bin/env python
from distutils.core import setup
setup(name='torrent',
version='0.1',
description='would be nice',
packages=['torrent', 'torrent.tests', 'torrent.util']
)
To obtain a source distro, I'd then do:
$ cd workspace/torrent
$ ./setup.py sdist
This distro (dist/torrent-0.1.tar.gz
) will be usable on its own, simply by unpacking it and running setup.py install
or by using easy_install
from setuptools
toolkit. And you won't have to make several "eggs" for each supported version of Python.
If you really need an egg, you will need to add a dependency on setuptools
to your setup.py
, which will introduce an additional subcommand bdist_egg
that generates eggs.
But there's another advantage of setuptools
besides its egg-producing-qualities, it removes the need to enumerate packages in your setup.py
with a nice helper function find_packages
:
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='torrent',
version='0.1',
description='would be nice',
packages=find_packages()
)
Then, to obtain an "egg", I will do:
$ cd workspace
$ ./setup.py bdist_egg
... and it will give me the egg file: dist/torrent-0.1-py2.6.egg
Notice the py2.6
suffix, this is because on my machine I have Python 2.6. If you want to please lots of people, you'd need to publish an egg for each major Python release. You don't want hordes of Python 2.5 folks with axes and spears at your doorstep, do you?
But you don't have to build an egg, you can still use sdist
subcommand.
Updated: here's another useful page in Python documentation that introduces Distutils
from user's perspective.