Mercurial > hg > PaInt
annotate paint/package.py @ 62:726008cff4e3
remove code supporting old version
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 25 Jan 2013 11:07:34 -0800 |
parents | 13767ee2ddf4 |
children | ad174d9f396d |
rev | line source |
---|---|
4 | 1 """ |
2 package model for python PAckage INTrospection | |
3 """ | |
4 | |
36 | 5 # TODO: use pkginfo.sdist more |
6 | |
57 | 7 import info |
7 | 8 import os |
28 | 9 import pip |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
10 import shutil |
19 | 11 import subprocess |
12 import sys | |
7 | 13 import tarfile |
5 | 14 import tempfile |
7 | 15 import urllib2 |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
16 import urlparse |
7 | 17 import utils |
5 | 18 |
62
726008cff4e3
remove code supporting old version
Jeff Hammel <jhammel@mozilla.com>
parents:
58
diff
changeset
|
19 from subprocess import check_call as call |
19 | 20 |
10 | 21 __all__ = ['Package'] |
22 | |
4 | 23 class Package(object): |
33 | 24 """ |
25 class for python package introspection. | |
26 constructor takes the package 'src' | |
27 """ | |
4 | 28 |
50 | 29 def __init__(self, src, verbose=True): |
4 | 30 self.src = src |
50 | 31 self.verbose = verbose |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
32 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
33 # ephemeral data |
5 | 34 self._tmppath = None |
28 | 35 self._egg_info_path = None |
33 | 36 self._build_path = None |
40
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
37 self._pkg_info_path = None |
5 | 38 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
39 # TODO: list of temporary files/directories to be deleted |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
40 |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
41 def _log(self, message): |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
42 if self.verbose: |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
43 print '>>> %s' % message |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
44 |
34 | 45 def _path(self): |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
46 """filesystem path to package directory""" |
7 | 47 |
51 | 48 self._log(">>> _path:Getting path to package") |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
49 |
7 | 50 # return cached copy if it exists |
51 if self._tmppath: | |
52 return self._tmppath | |
53 | |
54 # fetch from the web if a URL | |
55 tmpfile = None | |
56 src = self.src | |
5 | 57 if utils.isURL(self.src): |
8 | 58 tmpfile = src = self.fetch() |
7 | 59 |
60 # unpack if an archive | |
28 | 61 if self._is_archive(src): |
8 | 62 try: |
37 | 63 self._unpack(src) |
8 | 64 finally: |
65 if tmpfile: | |
66 os.remove(tmpfile) | |
7 | 67 return self._tmppath |
68 | |
5 | 69 return self.src |
70 | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
71 def fetch(self, filename=None): |
8 | 72 """fetch from remote source to a temporary file""" |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
73 if filename is None: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
74 fd, filename = tempfile.mkstemp() |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
75 os.close(fd) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
76 fp = file(filename, 'w') |
15
8c8b7482772f
fix a few failures but still failing
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
77 resource = urllib2.urlopen(self.src) |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
78 fp.write(resource.read()) |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
79 fp.close() |
7 | 80 return filename |
81 | |
37 | 82 def _unpack(self, archive): |
7 | 83 """unpack the archive to a temporary destination""" |
84 # TODO: should handle zipfile additionally at least | |
85 # Ideally, this would be pluggable, etc | |
8 | 86 assert tarfile.is_tarfile(archive), "%s is not an archive" % self.src |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
87 tf = tarfile.TarFile.open(archive) |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
88 self._tmppath = tempfile.mkdtemp() |
19 | 89 members = tf.getmembers() |
90 | |
91 # cut off the top level directory | |
37 | 92 members = [i for i in members if os.path.sep in i.name] |
19 | 93 tld = set() |
94 for member in members: | |
95 directory, member.name = member.name.split(os.path.sep, 1) | |
96 tld.add(directory) | |
97 assert len(tld) == 1 | |
98 | |
99 # extract | |
100 for member in members: | |
101 tf.extract(member, path=self._tmppath) | |
102 tf.close() | |
7 | 103 |
28 | 104 def _is_archive(self, path): |
7 | 105 """returns if the filesystem path is an archive""" |
106 # TODO: should handle zipfile additionally at least | |
107 # Ideally, this would be pluggable, etc | |
108 return tarfile.is_tarfile(path) | |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
109 |
28 | 110 def _cleanup(self): |
9
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
111 if self._tmppath: |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
112 shutil.rmtree(self._tmppath) |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
113 self._tmppath = None |
562230cc2e86
now the package class should at least extracts things. it doesnt actually do anything useful
Jeff Hammel <jhammel@mozilla.com>
parents:
8
diff
changeset
|
114 |
18
4c4d1e194bf7
leave in debugging code for now
Jeff Hammel <jhammel@mozilla.com>
parents:
17
diff
changeset
|
115 # __del__ = cleanup |
11 | 116 |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
117 ### python-package-specific functionality |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
118 |
28 | 119 def _egg_info(self): |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
120 """build the egg_info directory""" |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
121 |
28 | 122 if self._egg_info_path: |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
123 # return cached copy |
28 | 124 return self._egg_info_path |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
125 |
34 | 126 directory = self._path() |
16 | 127 setup_py = os.path.join(directory, 'setup.py') |
128 if not os.path.exists(setup_py): | |
17 | 129 raise AssertionError("%s does not exist" % setup_py) |
11 | 130 |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
131 # setup the egg info |
39
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
132 exception = None |
38 | 133 try: |
39
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
134 code = call([sys.executable, 'setup.py', 'egg_info'], cwd=directory, stdout=subprocess.PIPE) |
45 | 135 except Exception, exception: |
39
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
136 pass |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
137 if code or exception: |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
138 message = """Failure to generate egg_info |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
139 - src: %s |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
140 - directory: %s |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
141 """ % (self.src, directory) |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
142 if exception: |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
143 sys.stderr.write(message) |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
144 raise exception |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
145 else: |
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
146 raise Exception(message) |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
147 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
148 # get the .egg-info directory |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
149 egg_info = [i for i in os.listdir(directory) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
150 if i.endswith('.egg-info')] |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
151 assert len(egg_info) == 1, 'Expected one .egg-info directory in %s, got: %s' % (directory, egg_info) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
152 egg_info = os.path.join(directory, egg_info[0]) |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
153 assert os.path.isdir(egg_info), "%s is not a directory" % egg_info |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
154 |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
155 # cache it |
28 | 156 self._egg_info_path = egg_info |
157 return self._egg_info_path | |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
158 |
40
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
159 def _pkg_info(self): |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
160 """returns path to PKG-INFO file""" |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
161 |
39
cc25499e9485
note TODO....and cry a little
Jeff Hammel <jhammel@mozilla.com>
parents:
38
diff
changeset
|
162 if self._pkg_info_path: |
40
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
163 # return cached value |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
164 return self._pkg_info_path |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
165 |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
166 try: |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
167 egg_info = self._egg_info() |
45 | 168 except Exception, exception: |
40
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
169 # try to get the package info from a file |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
170 path = self._path() |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
171 pkg_info = os.path.join(path, 'PKG-INFO') |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
172 if os.path.exists(pkg_info): |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
173 self._pkg_info_path = pkg_info |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
174 return self._pkg_info_path |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
175 raise Exception("Cannot find or generate PKG-INFO") |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
176 |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
177 pkg_info = os.path.join(egg_info, 'PKG-INFO') |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
178 assert os.path.exists(pkg_info) |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
179 self._pkg_info_path = pkg_info |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
180 return self._pkg_info_path |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
181 |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
182 def info(self): |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
183 """return info dictionary for package""" |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
184 # could use pkginfo module |
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
185 |
53
c588375a7ce4
starting a new strawman to work out kinks
Jeff Hammel <jhammel@mozilla.com>
parents:
52
diff
changeset
|
186 self._log(">>> Getting the info") |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
187 |
40
06f21791eba1
add yet another indirection layer
Jeff Hammel <jhammel@mozilla.com>
parents:
39
diff
changeset
|
188 pkg_info = self._pkg_info() |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
189 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
190 # read the package information |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
191 info_dict = {} |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
192 for line in file(pkg_info).readlines(): |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
193 if not line or line[0].isspace(): |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
194 continue # XXX neglects description |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
195 assert ':' in line |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
196 key, value = [i.strip() for i in line.split(':', 1)] |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
197 info_dict[key] = value |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
198 |
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
199 # return the information |
20
11bc01a089e7
return only the dictionary
Jeff Hammel <jhammel@mozilla.com>
parents:
19
diff
changeset
|
200 return info_dict |
13
0dd1f8f83be2
moving towards some sort of organization
Jeff Hammel <jhammel@mozilla.com>
parents:
12
diff
changeset
|
201 |
11 | 202 def dependencies(self): |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
203 """return the dependencies""" |
32 | 204 # TODO: should probably have a more detailed dict: |
205 # {'mozinfo': {'version': '>= 0.2', | |
206 # 'url': 'http://something.com/'}} | |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
207 # get the egg_info directory |
28 | 208 egg_info = self._egg_info() |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
209 |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
210 # read the dependencies |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
211 requires = os.path.join(egg_info, 'requires.txt') |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
212 if os.path.exists(requires): |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
213 dependencies = [i.strip() for i in file(requires).readlines() if i.strip()] |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
214 else: |
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
215 dependencies = [] |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
216 dependencies = dict([(i, None) for i in dependencies]) |
14
6d27c2136163
a decent structure; need to reuse more
Jeff Hammel <jhammel@mozilla.com>
parents:
13
diff
changeset
|
217 |
21
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
218 # read the dependency links |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
219 dependency_links = os.path.join(egg_info, 'dependency_links.txt') |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
220 if os.path.exists(dependency_links): |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
221 links = [i.strip() for i in file(dependency_links).readlines() if i.strip()] |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
222 for link in links: |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
223 # XXX pretty ghetto |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
224 assert '#egg=' in link |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
225 url, dep = link.split('#egg=', 1) |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
226 if dep in dependencies: |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
227 dependencies[dep] = link |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
228 |
4df3e715817d
now have passing tests again
Jeff Hammel <jhammel@mozilla.com>
parents:
20
diff
changeset
|
229 return dependencies |
24 | 230 |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
231 def extension(self): |
35 | 232 """filename extension of the package""" |
233 | |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
234 print ">>> extension:Getting package" |
35 | 235 package = self.package() |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
236 print ">>> extension:package=%s" % package |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
237 |
35 | 238 # determine the extension (XXX hacky) |
239 extensions = ('.tar.gz', '.zip', '.tar.bz2') | |
240 for ext in extensions: | |
36 | 241 if package.endswith(ext): |
35 | 242 return ext |
243 | |
244 raise Exception("Extension %s not found: %s" % (extensions, package)) | |
245 | |
246 def package(self, destination=None): | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
247 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
248 repackage the package to ensure its actually in the right form |
34 | 249 and return the path to the destination |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
250 - destination: if given, path to put the build in |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
251 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
252 |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
253 self._log("package: Getting package directory, destination=%s" % repr(destination)) |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
254 |
33 | 255 if self._build_path: |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
256 self._log("package: build_path already set: %s" % self._build_path) |
34 | 257 if destination: |
258 shutil.copy(self._build_path, destination) | |
259 return os.path.abspath(destination) | |
260 | |
261 # return cached copy | |
33 | 262 return self._build_path |
263 | |
34 | 264 path = self._path() |
265 dist = os.path.join(path, 'dist') | |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
266 self._log("package: dist directory: %s; (path=%s)" % (dist, path)) |
34 | 267 if os.path.exists(dist): |
268 shutil.rmtree(dist) | |
269 | |
49
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
270 command = [sys.executable, 'setup.py', 'sdist'] |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
271 self._log("package: running: %s" % ' '.join(command)) |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
272 call(command, cwd=path) |
85374a69cf89
call in foreground to avoid hang :(
Jeff Hammel <jhammel@mozilla.com>
parents:
48
diff
changeset
|
273 self._log("package: done running setup.py dist") |
34 | 274 |
275 assert os.path.exists(dist) | |
276 contents = os.listdir(dist) | |
277 assert len(contents) == 1 | |
278 | |
279 self._build_path = os.path.join(dist, contents[0]) | |
280 | |
281 # destination | |
282 # use an evil recursive trick | |
283 if destination: | |
36 | 284 return self.package(destination=destination) |
34 | 285 |
286 return self._build_path | |
287 | |
24 | 288 def download(self, directory): |
289 """download a package and all its dependencies using pip""" | |
28 | 290 if not os.path.exists(directory): |
291 os.makedirs(directory) | |
292 assert os.path.isdir(directory) | |
293 pip.main(['install', '--download', directory, self.src]) | |
294 | |
295 def pypi(self, directory): | |
296 """ | |
297 download packages for a pypi directory structure | |
298 http://k0s.org/portfolio/pypi.html | |
299 """ | |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
300 if not os.path.exists(directory): |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
301 os.makedirs(directory) |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
302 assert os.path.isdir(directory) |
28 | 303 tempdir = tempfile.mkdtemp() |
304 try: | |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
305 self.download(tempdir) |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
306 files = os.listdir(tempdir) |
52 | 307 self._log(">>> Files: %s" % files) |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
308 for f in files: |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
309 |
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
310 # full path |
47 | 311 src = os.path.join(tempdir, f) |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
312 |
35 | 313 # make a package of the thing |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
314 print ">>> pypi:Packaging %s" % src |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
315 package = Package(src) |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
316 print ">>> pypi:DONE packaging %s" % src |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
317 |
36 | 318 # get destination dirname, filename |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
319 print ">>> pypi:Getting PyPI path" |
36 | 320 dirname, filename = package.pypi_path() |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
321 print ">>> pypi:DONE PyPI path: %s/%s" % (dirname, filename) |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
322 |
36 | 323 # make the directory if it doesn't exist |
324 subdir = os.path.join(directory, dirname) | |
325 if not os.path.exists(subdir): | |
326 os.makedirs(subdir) | |
327 assert os.path.isdir(subdir) | |
29
59524b6d25c0
implementing making pypi directory strcuture from a package
Jeff Hammel <jhammel@mozilla.com>
parents:
28
diff
changeset
|
328 |
36 | 329 # move the file |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
330 print ">>> pypi:Moving to PyPI path %s/%s" % (subdir, filename) |
47 | 331 package.package(destination=os.path.join(subdir, filename)) |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
332 print ">>> Done with %s" % src |
28 | 333 finally: |
334 shutil.rmtree(tempdir) | |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
335 |
36 | 336 def pypi_path(self): |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
337 """ |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
338 returns subpath 2-tuple appropriate for pypi path structure: |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
339 http://k0s.org/portfolio/pypi.html |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
340 """ |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
341 print ">>> pypi_path:Getting info" |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
342 info = self.info() |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
343 print ">>> pypi_path:DONE getting info" |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
344 |
36 | 345 # determine the extension |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
346 print ">>> pypi_path:Getting extension" |
36 | 347 extension = self.extension() |
48
abfb267e8332
debugging info; lord i hate this
Jeff Hammel <jhammel@mozilla.com>
parents:
47
diff
changeset
|
348 print ">>> pypi_path:DONE Getting extension: %s" % extension |
31
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
349 |
5fb1844db0b2
back to the drawring broad
Jeff Hammel <jhammel@mozilla.com>
parents:
30
diff
changeset
|
350 # get the filename destination |
36 | 351 name = info['Name'] |
352 version = info['Version'] | |
353 filename = '%s-%s%s' % (name, version, extension) | |
354 return name, filename |