changeset 13:0dd1f8f83be2

moving towards some sort of organization
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 24 Feb 2012 15:39:42 -0800
parents ceb8c69a16f3
children 6d27c2136163
files paint/package.py
diffstat 1 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/paint/package.py	Fri Feb 24 15:21:28 2012 -0800
+++ b/paint/package.py	Fri Feb 24 15:39:42 2012 -0800
@@ -16,7 +16,10 @@
 
     def __init__(self, src):
         self.src = src
+
+        # ephemeral data
         self._tmppath = None
+        self._egg_info = None
 
     def path(self):
         """filesystem path to package"""
@@ -72,10 +75,51 @@
 
     __del__ = cleanup
 
+    ### python-package-specific functionality
+
+    def egg_info(self):
+        """build the egg_info directory"""
+
+        if self._egg_info:
+            # return cached copy
+            return self._egg_info
+
+        directory = self.path
+
     def info(self):
         """return info dictionary for package"""
-        path = self.path()
+        directory = self.path()
         assert os.path.exists(os.path.join(path, 'setup.py'))
 
+        # setup the egg info
+        call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE)
+
+        # get the .egg-info directory
+        egg_info = [i for i in os.listdir(directory)
+                    if i.endswith('.egg-info')]
+        assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info)
+        egg_info = os.path.join(directory, egg_info[0])
+        assert os.path.isdir(egg_info), "%s is not a directory" % egg_info
+
+        # read the dependencies
+        requires = os.path.join(egg_info, 'requires.txt')
+        if os.path.exists(requires):
+            dependencies = [i.strip() for i in file(requires).readlines() if i.strip()]
+        else:
+            dependencies = []
+
+        # read the package information
+        pkg_info = os.path.join(egg_info, 'PKG-INFO')
+        info_dict = {}
+        for line in file(pkg_info).readlines():
+            if not line or line[0].isspace():
+                continue # XXX neglects description
+            assert ':' in line
+            key, value = [i.strip() for i in line.split(':', 1)]
+            info_dict[key] = value
+
+        # return the information
+        return info_dict['Name'], dependencies
+
     def dependencies(self):
         info = self.info()