Chromium Code Reviews| 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 """Utilities for testing with real repos (e.g. git).""" | 5 """Utilities for testing with real repos (e.g. git).""" |
| 6 | 6 |
| 7 | 7 |
| 8 import contextlib | 8 import contextlib |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 subprocess.check_call(['git', 'branch', '-f', 'origin/master', rev]) | 170 subprocess.check_call(['git', 'branch', '-f', 'origin/master', rev]) |
| 171 return { | 171 return { |
| 172 'root': repo['root'], | 172 'root': repo['root'], |
| 173 'revision': rev, | 173 'revision': rev, |
| 174 'spec': repo['spec'], | 174 'spec': repo['spec'], |
| 175 'author_name': author_name, | 175 'author_name': author_name, |
| 176 'author_email': author_email, | 176 'author_email': author_email, |
| 177 'message': message, | 177 'message': message, |
| 178 } | 178 } |
| 179 | 179 |
| 180 def train_recipes(self, repo, overrides=None): | |
|
iannucci
2017/01/31 18:22:54
docstring please
Paweł Hajdan Jr.
2017/01/31 18:30:54
Yup, done.
I just wasn't sure what you'd think ab
| |
| 181 if not overrides: | |
| 182 overrides = [] | |
| 183 with in_directory(repo['root']): | |
| 184 args = [ | |
| 185 sys.executable, self._recipe_tool, | |
| 186 '--package', os.path.join( | |
| 187 repo['root'], 'infra', 'config', 'recipes.cfg'), | |
| 188 ] | |
| 189 for repo, path in overrides: | |
| 190 args.extend(['-O', '%s=%s' % (repo, path)]) | |
| 191 args.extend([ | |
| 192 'simulation_test', | |
| 193 'train', | |
| 194 ]) | |
| 195 subprocess.check_output(args, stderr=subprocess.STDOUT) | |
| 196 | |
| 180 def update_recipe(self, repo, name, deps, calls): | 197 def update_recipe(self, repo, name, deps, calls): |
| 181 """Updates or creates a recipe in given repo. | 198 """Updates or creates a recipe in given repo. |
| 182 Commits the change. | 199 Commits the change. |
| 183 | 200 |
| 184 Arguments: | 201 Arguments: |
| 185 repo(dict): one of the repos returned by |repo_setup| | 202 repo(dict): one of the repos returned by |repo_setup| |
| 186 name(str): name of the recipe (without .py) | 203 name(str): name of the recipe (without .py) |
| 187 deps(iterable(str)): list of recipe dependencies (DEPS) | 204 deps(iterable(str)): list of recipe dependencies (DEPS) |
| 188 calls(iterable((str, str))): list of calls to recipe module | 205 calls(iterable((str, str))): list of calls to recipe module |
| 189 methods to make in the recipe; first element of the tuple | 206 methods to make in the recipe; first element of the tuple |
| 190 is the module name, and second is the method name | 207 is the module name, and second is the method name |
| 191 | 208 |
| 192 """ | 209 """ |
| 193 with in_directory(repo['root']): | 210 with in_directory(repo['root']): |
| 194 recipes_dir = 'recipes' | 211 recipes_dir = 'recipes' |
| 195 if not os.path.exists(recipes_dir): | 212 if not os.path.exists(recipes_dir): |
| 196 os.makedirs(recipes_dir) | 213 os.makedirs(recipes_dir) |
| 197 with open(os.path.join(recipes_dir, '%s.py' % name), 'w') as f: | 214 with open(os.path.join(recipes_dir, '%s.py' % name), 'w') as f: |
| 198 f.write('\n'.join([ | 215 f.write('\n'.join([ |
| 199 'DEPS = %r' % deps, | 216 'DEPS = %r' % deps, |
| 200 '', | 217 '', |
| 201 'def RunSteps(api):', | 218 'def RunSteps(api):', |
| 202 ] + [' api.%s.%s()' % c for c in calls] + [ | 219 ] + [' api.%s.%s()' % c for c in calls] + [ |
| 203 '', | 220 '', |
| 204 'def GenTests(api):', | 221 'def GenTests(api):', |
| 205 ' yield api.test("basic")', | 222 ' yield api.test("basic")', |
| 206 ])) | 223 ])) |
| 207 | 224 |
| 208 subprocess.check_output([ | 225 self.train_recipes(repo) |
| 209 sys.executable, self._recipe_tool, | |
| 210 '--package', os.path.join( | |
| 211 repo['root'], 'infra', 'config', 'recipes.cfg'), | |
| 212 'simulation_test', | |
| 213 'train', | |
| 214 ]) | |
| 215 | 226 |
| 216 subprocess.check_call( | 227 subprocess.check_call( |
| 217 ['git', 'add', os.path.join(recipes_dir, '%s.py' % name)]) | 228 ['git', 'add', os.path.join(recipes_dir, '%s.py' % name)]) |
| 218 subprocess.check_call( | 229 subprocess.check_call( |
| 219 ['git', 'add', os.path.join(recipes_dir, '%s.expected' % name)]) | 230 ['git', 'add', os.path.join(recipes_dir, '%s.expected' % name)]) |
| 220 return self.commit_in_repo(repo, message='recipe update') | 231 return self.commit_in_repo(repo, message='recipe update') |
| 221 | 232 |
| 222 def update_recipe_module(self, repo, name, methods): | 233 def update_recipe_module(self, repo, name, methods): |
| 223 """Updates or creates a recipe module in given repo. | 234 """Updates or creates a recipe module in given repo. |
| 224 Commits the change. | 235 Commits the change. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 message = ' '.join( | 280 message = ' '.join( |
| 270 ['update %r recipe_module: ' % name] + | 281 ['update %r recipe_module: ' % name] + |
| 271 ['%s(%s)' % t for t in methods.iteritems()] | 282 ['%s(%s)' % t for t in methods.iteritems()] |
| 272 ) | 283 ) |
| 273 return self.commit_in_repo(repo, message) | 284 return self.commit_in_repo(repo, message) |
| 274 | 285 |
| 275 def reset_repo(self, repo, revision): | 286 def reset_repo(self, repo, revision): |
| 276 """Resets repo contents to given revision.""" | 287 """Resets repo contents to given revision.""" |
| 277 with in_directory(repo['root']): | 288 with in_directory(repo['root']): |
| 278 subprocess.check_output(['git', 'reset', '--hard', revision]) | 289 subprocess.check_output(['git', 'reset', '--hard', revision]) |
| OLD | NEW |