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

Side by Side Diff: recipe_modules/path/api.py

Issue 1925653002: recipe engine: require all path bases to be classes (Closed) Base URL: https://github.com/luci/recipes-py.git@master
Patch Set: rebase Created 4 years, 7 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_types.py ('k') | recipe_modules/path/example.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 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 functools 5 import functools
6 import os 6 import os
7 import sys 7 import sys
8 import tempfile 8 import tempfile
9 9
10 from recipe_engine import recipe_api 10 from recipe_engine import recipe_api
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 def __setitem__(self, pathname, path): 184 def __setitem__(self, pathname, path):
185 assert isinstance(path, config_types.Path), ( 185 assert isinstance(path, config_types.Path), (
186 'Setting dynamic path to something other than a Path: %r' % path) 186 'Setting dynamic path to something other than a Path: %r' % path)
187 assert pathname in self.c.dynamic_paths, ( 187 assert pathname in self.c.dynamic_paths, (
188 'Must declare dynamic path (%r) in config before setting it.' % path) 188 'Must declare dynamic path (%r) in config before setting it.' % path)
189 assert isinstance(path.base, config_types.BasePath), ( 189 assert isinstance(path.base, config_types.BasePath), (
190 'Dynamic path values must be based on a base_path' % path.base) 190 'Dynamic path values must be based on a base_path' % path.base)
191 self.c.dynamic_paths[pathname] = path 191 self.c.dynamic_paths[pathname] = path
192 192
193 def __getitem__(self, name): 193 def __getitem__(self, name):
194 if name in self.c.dynamic_paths: 194 if name in self.c.base_paths or name in self.c.dynamic_paths:
195 r = self.c.dynamic_paths[name]
196 assert r is not None, ('Tried to get dynamic path %s but it has not been '
197 'set yet.' % name)
198 return r
199 if name in self.c.base_paths:
200 return config_types.Path(config_types.NamedBasePath(name)) 195 return config_types.Path(config_types.NamedBasePath(name))
201 raise KeyError('Unknown path: %s' % name) # pragma: no cover 196 raise KeyError('Unknown path: %s' % name) # pragma: no cover
202 197
203 def __getattr__(self, name): 198 def __getattr__(self, name):
204 # retrieve os.path attributes 199 # retrieve os.path attributes
205 if name in self.OK_ATTRS: 200 if name in self.OK_ATTRS:
206 return getattr(self._path_mod, name) 201 return getattr(self._path_mod, name)
207 if name in self.FILTER_METHODS: 202 if name in self.FILTER_METHODS:
208 return string_filter(getattr(self._path_mod, name)) 203 return string_filter(getattr(self._path_mod, name))
209 raise AttributeError("'%s' object has no attribute '%s'" % 204 raise AttributeError("'%s' object has no attribute '%s'" %
210 (self._path_mod, name)) # pragma: no cover 205 (self._path_mod, name)) # pragma: no cover
211 206
212 def __dir__(self): # pragma: no cover 207 def __dir__(self): # pragma: no cover
213 # Used for helping out show_me_the_modules.py 208 # Used for helping out show_me_the_modules.py
214 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS) 209 return self.__dict__.keys() + list(self.OK_ATTRS + self.FILTER_METHODS)
OLDNEW
« no previous file with comments | « recipe_engine/config_types.py ('k') | recipe_modules/path/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698