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

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: LICENSE and small things. Created 4 years, 8 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 Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # 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 functools 9 import functools
10 import itertools 10 import itertools
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return False 347 return False
348 return self._proto_file == other._proto_file 348 return self._proto_file == other._proto_file
349 349
350 350
351 class Package(object): 351 class Package(object):
352 """Package represents a loaded package, and contains path and dependency 352 """Package represents a loaded package, and contains path and dependency
353 information. 353 information.
354 354
355 This is accessed by loader.py through RecipeDeps.get_package. 355 This is accessed by loader.py through RecipeDeps.get_package.
356 """ 356 """
357 def __init__(self, name, repo_spec, deps, repo_root, recipes_dir): 357 def __init__(self, name, repo_spec, deps, repo_root, relative_recipes_dir):
358 self.name = name 358 self.name = name
359 self.repo_spec = repo_spec 359 self.repo_spec = repo_spec
360 self.deps = deps 360 self.deps = deps
361 self.repo_root = repo_root 361 self.repo_root = repo_root
362 self.recipes_dir = recipes_dir 362 self.relative_recipes_dir = relative_recipes_dir
363 363
364 def __repr__(self): 364 def __repr__(self):
365 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % ( 365 return '<Package(name=%r,repo_spec=%r,deps=%r,recipes_dir=%r)>' % (
366 self.name, self.repo_spec, self.deps, self.recipes_dir) 366 self.name, self.repo_spec, self.deps, self.recipes_dir)
367 367
368 @property 368 @property
369 def recipes_dir(self):
370 return os.path.join(self.repo_root, self.relative_recipes_dir)
371
372 @property
369 def recipe_dirs(self): 373 def recipe_dirs(self):
370 return [os.path.join(self.recipes_dir, 'recipes')] 374 return [os.path.join(self.recipes_dir, 'recipes')]
371 375
372 @property 376 @property
373 def module_dirs(self): 377 def module_dirs(self):
374 return [os.path.join(self.recipes_dir, 'recipe_modules')] 378 return [os.path.join(self.recipes_dir, 'recipe_modules')]
375 379
376 def find_dep(self, dep_name): 380 def find_dep(self, dep_name):
377 if dep_name == self.name: 381 if dep_name == self.name:
378 return self 382 return self
379 383
380 assert dep_name in self.deps, ( 384 assert dep_name in self.deps, (
381 '%s does not exist or is not declared as a dependency of %s' % ( 385 '%s does not exist or is not declared as a dependency of %s' % (
382 dep_name, self.name)) 386 dep_name, self.name))
383 return self.deps[dep_name] 387 return self.deps[dep_name]
384 388
385 def module_path(self, module_name): 389 def module_path(self, module_name):
386 return os.path.join(self.recipes_dir, 'recipe_modules', module_name) 390 return os.path.join(self.recipes_dir, 'recipe_modules', module_name)
387 391
388 def loop_over_recipe_modules():
martiniss 2016/04/06 00:27:43 Derp.
389 for path in self.module_dirs:
390 if os.path.isdir(path):
391 for item in os.listdir(path):
392 subpath = os.path.join(path, item)
393 if _is_recipe_module_dir(subpath):
394 yield subpath
395
396 def __repr__(self): 392 def __repr__(self):
397 return 'Package(%r, %r, %r, %r)' % ( 393 return 'Package(%r, %r, %r, %r)' % (
398 self.name, self.repo_spec, self.deps, self.recipe_dirs) 394 self.name, self.repo_spec, self.deps, self.recipe_dirs)
399 395
400 def __str__(self): 396 def __str__(self):
401 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys()) 397 return 'Package %s, with dependencies %s' % (self.name, self.deps.keys())
402 398
403 399
404 class PackageSpec(object): 400 class PackageSpec(object):
405 API_VERSION = 1 401 API_VERSION = 1
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 (repo_spec, self._packages[project_id].repo_spec)) 613 (repo_spec, self._packages[project_id].repo_spec))
618 self._packages[project_id] = None 614 self._packages[project_id] = None
619 615
620 deps = {} 616 deps = {}
621 for dep, dep_repo in sorted(package_spec.deps.items()): 617 for dep, dep_repo in sorted(package_spec.deps.items()):
622 deps[dep] = self._create_package(dep_repo) 618 deps[dep] = self._create_package(dep_repo)
623 619
624 package = Package( 620 package = Package(
625 project_id, repo_spec, deps, 621 project_id, repo_spec, deps,
626 repo_spec.repo_root(self._context), 622 repo_spec.repo_root(self._context),
627 os.path.join(repo_spec.repo_root(self._context), 623 package_spec.recipes_path)
628 package_spec.recipes_path))
629 624
630 self._packages[project_id] = package 625 self._packages[project_id] = package
631 return package 626 return package
632 627
633 # TODO(luqui): Remove this, so all accesses to packages are done 628 # TODO(luqui): Remove this, so all accesses to packages are done
634 # via other packages with properly scoped deps. 629 # via other packages with properly scoped deps.
635 def get_package(self, package_id): 630 def get_package(self, package_id):
636 return self._packages[package_id] 631 return self._packages[package_id]
637 632
638 @property 633 @property
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 >>> d = { 'x': 1, 'y': 2 } 708 >>> d = { 'x': 1, 'y': 2 }
714 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items()) 709 >>> sorted(_updated(d, { 'y': 3, 'z': 4 }).items())
715 [('x', 1), ('y', 3), ('z', 4)] 710 [('x', 1), ('y', 3), ('z', 4)]
716 >>> sorted(d.items()) 711 >>> sorted(d.items())
717 [('x', 1), ('y', 2)] 712 [('x', 1), ('y', 2)]
718 """ 713 """
719 714
720 d = copy.copy(d) 715 d = copy.copy(d)
721 d.update(updates) 716 d.update(updates)
722 return d 717 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