Chromium Code Reviews| 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 else: | |
| 245 recipe_path = os.path.join(module_dir, 'tests', recipe_name + '.py') | |
|
iannucci1
2017/04/11 20:06:27
let's just change this to have less magic, so the
Paweł Hajdan Jr.
2017/04/11 20:14:01
Done.
| |
| 244 else: | 246 else: |
| 245 recipe_path = os.path.join(self.package.recipe_dir, recipe)+".py" | 247 recipe_path = os.path.join(self.package.recipe_dir, recipe)+".py" |
| 246 | 248 |
| 247 if os.path.exists(recipe_path): | 249 if os.path.exists(recipe_path): |
| 248 return recipe_path | 250 return recipe_path |
| 249 | 251 |
| 250 raise NoSuchRecipe(recipe) | 252 raise NoSuchRecipe(recipe) |
| 251 | 253 |
| 252 def load_recipe(self, recipe, engine=None): | 254 def load_recipe(self, recipe, engine=None): |
| 253 """Given name of a recipe, loads and returns it as RecipeScript instance. | 255 """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'))] | 307 if not x.endswith(('.expected', '.resources'))] |
| 306 for file_name in (f for f in files if predicate(f)): | 308 for file_name in (f for f in files if predicate(f)): |
| 307 file_path = os.path.join(root, file_name) | 309 file_path = os.path.join(root, file_name) |
| 308 yield file_path | 310 yield file_path |
| 309 | 311 |
| 310 path = self.package.recipe_dir | 312 path = self.package.recipe_dir |
| 311 for recipe in scan_directory( | 313 for recipe in scan_directory( |
| 312 path, lambda f: f.endswith('.py') and f[0] != '_'): | 314 path, lambda f: f.endswith('.py') and f[0] != '_'): |
| 313 yield recipe, recipe[len(path)+1:-len('.py')] | 315 yield recipe, recipe[len(path)+1:-len('.py')] |
| 314 | 316 |
| 315 path = self.package.module_dir | 317 for module_name in self.loop_over_recipe_modules(): |
| 316 for recipe in scan_directory( | 318 module_dir = os.path.join(self.package.module_dir, module_name) |
| 317 path, lambda f: f.endswith('example.py')): | 319 |
| 318 module_name = os.path.dirname(recipe)[len(path)+1:] | 320 example_path = os.path.join(module_dir, 'example.py') |
| 319 yield recipe, '%s:example' % module_name | 321 if os.path.exists(example_path): |
| 322 yield example_path, '%s:example' % module_name | |
| 323 | |
| 324 test_dir = os.path.join(module_dir, 'tests') | |
| 325 if os.path.exists(test_dir): | |
| 326 for recipe in scan_directory(test_dir, lambda f: f.endswith('.py')): | |
| 327 yield recipe, '%s:%s' % ( | |
| 328 module_name, recipe[len(test_dir)+1:-len('.py')]) | |
| 320 | 329 |
| 321 def loop_over_recipe_modules(self): | 330 def loop_over_recipe_modules(self): |
| 322 """Yields the paths to all the modules that this view can see.""" | 331 """Yields the paths to all the modules that this view can see.""" |
| 323 path = self.package.module_dir | 332 path = self.package.module_dir |
| 324 if os.path.isdir(path): | 333 if os.path.isdir(path): |
| 325 for item in os.listdir(path): | 334 for item in os.listdir(path): |
| 326 subpath = os.path.join(path, item) | 335 subpath = os.path.join(path, item) |
| 327 if _is_recipe_module_dir(subpath): | 336 if _is_recipe_module_dir(subpath): |
| 328 yield os.path.basename(subpath) | 337 yield os.path.basename(subpath) |
| 329 | 338 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 for k,v in toplevel_deps.iteritems(): | 667 for k,v in toplevel_deps.iteritems(): |
| 659 setattr(api, k, mapper.instantiate(v)) | 668 setattr(api, k, mapper.instantiate(v)) |
| 660 return api | 669 return api |
| 661 | 670 |
| 662 | 671 |
| 663 def _resolve_requirement(req, engine): | 672 def _resolve_requirement(req, engine): |
| 664 if req._typ == 'client': | 673 if req._typ == 'client': |
| 665 return engine._get_client(req._name) | 674 return engine._get_client(req._name) |
| 666 else: | 675 else: |
| 667 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) | 676 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) |
| OLD | NEW |