[Distutils] pkg_resources get Distribution by module name

Tarek Ziadé ziade.tarek at gmail.com
Fri Jan 15 10:29:44 CET 2010

On Fri, Jan 15, 2010 at 10:14 AM, anatoly techtonik <techtonik at gmail.com> wrote:
>> As long as that "plugins" folder is loaded in your WorkingEnv, you
>> could try to see if the module's __file__ path is under the location
>> of one distribution listed in the working env.
> How can I get the list of distributions for working env?

See Setuptools or Distribute doc, and in particular pkg_resources

> List of distributions? Each imported file belongs to one distribution
> only. If normalized path belongs to two simultaneously installed
> distributions then I doubt I need this "new" system. =)

Not necessarely. While this is not happening often, a module or package can
be installed by two distributions. (or "package distribution", or
"parcels" ;) ).

> Considering PEP 376 I apologize for not being able to read it
> completely, but as with many PEPs there is one major drawback - no use
> cases.

MMmm. I thought these two use cases where obvious:

- uninstall distributions
- query installed distributions (like what setuptools provides)

Of course patches are welcome to make it more understandable.

> In the context of my problem I can not see how PEP 376 help with
> Python packages installed into PYTHONPATH, .eggs that present in
> PYTHONPATH and modules without distribution information. How can it
> help to figure out the root package or distribution the imported
> module belongs to. Are there any other PEPs for this?

The code that will be developed for this PEP, as Setutpools is doing,
will make it work against sys.path, and let you browse all
installed/reachable distributions and their files. Meaning that you
will be able to rebuild the info you need. (and make it work on
arbitrary locations if required)

the RECORD file in PEP 376 replaces SOURCES.txt, so you will be able
to use a similar approach than Trac but through APIs

> BTW, there is "fils" typo in PEP 376.


> --
> anatoly t.

Tarek Ziadé | http://ziade.org

More information about the Distutils-SIG mailing list