Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 29329056: Issue 3194 - Allow multiple sources for a dependency (Closed)
Left Patch Set: Addressed feedback Created Oct. 15, 2015, 4:06 p.m.
Right Patch Set: Just return a list from merge_seqs instead of coercing the result into a tuple Created Oct. 16, 2015, 10:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This Source Code Form is subject to the terms of the Mozilla Public 4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 7
8 import sys 8 import sys
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 16 matching lines...) Expand all
27 # File to update this script from (optional) 27 # File to update this script from (optional)
28 _self = buildtools/ensure_dependencies.py 28 _self = buildtools/ensure_dependencies.py
29 # Clone elemhidehelper repository into extensions/elemhidehelper directory at 29 # Clone elemhidehelper repository into extensions/elemhidehelper directory at
30 # tag "1.2". 30 # tag "1.2".
31 extensions/elemhidehelper = elemhidehelper 1.2 31 extensions/elemhidehelper = elemhidehelper 1.2
32 # Clone buildtools repository into buildtools directory at VCS-specific 32 # Clone buildtools repository into buildtools directory at VCS-specific
33 # revision IDs. 33 # revision IDs.
34 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5 34 buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5
35 # Clone the adblockplus repository into adblockplus directory, overwriting the 35 # Clone the adblockplus repository into adblockplus directory, overwriting the
36 # usual source URL for Git repository and specifying VCS specific revision IDs . 36 # usual source URL for Git repository and specifying VCS specific revision IDs .
37 adblockplus = adblockplus hg:893426c6a6ab git:git@github.com:kzar/adblockplus. git@b2ffd52b 37 adblockplus = adblockplus hg:893426c6a6ab git:git@github.com:user/adblockplus. git@b2ffd52b
38 # Clone the adblockpluschrome repository into the adblockpluschrome directory, 38 # Clone the adblockpluschrome repository into the adblockpluschrome directory,
39 # from a specific Git repository, specifying the revision ID. 39 # from a specific Git repository, specifying the revision ID.
40 adblockpluschrome = git:git@github.com:kzar/adblockpluschrome.git@1fad3a7 40 adblockpluschrome = git:git@github.com:user/adblockpluschrome.git@1fad3a7
41 """ 41 """
42 42
43 SKIP_DEPENDENCY_UPDATES = os.environ.get( 43 SKIP_DEPENDENCY_UPDATES = os.environ.get(
44 "SKIP_DEPENDENCY_UPDATES", "" 44 "SKIP_DEPENDENCY_UPDATES", ""
45 ).lower() not in ("", "0", "false") 45 ).lower() not in ("", "0", "false")
46 46
47 class Mercurial(): 47 class Mercurial():
48 def istype(self, repodir): 48 def istype(self, repodir):
49 return os.path.exists(os.path.join(repodir, ".hg")) 49 return os.path.exists(os.path.join(repodir, ".hg"))
50 50
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return "ssh://" + url.replace(":", "/", 1) 136 return "ssh://" + url.replace(":", "/", 1)
137 return url 137 return url
138 138
139 repo_types = OrderedDict(( 139 repo_types = OrderedDict((
140 ("hg", Mercurial()), 140 ("hg", Mercurial()),
141 ("git", Git()), 141 ("git", Git()),
142 )) 142 ))
143 143
144 # [vcs:]value 144 # [vcs:]value
145 item_regexp = re.compile( 145 item_regexp = re.compile(
146 "^(?:(" + "|".join(repo_types.keys()) +"):)?" 146 "^(?:(" + "|".join(map(re.escape, repo_types.keys())) +"):)?"
Sebastian Noack 2015/10/15 17:03:07 Please use map(re.escape, ...), just in case.
kzar 2015/10/16 10:20:05 Done.
147 "(.+)$" 147 "(.+)$"
148 ) 148 )
149 149
150 # [url@]rev 150 # [url@]rev
151 source_regexp = re.compile( 151 source_regexp = re.compile(
152 "^(?:(.*)@)?" 152 "^(?:(.*)@)?"
153 "(.+)$" 153 "(.+)$"
154 ) 154 )
155 155
156 def merge_tuples(tuple_1, tuple_2): 156 def merge_seqs(seq1, seq2):
157 """Return tuple containing any truthy values from the suplied tuples 157 """Return a list of any truthy values from the suplied sequences
158 158
159 (None, 2), (1,) => (1, 2) 159 (None, 2), (1,) => [1, 2]
160 None, (1, 2) => (1, 2) 160 None, (1, 2) => [1, 2]
161 (1, 2), (3, 4) => (3, 4) 161 (1, 2), (3, 4) => [3, 4]
162 """ 162 """
163 return tuple(i2 or i1 for i1, i2 in map(None, tuple_1 or (), tuple_2 or ())) 163 return map(lambda item1, item2: item2 or item1, seq1 or (), seq2 or ())
Sebastian Noack 2015/10/15 17:03:07 While already using map, why not passing a functio
kzar 2015/10/16 10:20:05 Good points and I agree that the function's name d
164 164
165 def parse_spec(path, line): 165 def parse_spec(path, line):
166 if "=" not in line: 166 if "=" not in line:
167 logging.warning("Invalid line in file %s: %s" % (path, line)) 167 logging.warning("Invalid line in file %s: %s" % (path, line))
168 return None, None 168 return None, None
169 169
170 key, value = line.split("=", 1) 170 key, value = line.split("=", 1)
171 key = key.strip() 171 key = key.strip()
172 items = value.split() 172 items = value.split()
173 if not len(items): 173 if not len(items):
174 logging.warning("No value specified for key %s in file %s" % (key, path)) 174 logging.warning("No value specified for key %s in file %s" % (key, path))
175 return key, None 175 return key, None
176 176
177 result = OrderedDict() 177 result = OrderedDict()
178 is_dependency_field = not key.startswith("_") 178 is_dependency_field = not key.startswith("_")
179 179
180 for i, item in enumerate(items): 180 for i, item in enumerate(items):
181 try: 181 try:
182 vcs, value = re.search(item_regexp, item).groups() 182 vcs, value = re.search(item_regexp, item).groups()
183 vcs = vcs or "*" 183 vcs = vcs or "*"
184 if is_dependency_field: 184 if is_dependency_field:
185 if i == 0 and vcs == "*": 185 if i == 0 and vcs == "*":
186 # In order to be backwards compatible we have to assume that the first 186 # In order to be backwards compatible we have to assume that the first
187 # source contains only a URL/path for the repo if it does not contain 187 # source contains only a URL/path for the repo if it does not contain
188 # the VCS part 188 # the VCS part
189 url_rev = (value, None) 189 url_rev = (value, None)
190 else: 190 else:
191 url_rev = re.search(source_regexp, value).groups() 191 url_rev = re.search(source_regexp, value).groups()
192 result[vcs] = merge_tuples(result.get(vcs), url_rev) 192 result[vcs] = merge_seqs(result.get(vcs), url_rev)
193 else: 193 else:
194 if vcs in result: 194 if vcs in result:
195 logging.warning("Ignoring duplicate value for type %r " 195 logging.warning("Ignoring duplicate value for type %r "
196 "(key %r in file %r)" % (vcs, key, path)) 196 "(key %r in file %r)" % (vcs, key, path))
197 result[vcs] = value 197 result[vcs] = value
198 except AttributeError: 198 except AttributeError:
199 logging.warning("Ignoring invalid item %r for type %r " 199 logging.warning("Ignoring invalid item %r for type %r "
200 "(key %r in file %r)" % (item, vcs, key, path)) 200 "(key %r in file %r)" % (item, vcs, key, path))
201 continue 201 continue
202 return key, result 202 return key, result
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 skipdependencies.intersection([s[0] for s in sources if s[0]])): 300 skipdependencies.intersection([s[0] for s in sources if s[0]])):
301 continue 301 continue
302 302
303 target = safe_join(repodir, dir) 303 target = safe_join(repodir, dir)
304 parenttype = get_repo_type(repodir) 304 parenttype = get_repo_type(repodir)
305 _root = config.get("_root", {}) 305 _root = config.get("_root", {})
306 306
307 for key in sources.keys() + _root.keys(): 307 for key in sources.keys() + _root.keys():
308 if key == parenttype or key is None and vcs != "*": 308 if key == parenttype or key is None and vcs != "*":
309 vcs = key 309 vcs = key
310 source, rev = merge_tuples(sources.get("*"), sources.get(vcs)) 310 source, rev = merge_seqs(sources.get("*"), sources.get(vcs))
311 311
312 if not (vcs and source and rev): 312 if not (vcs and source and rev):
313 logging.warning("No valid source / revision found to create %s" % target) 313 logging.warning("No valid source / revision found to create %s" % target)
314 continue 314 continue
315 315
316 ensure_repo(repodir, parenttype, target, vcs, _root.get(vcs, ""), source) 316 ensure_repo(repodir, parenttype, target, vcs, _root.get(vcs, ""), source)
317 update_repo(target, vcs, rev) 317 update_repo(target, vcs, rev)
318 resolve_deps(target, level + 1, self_update=False, 318 resolve_deps(target, level + 1, self_update=False,
319 overrideroots=overrideroots, skipdependencies=skipdependencies) 319 overrideroots=overrideroots, skipdependencies=skipdependencies)
320 320
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 args = parser.parse_args() 362 args = parser.parse_args()
363 363
364 if args.quiet: 364 if args.quiet:
365 logging.disable(logging.INFO) 365 logging.disable(logging.INFO)
366 366
367 repos = args.repos 367 repos = args.repos
368 if not len(repos): 368 if not len(repos):
369 repos = [os.path.dirname(__file__)] 369 repos = [os.path.dirname(__file__)]
370 for repo in repos: 370 for repo in repos:
371 resolve_deps(repo) 371 resolve_deps(repo)
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld