[Checkins] SVN: zope.introspector/trunk/src/zope/introspector/code. Add egg infos for packages.

Uli Fouquet uli at gnufix.de
Thu Aug 7 20:01:45 EDT 2008


Log message for revision 89528:
  Add egg infos for packages.

Changed:
  U   zope.introspector/trunk/src/zope/introspector/code.py
  U   zope.introspector/trunk/src/zope/introspector/code.txt

-=-
Modified: zope.introspector/trunk/src/zope/introspector/code.py
===================================================================
--- zope.introspector/trunk/src/zope/introspector/code.py	2008-08-07 23:28:35 UTC (rev 89527)
+++ zope.introspector/trunk/src/zope/introspector/code.py	2008-08-08 00:01:44 UTC (rev 89528)
@@ -14,6 +14,8 @@
 """The real information providers for code objects (packages, classes, etc.)
 """
 
+import pkg_resources
+from pkg_resources import DistributionNotFound
 import grokcore.component as grok
 from grokcore.component.interfaces import IContext
 import types
@@ -103,8 +105,22 @@
 
     def getModules(self):
         return sorted(self._filterSubItems(lambda x: not x.isPackage()))
-        
 
+    def getEggInfo(self):
+        try:
+            info = pkg_resources.get_distribution(self.context.dotted_name)
+        except DistributionNotFound:
+            return None
+        version = info.has_version and info.version or None
+        name = info.project_name
+        py_version = info.py_version
+        location = info.location
+        return dict(
+            name=name,
+            version=version,
+            py_version=py_version,
+            location=location)
+
 class Module(PackageOrModule):
     def __getitem__(self, name):
         module = self._module_info.getModule()

Modified: zope.introspector/trunk/src/zope/introspector/code.txt
===================================================================
--- zope.introspector/trunk/src/zope/introspector/code.txt	2008-08-07 23:28:35 UTC (rev 89527)
+++ zope.introspector/trunk/src/zope/introspector/code.txt	2008-08-08 00:01:44 UTC (rev 89528)
@@ -158,6 +158,15 @@
    <ModuleInfo object for 'zope.introspector.util'>,
    <ModuleInfo object for 'zope.introspector.viewinfo'>]
 
+We can get some information about the egg, this package is part of (if
+any). We get the egg name, version, Python version and egg location::
+
+  >>> pprint(info.getEggInfo())
+  {'location': '.../src',
+   'name': 'zope.introspector',
+   'py_version': None,
+   'version': '0...'}
+
 We can also grab the basic information provided by the adapted
 ``Package`` object::
 



More information about the Checkins mailing list