⇤ ← Revision 1 as of 2005-10-27 17:01:57
Size: 1941
Comment:
|
Size: 1968
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
1. unpack zipped eggs, because I believe py2exe chokes on them when | 1. unpack zipped eggs, because I believe py2exe chokes on them when |
Line 7: | Line 7: |
2. keep track of the top level packages in the eggs 3. add all of the files in the eggs to the data_files, so that the |
2. keep track of the top level packages in the eggs 3. add all of the files in the eggs to the data_files, so that the |
Line 10: | Line 10: |
4. build the exe 5. generate a new library.zip that does not include anything in the |
4. build the exe 5. generate a new library.zip that does not include anything in the |
Line 16: | Line 16: |
{{{ | |
Line 36: | Line 37: |
}}} | |
Line 38: | Line 40: |
{{{ |
|
Line 60: | Line 64: |
}}} |
This is an ugly hack that, I assume, will go away some day when py2exe is aware of eggs. The good thing about this hack is that the basic principles work with both py2exe and py2app.
This is cut from a couple spots in my script. The basic flow is:
- unpack zipped eggs, because I believe py2exe chokes on them when
resolving dependencies
- keep track of the top level packages in the eggs
- add all of the files in the eggs to the data_files, so that the
eggs are installed along side the main exe
- build the exe
- generate a new library.zip that does not include anything in the
top level packages found in step 2
here's steps 1 and 2:
import pkg_resources eggs = pkg_resources.require("TurboGears") from setuptools.archive_util import unpack_archive for egg in eggs: if os.path.isdir(egg.location): sys.path.insert(0, egg.location) continue unpack_archive(egg.location, eggdir) eggpacks = set() eggspth = open("build/eggs.pth", "w") for egg in eggs: print egg eggspth.write(os.path.basename(egg.location)) eggspth.write("\n") eggpacks.update(egg.get_metadata_lines("top_level.txt")) eggspth.close() eggpacks.remove("pkg_resources")
and here's step 5:
import zipfile oldzipfile = "dist/exe/library.zip" newzipfile = "dist/exe/small-library.zip" oldzip = zipfile.ZipFile(oldzipfile, "r") newzip = zipfile.ZipFile(newzipfile, "w", zipfile.ZIP_STORED) for entry in oldzip.infolist(): delim = entry.filename.find("/") if delim == -1: delim = entry.filename.find(".") if delim > -1: if entry.filename[0:delim] in eggpacks: print "Skipping %s, it's in the egg" % (entry.filename) continue newzip.writestr(entry, oldzip.read(entry.filename)) newzip.close() oldzip.close() os.remove(oldzipfile) os.rename(newzipfile, oldzipfile)