[Distutils] Finding modules in an egg / distribution

PJ Eby pje at telecommunity.com
Tue Jul 2 20:27:43 CEST 2013


On Tue, Jul 2, 2013 at 1:30 PM, Iwan Vosloo <iwan at reahl.org> wrote:
> On 02/07/2013 17:08, PJ Eby wrote:
>>
>> If you are targeting at least Python 2.5, see:
>> http://docs.python.org/2/library/pkgutil.html#pkgutil.walk_packages
>
>
> We're targeting Python 2.7.
>
> Trouble is that pkgutil.walk_packages needs a path to search from.
> Distribution.location is always your site-packages directory once a
> Distribution is installed, so walking that just gives ALL installed
> packages. If your Distribution contains some sort of main package that
> contains everything in it, you can use that package's .__path__, but then
> you'd need to discover what that package is.
>
> Distributions could also contain more than one package next to each other,
> and top-level modules. (The __path__ of a top-level module is also simply
> the site-packages directory.)
>
> There is a metadata file top_level.txt which one could use to get the names
> of top-level packages/modules in the Distribution. This can however contain
> a namespace package too - and you don't want all the packages inside the
> namespace package - just the bits inside the chosen Distribution...

Ah, well in that case you'll have to inspect either
.egg-info/SOURCES.txt or the PEP 376 installation manifest.  I don't
know of any reliable way to do what you want for system-installed
packages at the moment.


More information about the Distutils-SIG mailing list