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

Side by Side Diff: recipe_engine/recipe_api.py

Issue 2512253002: Add name, package_repo_resource and resource support to recipe scripts. (Closed)
Patch Set: Fix bug, add additional test Created 4 years, 1 month 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
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 from __future__ import absolute_import 5 from __future__ import absolute_import
6 import contextlib 6 import contextlib
7 import collections 7 import collections
8 import copy 8 import copy
9 import keyword 9 import keyword
10 import re 10 import re
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 """Note: Injected dependencies are NOT available in __init__().""" 640 """Note: Injected dependencies are NOT available in __init__()."""
641 super(RecipeApiPlain, self).__init__() 641 super(RecipeApiPlain, self).__init__()
642 642
643 self._module = module 643 self._module = module
644 644
645 assert isinstance(test_data, (ModuleTestData, DisabledTestData)) 645 assert isinstance(test_data, (ModuleTestData, DisabledTestData))
646 self._test_data = test_data 646 self._test_data = test_data
647 647
648 # If we're the 'root' api, inject directly into 'self'. 648 # If we're the 'root' api, inject directly into 'self'.
649 # Otherwise inject into 'self.m' 649 # Otherwise inject into 'self.m'
650 self.m = self if module is None else ModuleInjectionSite(self) 650 if not isinstance(module, types.ModuleType):
651 self.m = self
652 else:
653 self.m = ModuleInjectionSite(self)
iannucci 2016/11/19 00:15:32 this is really dumb, but it's what caused the erro
651 654
652 # If our module has a test api, it gets injected here. 655 # If our module has a test api, it gets injected here.
653 self.test_api = None 656 self.test_api = None
654 657
655 # Config goes here. 658 # Config goes here.
656 self.c = None 659 self.c = None
657 660
658 def initialize(self): 661 def initialize(self):
659 """ 662 """
660 Initializes the recipe module after it has been instantiated with all 663 Initializes the recipe module after it has been instantiated with all
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 config_object or self.c, optional=optional) 731 config_object or self.c, optional=optional)
729 732
730 def resource(self, *path): 733 def resource(self, *path):
731 """Returns path to a file under <recipe module>/resources/ directory. 734 """Returns path to a file under <recipe module>/resources/ directory.
732 735
733 Args: 736 Args:
734 path: path relative to module's resources/ directory. 737 path: path relative to module's resources/ directory.
735 """ 738 """
736 # TODO(vadimsh): Verify that file exists. Including a case like: 739 # TODO(vadimsh): Verify that file exists. Including a case like:
737 # module.resource('dir').join('subdir', 'file.py') 740 # module.resource('dir').join('subdir', 'file.py')
738 return self._module.MODULE_DIRECTORY.join('resources', *path) 741 return self._module.RESOURCE_DIRECTORY.join(*path)
739 742
740 def package_repo_resource(self, *path): 743 def package_repo_resource(self, *path):
741 """Returns a resource path, where path is relative to the root of 744 """Returns a resource path, where path is relative to the root of
742 the package repo where this module is defined. 745 the package repo where this module is defined.
743 """ 746 """
744 return self._module.PACKAGE_REPO_ROOT.join(*path) 747 return self._module.PACKAGE_REPO_ROOT.join(*path)
745 748
746 @property 749 @property
747 def name(self): 750 def name(self):
748 return self._module.NAME 751 return self._module.NAME
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 """ 931 """
929 Gets the BoundProperty version of this Property. Requires a name. 932 Gets the BoundProperty version of this Property. Requires a name.
930 """ 933 """
931 return BoundProperty( 934 return BoundProperty(
932 self._default, self.help, self.kind, name, property_type, module, 935 self._default, self.help, self.kind, name, property_type, module,
933 self.param_name) 936 self.param_name)
934 937
935 class UndefinedPropertyException(TypeError): 938 class UndefinedPropertyException(TypeError):
936 pass 939 pass
937 940
OLDNEW
« recipe_engine/loader.py ('K') | « recipe_engine/loader.py ('k') | recipe_engine/run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698