Getting the distribution that a module belongs to

Issue #102 new
Former user created an issue

Is there any way to do this (with distlib)? The best way that I can think of is to iterate through all of the files in every distribution to create module map. Other ways include exposing your code to distribution internals which is less robust...I'd rather not do this.


Comments (3)

  1. Vinay Sajip

    Not in a bullet-proof way ... I just pushed a change (6769e16) which adds a modules attribute to InstalledDistribution. If it's installed using setuptools, you can get a list of top-level modules from the top_level.txt file that setuptools creates - and EggInfoDistribution uses it to populate modules.

    So if all your packages are setuptools-installed, you could in theory walk through all the distributions, look at their modules attribute and create a map (for example).

    Update: As of 8ebc4f8 - if top_level.txt is found in the .dist-info directory, then those InstalledDistribution instances will have their modules attribute updated as well.

  2. Log in to comment