changeset 40:06f21791eba1

add yet another indirection layer
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 30 Mar 2012 15:58:13 -0700
parents cc25499e9485
children f5379e8ee6c2
files paint/package.py
diffstat 1 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/paint/package.py	Fri Mar 30 15:46:37 2012 -0700
+++ b/paint/package.py	Fri Mar 30 15:58:13 2012 -0700
@@ -36,6 +36,7 @@
         self._tmppath = None
         self._egg_info_path = None
         self._build_path = None
+        self._pkg_info_path = None
 
         # TODO: list of temporary files/directories to be deleted
 
@@ -151,19 +152,34 @@
         self._egg_info_path = egg_info
         return self._egg_info_path
 
-    def info(self):
-        """return info dictionary for package"""
-        # could use pkginfo
+    def _pkg_info(self):
+        """returns path to PKG-INFO file"""
 
         if self._pkg_info_path:
-            pkg_info = self._pkg_info_path
-        else:
-            try:
-                egg_info = self._egg_info()
-                pkg_info = os.path.join(egg_info, 'PKG-INFO')
-            except BaseException, exception:
-                # try to get the package info from a file
-                raise NotImplementedError("TODO: try to get the package info from a file")
+            # return cached value
+            return self._pkg_info_path
+
+        try:
+            egg_info = self._egg_info()
+        except BaseException, exception:
+            # try to get the package info from a file
+            path = self._path()
+            pkg_info = os.path.join(path, 'PKG-INFO')
+            if os.path.exists(pkg_info):
+                self._pkg_info_path = pkg_info
+                return self._pkg_info_path
+            raise Exception("Cannot find or generate PKG-INFO")
+
+        pkg_info = os.path.join(egg_info, 'PKG-INFO')
+        assert os.path.exists(pkg_info)
+        self._pkg_info_path = pkg_info
+        return self._pkg_info_path
+
+    def info(self):
+        """return info dictionary for package"""
+        # could use pkginfo module
+
+        pkg_info = self._pkg_info()
 
         # read the package information
         info_dict = {}