At 06:29 PM 8/19/2010 +0100, Chris Withers wrote:
Hi All,

Given a distribution name (ie: one of those things setuptools uses, 'name' parameter to setup.py's setup call, etc) of a dsitrbution that has been installed with easy_install, buildout, pip, etc, how can I find out what python packages (ie: dotted names that I can import) are provided by that package?

I'm trying to write a scanner than looks for SQLAlchemy table objects and it would be great to be able to pass a distribution name rather than a set of dotted package names...

get_distribution('projectname').get_metadata('top_level.txt').splitlines() will return you a list of top-level package or module names provided by the package.

Subpackages you'll have to find yourself; the pkgutil module in 2.5+ has a walk_packages() that might be helpful.

(Note that if there are packages installed in "flat" form (e.g. pip-installed or system-installed), you may see overlapping packages in the same directory, so simply walking packages in a distribution object's base directory may include packages and modules from another project.)

_______________________________________________
Distutils-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to