[Distutils] Finding modules in an egg / distribution

2013-07-02 Thread Iwan Vosloo

Hi there,

We have been struggling to find a nice way to list all the modules (or 
packages) that are part of a particular Distribution (or egg). Nice 
should also mean that it works when the egg is installed. We have a need 
to do some introspection on the code shipped as an egg.


Any ideas?

Regards
- Iwan
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Finding modules in an egg / distribution

2013-07-02 Thread PJ Eby
On Tue, Jul 2, 2013 at 6:59 AM, Iwan Vosloo i...@reahl.org wrote:
 Hi there,

 We have been struggling to find a nice way to list all the modules (or
 packages) that are part of a particular Distribution (or egg). Nice should
 also mean that it works when the egg is installed. We have a need to do some
 introspection on the code shipped as an egg.

 Any ideas?

If you are targeting at least Python 2.5, see:

http://docs.python.org/2/library/pkgutil.html#pkgutil.walk_packages
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Finding modules in an egg / distribution

2013-07-02 Thread Iwan Vosloo

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...


Regards
- Iwan
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Finding modules in an egg / distribution

2013-07-02 Thread Éric Araujo
Hello Iwan,

This project can answer your questions: https://pypi.python.org/pypi/pkginfo

FTR we planned to include something like it when the distutils2 project
was active; distlib or the variant of distlib that will end up in the
3.4 standard library could include similar features.

Regards
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig


Re: [Distutils] Finding modules in an egg / distribution

2013-07-02 Thread PJ Eby
On Tue, Jul 2, 2013 at 1:30 PM, Iwan Vosloo i...@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.
___
Distutils-SIG maillist  -  Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig