| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 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 collections | 5 import collections |
| 6 import imp | 6 import imp |
| 7 import inspect | 7 import inspect |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 228 } |
| 229 """ | 229 """ |
| 230 return { | 230 return { |
| 231 local_name: self.universe.load(pkg, name) | 231 local_name: self.universe.load(pkg, name) |
| 232 for local_name, (pkg, name) in self.normalize_deps_spec(spec).iteritems() | 232 for local_name, (pkg, name) in self.normalize_deps_spec(spec).iteritems() |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| 236 def find_recipe(self, recipe): | 236 def find_recipe(self, recipe): |
| 237 if ':' in recipe: | 237 if ':' in recipe: |
| 238 module_name, example = recipe.split(':') | 238 module_name, recipe_name = recipe.split(':') |
| 239 #TODO(martinis) change to example == 'example' ? Technically a bug... | 239 module_dir = os.path.join(self.package.module_dir, module_name) |
| 240 assert example.endswith('example') | 240 if _is_recipe_module_dir(module_dir): |
| 241 subpath = os.path.join(self.package.module_dir, module_name) | 241 if recipe_name.endswith('example'): |
| 242 if _is_recipe_module_dir(subpath): | 242 # TODO(martinis) change to example == 'example' ? Technically a bug... |
| 243 recipe_path = os.path.join(subpath, 'example.py') | 243 recipe_path = os.path.join(module_dir, 'example.py') |
| 244 elif recipe_name.startswith('tests/'): |
| 245 recipe_path = os.path.join( |
| 246 module_dir, 'tests', recipe_name[len('tests/'):] + '.py') |
| 247 else: |
| 248 raise NoSuchRecipe(recipe) |
| 244 else: | 249 else: |
| 245 recipe_path = os.path.join(self.package.recipe_dir, recipe)+".py" | 250 recipe_path = os.path.join(self.package.recipe_dir, recipe)+".py" |
| 246 | 251 |
| 247 if os.path.exists(recipe_path): | 252 if os.path.exists(recipe_path): |
| 248 return recipe_path | 253 return recipe_path |
| 249 | 254 |
| 250 raise NoSuchRecipe(recipe) | 255 raise NoSuchRecipe(recipe) |
| 251 | 256 |
| 252 def load_recipe(self, recipe, engine=None): | 257 def load_recipe(self, recipe, engine=None): |
| 253 """Given name of a recipe, loads and returns it as RecipeScript instance. | 258 """Given name of a recipe, loads and returns it as RecipeScript instance. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 if not x.endswith(('.expected', '.resources'))] | 310 if not x.endswith(('.expected', '.resources'))] |
| 306 for file_name in (f for f in files if predicate(f)): | 311 for file_name in (f for f in files if predicate(f)): |
| 307 file_path = os.path.join(root, file_name) | 312 file_path = os.path.join(root, file_name) |
| 308 yield file_path | 313 yield file_path |
| 309 | 314 |
| 310 path = self.package.recipe_dir | 315 path = self.package.recipe_dir |
| 311 for recipe in scan_directory( | 316 for recipe in scan_directory( |
| 312 path, lambda f: f.endswith('.py') and f[0] != '_'): | 317 path, lambda f: f.endswith('.py') and f[0] != '_'): |
| 313 yield recipe, recipe[len(path)+1:-len('.py')] | 318 yield recipe, recipe[len(path)+1:-len('.py')] |
| 314 | 319 |
| 315 path = self.package.module_dir | 320 for module_name in self.loop_over_recipe_modules(): |
| 316 for recipe in scan_directory( | 321 module_dir = os.path.join(self.package.module_dir, module_name) |
| 317 path, lambda f: f.endswith('example.py')): | 322 |
| 318 module_name = os.path.dirname(recipe)[len(path)+1:] | 323 example_path = os.path.join(module_dir, 'example.py') |
| 319 yield recipe, '%s:example' % module_name | 324 if os.path.exists(example_path): |
| 325 yield example_path, '%s:example' % module_name |
| 326 |
| 327 test_dir = os.path.join(module_dir, 'tests') |
| 328 if os.path.exists(test_dir): |
| 329 for recipe in scan_directory(test_dir, lambda f: f.endswith('.py')): |
| 330 yield recipe, '%s:tests/%s' % ( |
| 331 module_name, recipe[len(test_dir)+1:-len('.py')]) |
| 320 | 332 |
| 321 def loop_over_recipe_modules(self): | 333 def loop_over_recipe_modules(self): |
| 322 """Yields the paths to all the modules that this view can see.""" | 334 """Yields the paths to all the modules that this view can see.""" |
| 323 path = self.package.module_dir | 335 path = self.package.module_dir |
| 324 if os.path.isdir(path): | 336 if os.path.isdir(path): |
| 325 for item in os.listdir(path): | 337 for item in os.listdir(path): |
| 326 subpath = os.path.join(path, item) | 338 subpath = os.path.join(path, item) |
| 327 if _is_recipe_module_dir(subpath): | 339 if _is_recipe_module_dir(subpath): |
| 328 yield os.path.basename(subpath) | 340 yield os.path.basename(subpath) |
| 329 | 341 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 for k,v in toplevel_deps.iteritems(): | 670 for k,v in toplevel_deps.iteritems(): |
| 659 setattr(api, k, mapper.instantiate(v)) | 671 setattr(api, k, mapper.instantiate(v)) |
| 660 return api | 672 return api |
| 661 | 673 |
| 662 | 674 |
| 663 def _resolve_requirement(req, engine): | 675 def _resolve_requirement(req, engine): |
| 664 if req._typ == 'client': | 676 if req._typ == 'client': |
| 665 return engine._get_client(req._name) | 677 return engine._get_client(req._name) |
| 666 else: | 678 else: |
| 667 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) | 679 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) |
| OLD | NEW |