Mercurial > hg > PaInt
comparison paint/package.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 12:ceb8c69a16f3 | 13:0dd1f8f83be2 |
|---|---|
| 14 class Package(object): | 14 class Package(object): |
| 15 # XXX much of this is generic resource stuff and should be split off | 15 # XXX much of this is generic resource stuff and should be split off |
| 16 | 16 |
| 17 def __init__(self, src): | 17 def __init__(self, src): |
| 18 self.src = src | 18 self.src = src |
| 19 | |
| 20 # ephemeral data | |
| 19 self._tmppath = None | 21 self._tmppath = None |
| 22 self._egg_info = None | |
| 20 | 23 |
| 21 def path(self): | 24 def path(self): |
| 22 """filesystem path to package""" | 25 """filesystem path to package""" |
| 23 | 26 |
| 24 # return cached copy if it exists | 27 # return cached copy if it exists |
| 70 shutil.rmtree(self._tmppath) | 73 shutil.rmtree(self._tmppath) |
| 71 self._tmppath = None | 74 self._tmppath = None |
| 72 | 75 |
| 73 __del__ = cleanup | 76 __del__ = cleanup |
| 74 | 77 |
| 78 ### python-package-specific functionality | |
| 79 | |
| 80 def egg_info(self): | |
| 81 """build the egg_info directory""" | |
| 82 | |
| 83 if self._egg_info: | |
| 84 # return cached copy | |
| 85 return self._egg_info | |
| 86 | |
| 87 directory = self.path | |
| 88 | |
| 75 def info(self): | 89 def info(self): |
| 76 """return info dictionary for package""" | 90 """return info dictionary for package""" |
| 77 path = self.path() | 91 directory = self.path() |
| 78 assert os.path.exists(os.path.join(path, 'setup.py')) | 92 assert os.path.exists(os.path.join(path, 'setup.py')) |
| 93 | |
| 94 # setup the egg info | |
| 95 call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=PIPE) | |
| 96 | |
| 97 # get the .egg-info directory | |
| 98 egg_info = [i for i in os.listdir(directory) | |
| 99 if i.endswith('.egg-info')] | |
| 100 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) | |
| 101 egg_info = os.path.join(directory, egg_info[0]) | |
| 102 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info | |
| 103 | |
| 104 # read the dependencies | |
| 105 requires = os.path.join(egg_info, 'requires.txt') | |
| 106 if os.path.exists(requires): | |
| 107 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()] | |
| 108 else: | |
| 109 dependencies = [] | |
| 110 | |
| 111 # read the package information | |
| 112 pkg_info = os.path.join(egg_info, 'PKG-INFO') | |
| 113 info_dict = {} | |
| 114 for line in file(pkg_info).readlines(): | |
| 115 if not line or line[0].isspace(): | |
| 116 continue # XXX neglects description | |
| 117 assert ':' in line | |
| 118 key, value = [i.strip() for i in line.split(':', 1)] | |
| 119 info_dict[key] = value | |
| 120 | |
| 121 # return the information | |
| 122 return info_dict['Name'], dependencies | |
| 79 | 123 |
| 80 def dependencies(self): | 124 def dependencies(self): |
| 81 info = self.info() | 125 info = self.info() |
