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

Side by Side Diff: ensure_dependencies.py

Issue 29573912: Issue 5857 - Retry npm install on failure (Closed)
Patch Set: Created Oct. 11, 2017, 10:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 adblockplus = adblockplus hg:893426c6a6ab git:git@github.com:user/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:user/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 NPM_LOCKFILE = '.npm_install_lock'
Sebastian Noack 2017/10/11 23:22:33 This file would have to be added to .hgignore/.git
tlucas 2017/10/11 23:48:55 It is added to .hgignore/.gitignore, please see be
Sebastian Noack 2017/10/12 00:08:00 Ah right, I see. Yeah, if we can just make sure th
48
47 49
48 class Mercurial(): 50 class Mercurial():
49 def istype(self, repodir): 51 def istype(self, repodir):
50 return os.path.exists(os.path.join(repodir, '.hg')) 52 return os.path.exists(os.path.join(repodir, '.hg'))
51 53
52 def clone(self, source, target): 54 def clone(self, source, target):
53 if not source.endswith('/'): 55 if not source.endswith('/'):
54 source += '/' 56 source += '/'
55 subprocess.check_call(['hg', 'clone', '--quiet', '--noupdate', source, t arget]) 57 subprocess.check_call(['hg', 'clone', '--quiet', '--noupdate', source, t arget])
56 58
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 266
265 # In case a package.json does not exist at all or if there are no 267 # In case a package.json does not exist at all or if there are no
266 # production dependencies declared, we don't need to run npm and can 268 # production dependencies declared, we don't need to run npm and can
267 # bail out early. 269 # bail out early.
268 if not package_data.get('dependencies', False): 270 if not package_data.get('dependencies', False):
269 return 271 return
270 except IOError: 272 except IOError:
271 return 273 return
272 274
273 try: 275 try:
276 # Create an empty file, which gets deleted after successfully
277 # installing Node.js dependencies.
278 lockfile_path = os.path.join(target, NPM_LOCKFILE)
279 open(lockfile_path, 'a').close()
280
274 cmd = ['npm', 'install', '--only=production', '--loglevel=warn'] 281 cmd = ['npm', 'install', '--only=production', '--loglevel=warn']
275 subprocess.check_output(cmd, cwd=target) 282 subprocess.check_output(cmd, cwd=target)
276 283
284 repo_types[vcs].ignore(os.path.join(target, NPM_LOCKFILE), target)
kzar 2017/10/13 10:14:23 I wonder if we should just ignore this file consis
tlucas 2017/10/13 10:31:36 This file should - in a best case scenario - never
kzar 2017/10/13 11:20:42 Yea, fair enough.
277 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target) 285 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target)
286
287 os.remove(lockfile_path)
278 except OSError as e: 288 except OSError as e:
279 import errno 289 import errno
280 if e.errno == errno.ENOENT: 290 if e.errno == errno.ENOENT:
281 logging.error('Failed to install Node.js dependencies for %s,' 291 logging.error('Failed to install Node.js dependencies for %s,'
282 ' please ensure Node.js is installed.', target) 292 ' please ensure Node.js is installed.', target)
283 else: 293 else:
284 raise 294 raise
285 295
286 296
287 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename): 297 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename):
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 vcs = key 368 vcs = key
359 source, rev = merge_seqs(sources.get('*'), sources.get(vcs)) 369 source, rev = merge_seqs(sources.get('*'), sources.get(vcs))
360 370
361 if not (vcs and source and rev): 371 if not (vcs and source and rev):
362 logging.warning('No valid source / revision found to create %s' % ta rget) 372 logging.warning('No valid source / revision found to create %s' % ta rget)
363 continue 373 continue
364 374
365 repo_cloned = ensure_repo(repodir, parenttype, target, vcs, 375 repo_cloned = ensure_repo(repodir, parenttype, target, vcs,
366 _root.get(vcs, ''), source) 376 _root.get(vcs, ''), source)
367 repo_updated = update_repo(target, vcs, rev) 377 repo_updated = update_repo(target, vcs, rev)
368 if repo_cloned or repo_updated: 378 recent_npm_failed = os.path.exists(os.path.join(target, NPM_LOCKFILE))
379 if repo_cloned or repo_updated or recent_npm_failed:
369 resolve_npm_dependencies(target, vcs) 380 resolve_npm_dependencies(target, vcs)
370 resolve_deps(target, level + 1, self_update=False, 381 resolve_deps(target, level + 1, self_update=False,
371 overrideroots=overrideroots, skipdependencies=skipdependenc ies) 382 overrideroots=overrideroots, skipdependencies=skipdependenc ies)
372 383
373 if self_update and '_self' in config and '*' in config['_self']: 384 if self_update and '_self' in config and '*' in config['_self']:
374 source = safe_join(repodir, config['_self']['*']) 385 source = safe_join(repodir, config['_self']['*'])
375 try: 386 try:
376 with io.open(source, 'rb') as handle: 387 with io.open(source, 'rb') as handle:
377 sourcedata = handle.read() 388 sourcedata = handle.read()
378 except IOError as e: 389 except IOError as e:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 args = parser.parse_args() 428 args = parser.parse_args()
418 429
419 if args.quiet: 430 if args.quiet:
420 logging.disable(logging.INFO) 431 logging.disable(logging.INFO)
421 432
422 repos = args.repos 433 repos = args.repos
423 if not len(repos): 434 if not len(repos):
424 repos = [os.path.dirname(__file__)] 435 repos = [os.path.dirname(__file__)]
425 for repo in repos: 436 for repo in repos:
426 resolve_deps(repo) 437 resolve_deps(repo)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld