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

Delta Between Two Patch Sets: ensure_dependencies.py

Issue 29570614: Issue 5028 - Use browser namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Promisify Created Oct. 11, 2017, 3:22 a.m.
Right Patch Set: Update adblockplusui dependency Created Oct. 17, 2017, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « devtools.js ('k') | ext/background.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 25 matching lines...) Expand all
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: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
47 NPM_LOCKFILE = '.npm_install_lock'
46 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])
(...skipping 208 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:
274 cmd = ['npm', 'install', '--only=production', '--loglevel=warn'] 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
281 cmd = ['npm', 'install', '--only=production',
282 '--loglevel=warn', '--no-package-lock']
275 subprocess.check_output(cmd, cwd=target) 283 subprocess.check_output(cmd, cwd=target)
276 284
285 repo_types[vcs].ignore(os.path.join(target, NPM_LOCKFILE), target)
277 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target) 286 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target)
287
288 os.remove(lockfile_path)
278 except OSError as e: 289 except OSError as e:
279 import errno 290 import errno
280 if e.errno == errno.ENOENT: 291 if e.errno == errno.ENOENT:
281 logging.error('Failed to install Node.js dependencies for %s,' 292 logging.error('Failed to install Node.js dependencies for %s,'
282 ' please ensure Node.js is installed.', target) 293 ' please ensure Node.js is installed.', target)
283 else: 294 else:
284 raise 295 raise
285 296
286 297
287 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename): 298 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename):
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 vcs = key 369 vcs = key
359 source, rev = merge_seqs(sources.get('*'), sources.get(vcs)) 370 source, rev = merge_seqs(sources.get('*'), sources.get(vcs))
360 371
361 if not (vcs and source and rev): 372 if not (vcs and source and rev):
362 logging.warning('No valid source / revision found to create %s' % ta rget) 373 logging.warning('No valid source / revision found to create %s' % ta rget)
363 continue 374 continue
364 375
365 repo_cloned = ensure_repo(repodir, parenttype, target, vcs, 376 repo_cloned = ensure_repo(repodir, parenttype, target, vcs,
366 _root.get(vcs, ''), source) 377 _root.get(vcs, ''), source)
367 repo_updated = update_repo(target, vcs, rev) 378 repo_updated = update_repo(target, vcs, rev)
368 if repo_cloned or repo_updated: 379 recent_npm_failed = os.path.exists(os.path.join(target, NPM_LOCKFILE))
380 if repo_cloned or repo_updated or recent_npm_failed:
369 resolve_npm_dependencies(target, vcs) 381 resolve_npm_dependencies(target, vcs)
370 resolve_deps(target, level + 1, self_update=False, 382 resolve_deps(target, level + 1, self_update=False,
371 overrideroots=overrideroots, skipdependencies=skipdependenc ies) 383 overrideroots=overrideroots, skipdependencies=skipdependenc ies)
372 384
373 if self_update and '_self' in config and '*' in config['_self']: 385 if self_update and '_self' in config and '*' in config['_self']:
374 source = safe_join(repodir, config['_self']['*']) 386 source = safe_join(repodir, config['_self']['*'])
375 try: 387 try:
376 with io.open(source, 'rb') as handle: 388 with io.open(source, 'rb') as handle:
377 sourcedata = handle.read() 389 sourcedata = handle.read()
378 except IOError as e: 390 except IOError as e:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 args = parser.parse_args() 429 args = parser.parse_args()
418 430
419 if args.quiet: 431 if args.quiet:
420 logging.disable(logging.INFO) 432 logging.disable(logging.INFO)
421 433
422 repos = args.repos 434 repos = args.repos
423 if not len(repos): 435 if not len(repos):
424 repos = [os.path.dirname(__file__)] 436 repos = [os.path.dirname(__file__)]
425 for repo in repos: 437 for repo in repos:
426 resolve_deps(repo) 438 resolve_deps(repo)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld