comparison paint/package.py @ 66:af7609457dc6

introduce a failing test; yay!
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 25 Jan 2013 13:50:40 -0800
parents 6d6f5c5c26d4
children d001017d5870
comparison
equal deleted inserted replaced
65:6d6f5c5c26d4 66:af7609457dc6
122 122
123 __del__ = _cleanup 123 __del__ = _cleanup
124 124
125 ### python-package-specific functionality 125 ### python-package-specific functionality
126 126
127 def _egg_info(self):
128 """build the egg_info directory"""
129
130 if self._egg_info_path:
131 # return cached copy
132 return self._egg_info_path
133
134 directory = self._path()
135 setup_py = os.path.join(directory, 'setup.py')
136 if not os.path.exists(setup_py):
137 raise AssertionError("%s does not exist" % setup_py)
138
139 # setup the egg info
140 exception = None
141 try:
142 code = call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE)
143 except Exception, exception:
144 pass
145 if code or exception:
146 message = """Failure to generate egg_info
147 - src: %s
148 - directory: %s
149 """ % (self.src, directory)
150 if exception:
151 sys.stderr.write(message)
152 raise exception
153 else:
154 raise Exception(message)
155
156 # get the .egg-info directory
157 egg_info = [i for i in os.listdir(directory)
158 if i.endswith('.egg-info')]
159 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info)
160 egg_info = os.path.join(directory, egg_info[0])
161 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info
162
163 # cache it
164 self._egg_info_path = egg_info
165 return self._egg_info_path
166
167 def _pkg_info(self):
168 """returns path to PKG-INFO file"""
169
170 if self._pkg_info_path:
171 # return cached value
172 return self._pkg_info_path
173
174 try:
175 egg_info = self._egg_info()
176 except Exception, exception:
177 # try to get the package info from a file
178 path = self._path()
179 pkg_info = os.path.join(path, 'PKG-INFO')
180 if os.path.exists(pkg_info):
181 self._pkg_info_path = pkg_info
182 return self._pkg_info_path
183 raise Exception("Cannot find or generate PKG-INFO")
184
185 pkg_info = os.path.join(egg_info, 'PKG-INFO')
186 assert os.path.exists(pkg_info)
187 self._pkg_info_path = pkg_info
188 return self._pkg_info_path
189
190 def info(self): 127 def info(self):
191 """return info dictionary for package""" 128 """return info dictionary for package"""
192 # could use pkginfo module 129 # could use pkginfo module
193 130
194 self._log(">>> Getting the info") 131 self._log(">>> Getting the info")
195 132 return self.package_info(self._path())()
196 pkg_info = self._pkg_info()
197
198 # read the package information
199 info_dict = {}
200 for line in file(pkg_info).readlines():
201 if not line or line[0].isspace():
202 continue # XXX neglects description
203 assert ':' in line
204 key, value = [i.strip() for i in line.split(':', 1)]
205 info_dict[key] = value
206
207 # return the information
208 return info_dict
209 133
210 def dependencies(self): 134 def dependencies(self):
211 """return the dependencies""" 135 """return the dependencies"""
212 # TODO: should probably have a more detailed dict: 136 # TODO: should probably have a more detailed dict:
213 # {'mozinfo': {'version': '>= 0.2', 137 # {'mozinfo': {'version': '>= 0.2',