# HG changeset patch # User Jeff Hammel # Date 1358989176 28800 # Node ID 13767ee2ddf466e09d3314fdea359f5b87069c76 # Parent d5e5c74967842fb710463498250ee9c80edcfb9c start adding an egg_info based information thingy diff -r d5e5c7496784 -r 13767ee2ddf4 paint/info.py --- a/paint/info.py Wed Jan 23 16:26:14 2013 -0800 +++ b/paint/info.py Wed Jan 23 16:59:36 2013 -0800 @@ -4,6 +4,7 @@ import imp import os +import subprocess import sys from subprocess import check_call as call @@ -50,7 +51,26 @@ """ def __call__(self): - raise NotImplementedError("TODO") + + info = self.read_pkg_info(self._pkg_info()) + # TODO: install_requires + return info + + @classmethod + def read_pkg_info(cls, path): + """reads PKG-INFO and returns a dict""" + + # read the package information + info_dict = {} + for line in file(path).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 def _egg_info(self): """build the egg_info directory""" @@ -58,4 +78,46 @@ if self._egg_info_path: return self._egg_info_path - raise NotImplementedError("TODO") + directory = os.path.dirname(self.setup_py) + + # setup the egg info + try: + call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE) + except Exception: + print "Failure to generate egg_info: %s" % self.setup_py + raise + + # 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 + + # cache it + self._egg_info_path = egg_info + return self._egg_info_path + + def _pkg_info(self): + """returns path to PKG-INFO file""" + + if self._pkg_info_path: + # return cached value + return self._pkg_info_path + + try: + egg_info = self._egg_info() + except Exception, exception: + # try to get the package info from a file + path = os.path.dirname(self.setup_py) + 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 + diff -r d5e5c7496784 -r 13767ee2ddf4 paint/package.py --- a/paint/package.py Wed Jan 23 16:26:14 2013 -0800 +++ b/paint/package.py Wed Jan 23 16:59:36 2013 -0800 @@ -200,7 +200,6 @@ info_dict[key] = value # return the information - print ">>> Info: %s" % info_dict return info_dict def dependencies(self):