From reading this documentation, I've built a mental model of what the command sh setuptools-0.6c11-py2.7.egg
actually does, but it's very incomplete and I'm still mystified by a few aspects.
My mental model goes something like this:
- When this command is issued, the egg (which I'd considered as a sort of zip file that handles dependencies cleverly) somehow finds the right version of python on my system, and using that python, "installs itself" to an appropriate location.
- In practice this means that a 'Unix Executable File' called easy_install is created in a directory that's hopefully on my path. This is why I can just type
easy_install somepackage
in the terminal afterwards.
My questions are therefore:
- How is an 'egg' able to "install itself" in this way? Why does this work for this egg in particular, when other eggs require easy_install to work?
- The 'Unix Executable File' thus created is 4kb. What actually is it? Is it full of calls to other things? Where are they?
This isn't a 'how to get it working' question - I'm not having any problems along that axis, but I'd like to fully grok what's going on here.
Egg files are simply zip-compressed directories containing Python packages, modules and a little metadata, with a
.egg
extension.The zip format is flexible; it will ignore anything at the start of the file that isn't part of the zipfile. The zipfile is detected by finding a series of characters (
PK
and two more bytes indicating the type) and reading from there.This means you can put something in front of the zip. The
setuptools
eggs are special in that they use this trick to insert some shell script before the zip data:Past those first 8 lines, it's a genuine zip:
The script contained in those first 8 lines is what is being executed when you run
sh setuptools-0.6c11-py2.7.egg
.As you can see, the script is specific to the egg version; this in the version for python 2.7, and it simply uses the python interpreter to add this egg to the python search path. It then imports a function from the contained python module and runs it.
Here are the contents of the egg itself, which is as I mentioned just a zip archive: