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

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 29526588: Issue 5559 - include Node.js in ensure_dependencies.py (Closed)
Left Patch Set: Refactoring according to new integration notes Created Aug. 25, 2017, 9:50 a.m.
Right Patch Set: Created Aug. 28, 2017, 6:50 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 2
3 # This Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 import sys 7 import sys
8 import os 8 import os
9 import posixpath 9 import posixpath
10 import re 10 import re
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 Additionally, make sure that any VCS will ignore the installed files. 256 Additionally, make sure that any VCS will ignore the installed files.
257 257
258 Requires Node.js to be installed locally. 258 Requires Node.js to be installed locally.
259 """ 259 """
260 try: 260 try:
261 with open(os.path.join(target, 'package.json'), 'r') as fp: 261 with open(os.path.join(target, 'package.json'), 'r') as fp:
262 package_data = json.load(fp) 262 package_data = json.load(fp)
263 263
264 # In case a package.json does not exist at all or if there are no 264 # In case a package.json does not exist at all or if there are no
265 # production dependencies declared, we don't need to run npm and can 265 # production dependencies declared, we don't need to run npm and can
266 # bail out early 266 # bail out early.
267 if not package_data.get('dependencies', False): 267 if not package_data.get('dependencies', False):
268 return 268 return
269 except IOError: 269 except IOError:
270 return 270 return
271 271
272 try: 272 try:
273 cmd = ['npm', 'install', '--only=production', '--loglevel=warn'] 273 cmd = ['npm', 'install', '--only=production', '--loglevel=warn']
274 subprocess.check_output(cmd, cwd=target) 274 subprocess.check_output(cmd, cwd=target)
275 275
276 # Make sure Node.js related files / folders are ignored by the VCS in 276 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target)
277 # use
278 repo_types[vcs].ignore(
279 os.path.join(target, 'node_modules'), target
280 )
281 except OSError as e: 277 except OSError as e:
282 import errno 278 import errno
283 if e.errno == errno.ENOENT: 279 if e.errno == errno.ENOENT:
284 logging.error('Failed to install Node.js dependencies for %s,' 280 logging.error('Failed to install Node.js dependencies for %s,'
285 ' please ensure Node.js is installed.', target) 281 ' please ensure Node.js is installed.', target)
286 else: 282 else:
287 raise 283 raise
288 284
289 285
290 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename): 286 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename):
291 if os.path.exists(target): 287 if os.path.exists(target):
292 return 288 return False
293 289
294 if SKIP_DEPENDENCY_UPDATES: 290 if SKIP_DEPENDENCY_UPDATES:
295 logging.warning('SKIP_DEPENDENCY_UPDATES environment variable set, ' 291 logging.warning('SKIP_DEPENDENCY_UPDATES environment variable set, '
296 '%s not cloned', target) 292 '%s not cloned', target)
297 return 293 return False
298 294
299 postprocess_url = repo_types[type].postprocess_url 295 postprocess_url = repo_types[type].postprocess_url
300 root = postprocess_url(root) 296 root = postprocess_url(root)
301 sourcename = postprocess_url(sourcename) 297 sourcename = postprocess_url(sourcename)
302 298
303 if os.path.exists(root): 299 if os.path.exists(root):
304 url = os.path.join(root, sourcename) 300 url = os.path.join(root, sourcename)
305 else: 301 else:
306 url = urlparse.urljoin(root, sourcename) 302 url = urlparse.urljoin(root, sourcename)
307 303
308 logging.info('Cloning repository %s into %s' % (url, target)) 304 logging.info('Cloning repository %s into %s' % (url, target))
309 repo_types[type].clone(url, target) 305 repo_types[type].clone(url, target)
310 repo_types[parenttype].ignore(target, parentrepo) 306 repo_types[parenttype].ignore(target, parentrepo)
311 resolve_npm_dependencies(target, type) 307 return True
312 308
313 309
314 def update_repo(target, type, revision): 310 def update_repo(target, type, revision):
315 resolved_revision = repo_types[type].get_revision_id(target, revision) 311 resolved_revision = repo_types[type].get_revision_id(target, revision)
316 current_revision = repo_types[type].get_revision_id(target) 312 current_revision = repo_types[type].get_revision_id(target)
317 313
318 if resolved_revision != current_revision: 314 if resolved_revision != current_revision:
319 if SKIP_DEPENDENCY_UPDATES: 315 if SKIP_DEPENDENCY_UPDATES:
320 logging.warning('SKIP_DEPENDENCY_UPDATES environment variable set, ' 316 logging.warning('SKIP_DEPENDENCY_UPDATES environment variable set, '
321 '%s not checked out to %s', target, revision) 317 '%s not checked out to %s', target, revision)
322 return 318 return False
323 319
324 if not resolved_revision: 320 if not resolved_revision:
325 logging.info('Revision %s is unknown, downloading remote changes' % revision) 321 logging.info('Revision %s is unknown, downloading remote changes' % revision)
326 repo_types[type].pull(target) 322 repo_types[type].pull(target)
327 resolved_revision = repo_types[type].get_revision_id(target, revisio n) 323 resolved_revision = repo_types[type].get_revision_id(target, revisio n)
328 if not resolved_revision: 324 if not resolved_revision:
329 raise Exception('Failed to resolve revision %s' % revision) 325 raise Exception('Failed to resolve revision %s' % revision)
330 326
331 logging.info('Updating repository %s to revision %s' % (target, resolved _revision)) 327 logging.info('Updating repository %s to revision %s' % (target, resolved _revision))
332 repo_types[type].update(target, resolved_revision, revision) 328 repo_types[type].update(target, resolved_revision, revision)
333 resolve_npm_dependencies(target, type) 329 return True
Wladimir Palant 2017/08/25 10:01:59 For Mercurial repositories, both cloning and updat
tlucas 2017/08/25 10:06:40 Done.
330 return False
334 331
335 332
336 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()): 333 def resolve_deps(repodir, level=0, self_update=True, overrideroots=None, skipdep endencies=set()):
337 config = read_deps(repodir) 334 config = read_deps(repodir)
338 if config is None: 335 if config is None:
339 if level == 0: 336 if level == 0:
340 logging.warning('No dependencies file in directory %s, nothing to do ...\n%s' % (repodir, USAGE)) 337 logging.warning('No dependencies file in directory %s, nothing to do ...\n%s' % (repodir, USAGE))
341 return 338 return
342 if level >= 10: 339 if level >= 10:
343 logging.warning('Too much subrepository nesting, ignoring %s' % repo) 340 logging.warning('Too much subrepository nesting, ignoring %s' % repo)
(...skipping 13 matching lines...) Expand all
357 354
358 for key in sources.keys() + _root.keys(): 355 for key in sources.keys() + _root.keys():
359 if key == parenttype or key is None and vcs != '*': 356 if key == parenttype or key is None and vcs != '*':
360 vcs = key 357 vcs = key
361 source, rev = merge_seqs(sources.get('*'), sources.get(vcs)) 358 source, rev = merge_seqs(sources.get('*'), sources.get(vcs))
362 359
363 if not (vcs and source and rev): 360 if not (vcs and source and rev):
364 logging.warning('No valid source / revision found to create %s' % ta rget) 361 logging.warning('No valid source / revision found to create %s' % ta rget)
365 continue 362 continue
366 363
367 ensure_repo(repodir, parenttype, target, vcs, _root.get(vcs, ''), source ) 364 repo_cloned = ensure_repo(repodir, parenttype, target, vcs,
368 update_repo(target, vcs, rev) 365 _root.get(vcs, ''), source)
366 repo_updated = update_repo(target, vcs, rev)
367 if repo_cloned or repo_updated:
368 resolve_npm_dependencies(target, vcs)
369 resolve_deps(target, level + 1, self_update=False, 369 resolve_deps(target, level + 1, self_update=False,
370 overrideroots=overrideroots, skipdependencies=skipdependenc ies) 370 overrideroots=overrideroots, skipdependencies=skipdependenc ies)
371 371
372 if self_update and '_self' in config and '*' in config['_self']: 372 if self_update and '_self' in config and '*' in config['_self']:
373 source = safe_join(repodir, config['_self']['*']) 373 source = safe_join(repodir, config['_self']['*'])
374 try: 374 try:
375 with io.open(source, 'rb') as handle: 375 with io.open(source, 'rb') as handle:
376 sourcedata = handle.read() 376 sourcedata = handle.read()
377 except IOError as e: 377 except IOError as e:
378 if e.errno != errno.ENOENT: 378 if e.errno != errno.ENOENT:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 args = parser.parse_args() 415 args = parser.parse_args()
416 416
417 if args.quiet: 417 if args.quiet:
418 logging.disable(logging.INFO) 418 logging.disable(logging.INFO)
419 419
420 repos = args.repos 420 repos = args.repos
421 if not len(repos): 421 if not len(repos):
422 repos = [os.path.dirname(__file__)] 422 repos = [os.path.dirname(__file__)]
423 for repo in repos: 423 for repo in repos:
424 resolve_deps(repo) 424 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