[Distutils] pkg_resources get Distribution by module name
ziade.tarek at gmail.com
Mon Jan 4 15:18:24 CET 2010
On Mon, Jan 4, 2010 at 3:03 PM, anatoly techtonik <techtonik at gmail.com> wrote:
> On Sun, Jan 3, 2010 at 10:28 PM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
>>> If there any way to get Distribution information given the module name
>>> like 'trac.admin.web_ui' in setuptools?
>>> There is a problem to extract information about exact distribution
>>> name and version when module is already imported in application (Trac
>> I am not sure exactly what you are trying to do, but :
>> If your trac plugin was done using entry points (as it says at
>> http://trac.edgewall.org/wiki/TracDev/PluginDevelopment), this means
>> that you can
>> use the iter_entry_points API from pkg_resources: You will get a
>> EntryPoint object that contains a dist attribute, pointing to the
>> distribution infos.
> Thanks. Already followed this way. Entrypoints is only one way to
> discover plugins - they will work also if imported directly (there is
> "plugins" folder in every user site setup). When plugin is imported,
> everything we have is a name of its class, its module name and path to
> module file.
> I need to figure out if given module belongs to any setuptools
> Distribution to know if it possible to extract any useful information
> from it to display to user in administration panel.
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.
I can't think of another way. PEP 376 will make this task really
simple in the future, as you will be able to directly ask for the list
of distributions that have installed a given file.
> anatoly t.
Tarek Ziadé | http://ziade.org
More information about the Distutils-SIG