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

Side by Side Diff: recipe_engine/loader.py

Issue 2628523004: Allow module self-reference in loader (Closed)
Patch Set: typo Created 3 years, 11 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 | recipes/example/module_self_ref.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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,))
OLDNEW
« no previous file with comments | « no previous file | recipes/example/module_self_ref.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698