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

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: Rebase and stuff. Created 4 years, 5 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') | recipe_engine/run.py » ('J')
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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return False 335 return False
336 return self._proto_file == other._proto_file 336 return self._proto_file == other._proto_file
337 337
338 338
339 class Package(object): 339 class Package(object):
340 """Package represents a loaded package, and contains path and dependency 340 """Package represents a loaded package, and contains path and dependency
341 information. 341 information.
342 342
343 This is accessed by loader.py through RecipeDeps.get_package. 343 This is accessed by loader.py through RecipeDeps.get_package.
344 """ 344 """
345 def __init__(self, name, repo_spec, deps, repo_root, recipes_dir): 345 def __init__(self, name, repo_spec, deps, repo_root, relative_recipes_dir):
346 self.name = name 346 self.name = name
347 self.repo_spec = repo_spec 347 self.repo_spec = repo_spec
348 self.deps = deps 348 self.deps = deps
349 self.repo_root = repo_root 349 self.repo_root = repo_root
350 self.recipes_dir = recipes_dir 350 self.relative_recipes_dir = relative_recipes_dir
351 351
352 def __repr__(self): 352 def __repr__(self):
353 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % ( 353 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % (
354 self.name, self.repo_spec, self.deps, self.recipes_dir) 354 self.name, self.repo_spec, self.deps, self.recipes_dir)
355 355
356 @property 356 @property
357 def recipes_dir(self):
358 return os.path.join(self.repo_root, self.relative_recipes_dir)
359
360 @property
357 def recipe_dirs(self): 361 def recipe_dirs(self):
358 return [os.path.join(self.recipes_dir, 'recipes')] 362 return [os.path.join(self.recipes_dir, 'recipes')]
359 363
360 @property 364 @property
361 def module_dirs(self): 365 def module_dirs(self):
362 return [os.path.join(self.recipes_dir, 'recipe_modules')] 366 return [os.path.join(self.recipes_dir, 'recipe_modules')]
363 367
364 def find_dep(self, dep_name): 368 def find_dep(self, dep_name):
365 if dep_name == self.name: 369 if dep_name == self.name:
366 return self 370 return self
367 371
368 assert dep_name in self.deps, ( 372 assert dep_name in self.deps, (
369 '%s does not exist or is not declared as a dependency of %s' % ( 373 '%s does not exist or is not declared as a dependency of %s' % (
370 dep_name, self.name)) 374 dep_name, self.name))
371 return self.deps[dep_name] 375 return self.deps[dep_name]
372 376
373 def module_path(self, module_name): 377 def module_path(self, module_name):
374 return os.path.join(self.recipes_dir, 'recipe_modules', module_name) 378 return os.path.join(self.recipes_dir, 'recipe_modules', module_name)
375 379
376 def loop_over_recipe_modules():
377 for path in self.module_dirs:
378 if os.path.isdir(path):
379 for item in os.listdir(path):
380 subpath = os.path.join(path, item)
381 if _is_recipe_module_dir(subpath):
382 yield subpath
383
384 def __repr__(self): 380 def __repr__(self):
385 return 'Package(%r, %r, %r, %r)' % ( 381 return 'Package(%r, %r, %r, %r)' % (
386 self.name, self.repo_spec, self.deps, self.recipe_dirs) 382 self.name, self.repo_spec, self.deps, self.recipe_dirs)
387 383
388 def __str__(self): 384 def __str__(self):
389 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys()) 385 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys())
390 386
391 387
392 class RollCandidate(object): 388 class RollCandidate(object):
393 """RollCandidate represents a recipe roll candidate, i.e. updates 389 """RollCandidate represents a recipe roll candidate, i.e. updates
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 self._packages[project_id] = None 623 self._packages[project_id] = None
628 624
629 deps = {} 625 deps = {}
630 for dep, dep_repo in sorted(package_spec.deps.items()): 626 for dep, dep_repo in sorted(package_spec.deps.items()):
631 dep_repo = self._overrides.get(dep, dep_repo) 627 dep_repo = self._overrides.get(dep, dep_repo)
632 deps[dep] = self._create_package(dep_repo) 628 deps[dep] = self._create_package(dep_repo)
633 629
634 package = Package( 630 package = Package(
635 project_id, repo_spec, deps, 631 project_id, repo_spec, deps,
636 repo_spec.repo_root(self._context), 632 repo_spec.repo_root(self._context),
637 os.path.join(repo_spec.repo_root(self._context), 633 package_spec.recipes_path)
638 package_spec.recipes_path))
639 634
640 self._packages[project_id] = package 635 self._packages[project_id] = package
641 return package 636 return package
642 637
643 # TODO(luqui): Remove this, so all accesses to packages are done 638 # TODO(luqui): Remove this, so all accesses to packages are done
644 # via other packages with properly scoped deps. 639 # via other packages with properly scoped deps.
645 def get_package(self, package_id): 640 def get_package(self, package_id):
646 return self._packages[package_id] 641 return self._packages[package_id]
647 642
648 @property 643 @property
(...skipping 12 matching lines...) Expand all
661 >>> d = { 'x': 1, 'y': 2 } 656 >>> d = { 'x': 1, 'y': 2 }
662 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) 657 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items())
663 [('x', 1), ('y', 3), ('z', 4)] 658 [('x', 1), ('y', 3), ('z', 4)]
664 >>> sorted(d.items()) 659 >>> sorted(d.items())
665 [('x', 1), ('y', 2)] 660 [('x', 1), ('y', 2)]
666 """ 661 """
667 662
668 d = copy.copy(d) 663 d = copy.copy(d)
669 d.update(updates) 664 d.update(updates)
670 return d 665 return d
OLDNEW
« no previous file with comments | « no previous file | recipe_engine/run.py » ('j') | recipe_engine/run.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698