[Distutils] Determining if a module is in an egg or not

Phillip J. Eby pje at telecommunity.com
Fri Dec 9 22:44:33 CET 2005

At 12:39 PM 12/9/2005 -0800, Bob Ippolito wrote:
>I started refactoring py2app, modulegraph, etc. for setuptools and
>eggs.  After doing dependency resolution via modulegraph, py2app
>needs to know which of those dependencies are in eggs and where those
>eggs are so that it can just throw the egg (and its dependencies)
>into the application bundle instead of doing the normal py2app thing.
>Is there an API to map __file__ paths to eggs?  It seems possible for
>zip and directory eggs by walking up os.path.dirname(__file__) and
>using find_distributions, but that doesn't seem to work for "setup.py
>develop" eggs.

You would probably have an easier time if you go the other way, by walking 
a WorkingSet and querying the eggs to see if they contain the modules 
you're looking for, rather than the other way around.  You could use either 
the default working_set (based on current sys.path), or you could create a 
new WorkingSet instance based on a hypothetical sys.path, whatever makes 
sense for your tool.

System packages (which put multiple eggs in the same directory) are a 
tougher problem, though, unless they grow an additional manifest file to 
list all their modules, not just top-level ones.  (Though that really only 
becomes an issue with namespace packages, and of course system packages of 
eggs are still just a possibility rather than a reality.)

More information about the Distutils-SIG mailing list