Python 2.6 and beyond has the ability to directly execute a .zip file if the zip file contains a __main__.py
file at the top of the zip archive. I'm wanting to leverage this feature to provide preview releases of a tool I'm developing that won't require users to install anything beyond copying the .zip file to their disk. Is there a standard way to create such a zip file? I'm looking for a solution that works with python 2.6 and python 2.7.
Ideally I would like to use distutils, since I already have it working when I want to do a normal install. Is there a canonical way to use (or extend) distutils to create such a .zip file?
distutils provides an sdist
command which creates a source distribution that is almost right, but creates a structure that is a little too deep.
For example, my source tree looks like this:
my_package/
- setup.py
- src/
- __main__.py
- module1/
- module2/
- module3/
When I do python setup.py sdist
I end up with a .zip file with the following structure:
my_package-0.1.zip
- my_package-0.1/
- README.txt
- PKG_INFO
- src/
- __main__.py
- module1/
- module2/
- module3/
This isn't executable because __main__.py
is not at the top of the distribution. Effectively what I want is a src distribution that doesn't include src
, but only the files under src
. That, or exactly what sdist
gives me, but with an extra __main__.py
at the top of the archive.