# HG changeset patch # User Jeff Hammel # Date 1330126782 28800 # Node ID 0dd1f8f83be2729fa59049c10310026cf4dd8dfa # Parent ceb8c69a16f3ab856a0d17791e9137c0d229b7be moving towards some sort of organization diff -r ceb8c69a16f3 -r 0dd1f8f83be2 paint/package.py --- 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()