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

Side by Side Diff: recipe_engine/config_types.py

Issue 1344583003: Recipe package system. (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Recompiled proto Created 5 years, 3 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 | « recipe_engine/config.py ('k') | recipe_engine/doc.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 2013-2015 The Chromium Authors. All rights reserved. 1 # Copyright 2013-2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import abc 5 import abc
6 import re 6 import re
7 7
8 from collections import namedtuple 8 from collections import namedtuple
9 9
10 from infra.libs import infra_types 10 from . import types
11
12 11
13 RECIPE_MODULE_PREFIX = 'RECIPE_MODULES' 12 RECIPE_MODULE_PREFIX = 'RECIPE_MODULES'
14 13
15 14
16 def ResetTostringFns(): 15 def ResetTostringFns():
17 RecipeConfigType._TOSTRING_MAP.clear() # pylint: disable=W0212 16 RecipeConfigType._TOSTRING_MAP.clear() # pylint: disable=W0212
18 17
19 18
20 def json_fixup(obj): 19 def json_fixup(obj):
21 if isinstance(obj, RecipeConfigType): 20 if isinstance(obj, RecipeConfigType):
22 return str(obj) 21 return str(obj)
23 thawed = infra_types.thaw(obj) 22 if isinstance(obj, types.FrozenDict):
24 if thawed is not obj: # i.e. it was a frozen type 23 return dict(obj)
25 return thawed
26 raise TypeError("%r is not JSON serializable" % obj) 24 raise TypeError("%r is not JSON serializable" % obj)
27 25
28 26
29 class RecipeConfigType(object): 27 class RecipeConfigType(object):
30 """Base class for custom Recipe config types, intended to be subclassed. 28 """Base class for custom Recipe config types, intended to be subclassed.
31 29
32 RecipeConfigTypes are meant to be PURE data. There should be no dependency on 30 RecipeConfigTypes are meant to be PURE data. There should be no dependency on
33 any external systems (i.e. no importing sys, os, etc.). 31 any external systems (i.e. no importing sys, os, etc.).
34 32
35 The subclasses should override default_tostring_fn. This method should 33 The subclasses should override default_tostring_fn. This method should
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return child.pieces[:len(self.pieces)] == self.pieces 153 return child.pieces[:len(self.pieces)] == self.pieces
156 154
157 def default_tostring_fn(self): 155 def default_tostring_fn(self):
158 suffix = '' 156 suffix = ''
159 if self.platform_ext: 157 if self.platform_ext:
160 suffix = ', platform_ext=%r' % (self.platform_ext,) 158 suffix = ', platform_ext=%r' % (self.platform_ext,)
161 pieces = '' 159 pieces = ''
162 if self.pieces: 160 if self.pieces:
163 pieces = ', ' + (', '.join(map(repr, self.pieces))) 161 pieces = ', ' + (', '.join(map(repr, self.pieces)))
164 return 'Path(\'%s\'%s%s)' % (self.base, pieces, suffix) 162 return 'Path(\'%s\'%s%s)' % (self.base, pieces, suffix)
OLDNEW
« no previous file with comments | « recipe_engine/config.py ('k') | recipe_engine/doc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698