Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: recipe_engine/package.py

Issue 1861203002: Make recipes.py run give better messages. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Fix test, remove unneeded description. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipe_engine/run.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 import ast 5 import ast
6 import collections 6 import collections
7 import contextlib 7 import contextlib
8 import copy 8 import copy
9 import difflib 9 import difflib
10 import functools 10 import functools
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return False 343 return False
344 return self._proto_file == other._proto_file 344 return self._proto_file == other._proto_file
345 345
346 346
347 class Package(object): 347 class Package(object):
348 """Package represents a loaded package, and contains path and dependency 348 """Package represents a loaded package, and contains path and dependency
349 information. 349 information.
350 350
351 This is accessed by loader.py through RecipeDeps.get_package. 351 This is accessed by loader.py through RecipeDeps.get_package.
352 """ 352 """
353 def __init__(self, name, repo_spec, deps, repo_root, recipes_dir): 353 def __init__(self, name, repo_spec, deps, repo_root, relative_recipes_dir):
354 self.name = name 354 self.name = name
355 self.repo_spec = repo_spec 355 self.repo_spec = repo_spec
356 self.deps = deps 356 self.deps = deps
357 self.repo_root = repo_root 357 self.repo_root = repo_root
358 self.recipes_dir = recipes_dir 358 self.relative_recipes_dir = relative_recipes_dir
359 359
360 def __repr__(self): 360 def __repr__(self):
361 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % ( 361 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % (
362 self.name, self.repo_spec, self.deps, self.recipes_dir) 362 self.name, self.repo_spec, self.deps, self.recipes_dir)
363 363
364 @property 364 @property
365 def recipes_dir(self):
366 return os.path.join(self.repo_root, self.relative_recipes_dir)
367
368 @property
365 def recipe_dirs(self): 369 def recipe_dirs(self):
366 return [os.path.join(self.recipes_dir, 'recipes')] 370 return [os.path.join(self.recipes_dir, 'recipes')]
367 371
368 @property 372 @property
369 def module_dirs(self): 373 def module_dirs(self):
370 return [os.path.join(self.recipes_dir, 'recipe_modules')] 374 return [os.path.join(self.recipes_dir, 'recipe_modules')]
371 375
372 def find_dep(self, dep_name): 376 def find_dep(self, dep_name):
373 if dep_name == self.name: 377 if dep_name == self.name:
374 return self 378 return self
375 379
376 assert dep_name in self.deps, ( 380 assert dep_name in self.deps, (
377 '%s does not exist or is not declared as a dependency of %s' % ( 381 '%s does not exist or is not declared as a dependency of %s' % (
378 dep_name, self.name)) 382 dep_name, self.name))
379 return self.deps[dep_name] 383 return self.deps[dep_name]
380 384
381 def module_path(self, module_name): 385 def module_path(self, module_name):
382 return os.path.join(self.recipes_dir, 'recipe_modules', module_name) 386 return os.path.join(self.recipes_dir, 'recipe_modules', module_name)
383 387
384 def loop_over_recipe_modules():
385 for path in self.module_dirs:
386 if os.path.isdir(path):
387 for item in os.listdir(path):
388 subpath = os.path.join(path, item)
389 if _is_recipe_module_dir(subpath):
390 yield subpath
391
392 def __repr__(self): 388 def __repr__(self):
393 return 'Package(%r, %r, %r, %r)' % ( 389 return 'Package(%r, %r, %r, %r)' % (
394 self.name, self.repo_spec, self.deps, self.recipe_dirs) 390 self.name, self.repo_spec, self.deps, self.recipe_dirs)
395 391
396 def __str__(self): 392 def __str__(self):
397 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys()) 393 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys())
398 394
399 395
400 class RollCandidate(object): 396 class RollCandidate(object):
401 """RollCandidate represents a recipe roll candidate, i.e. updates 397 """RollCandidate represents a recipe roll candidate, i.e. updates
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 self._packages[project_id] = None 640 self._packages[project_id] = None
645 641
646 deps = {} 642 deps = {}
647 for dep, dep_repo in sorted(package_spec.deps.items()): 643 for dep, dep_repo in sorted(package_spec.deps.items()):
648 dep_repo = self._overrides.get(dep, dep_repo) 644 dep_repo = self._overrides.get(dep, dep_repo)
649 deps[dep] = self._create_package(dep_repo) 645 deps[dep] = self._create_package(dep_repo)
650 646
651 package = Package( 647 package = Package(
652 project_id, repo_spec, deps, 648 project_id, repo_spec, deps,
653 repo_spec.repo_root(self._context), 649 repo_spec.repo_root(self._context),
654 os.path.join(repo_spec.repo_root(self._context), 650 package_spec.recipes_path)
655 package_spec.recipes_path))
656 651
657 self._packages[project_id] = package 652 self._packages[project_id] = package
658 return package 653 return package
659 654
660 # TODO(luqui): Remove this, so all accesses to packages are done 655 # TODO(luqui): Remove this, so all accesses to packages are done
661 # via other packages with properly scoped deps. 656 # via other packages with properly scoped deps.
662 def get_package(self, package_id): 657 def get_package(self, package_id):
663 return self._packages[package_id] 658 return self._packages[package_id]
664 659
665 @property 660 @property
(...skipping 12 matching lines...) Expand all
678 >>> d = { 'x': 1, 'y': 2 } 673 >>> d = { 'x': 1, 'y': 2 }
679 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) 674 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items())
680 [('x', 1), ('y', 3), ('z', 4)] 675 [('x', 1), ('y', 3), ('z', 4)]
681 >>> sorted(d.items()) 676 >>> sorted(d.items())
682 [('x', 1), ('y', 2)] 677 [('x', 1), ('y', 2)]
683 """ 678 """
684 679
685 d = copy.copy(d) 680 d = copy.copy(d)
686 d.update(updates) 681 d.update(updates)
687 return d 682 return d
OLDNEW
« no previous file with comments | « no previous file | recipe_engine/run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698