| 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 contextlib | 6 import contextlib |
| 7 import imp | 7 import imp |
| 8 import inspect | 8 import inspect |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 } | 566 } |
| 567 prop_defs = mod.PROPERTIES | 567 prop_defs = mod.PROPERTIES |
| 568 mod_api = invoke_with_properties( | 568 mod_api = invoke_with_properties( |
| 569 mod.API, engine.properties, prop_defs, **kwargs) | 569 mod.API, engine.properties, prop_defs, **kwargs) |
| 570 mod_api.test_api = (getattr(mod, 'TEST_API', None) | 570 mod_api.test_api = (getattr(mod, 'TEST_API', None) |
| 571 or RecipeTestApi)(module=mod) | 571 or RecipeTestApi)(module=mod) |
| 572 for k, v in deps.iteritems(): | 572 for k, v in deps.iteritems(): |
| 573 setattr(mod_api.m, k, v) | 573 setattr(mod_api.m, k, v) |
| 574 setattr(mod_api.test_api.m, k, v.test_api) | 574 setattr(mod_api.test_api.m, k, v.test_api) |
| 575 | 575 |
| 576 # It is useful to have module's self-reference under .m . This allows |
| 577 # passing module's API to other objects within that module, still having |
| 578 # access to the module itself, along with all its dependencies. |
| 579 setattr(mod_api.m, mod.NAME, mod_api) |
| 580 |
| 576 # Replace class-level Requirements placeholders in the recipe API with | 581 # Replace class-level Requirements placeholders in the recipe API with |
| 577 # their instance-level real values. | 582 # their instance-level real values. |
| 578 map(lambda (k, v): setattr(mod_api, k, _resolve_requirement(v, engine)), | 583 map(lambda (k, v): setattr(mod_api, k, _resolve_requirement(v, engine)), |
| 579 ((k, v) for k, v in type(mod_api).__dict__.iteritems() | 584 ((k, v) for k, v in type(mod_api).__dict__.iteritems() |
| 580 if isinstance(v, _UnresolvedRequirement))) | 585 if isinstance(v, _UnresolvedRequirement))) |
| 581 | 586 |
| 582 mod_api.initialize() | 587 mod_api.initialize() |
| 583 return mod_api | 588 return mod_api |
| 584 | 589 |
| 585 mapper = DependencyMapper(instantiator) | 590 mapper = DependencyMapper(instantiator) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 for k,v in toplevel_deps.iteritems(): | 625 for k,v in toplevel_deps.iteritems(): |
| 621 setattr(api, k, mapper.instantiate(v)) | 626 setattr(api, k, mapper.instantiate(v)) |
| 622 return api | 627 return api |
| 623 | 628 |
| 624 | 629 |
| 625 def _resolve_requirement(req, engine): | 630 def _resolve_requirement(req, engine): |
| 626 if req._typ == 'client': | 631 if req._typ == 'client': |
| 627 return engine._get_client(req._name) | 632 return engine._get_client(req._name) |
| 628 else: | 633 else: |
| 629 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) | 634 raise ValueError('Unknown requirement type [%s]' % (req._typ,)) |
| OLD | NEW |