| 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 logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if bool: whether to generate examples/full.py covering the module | 287 if bool: whether to generate examples/full.py covering the module |
| 288 if iterable(str): which methods to cover in generated example | 288 if iterable(str): which methods to cover in generated example |
| 289 disable_strict_coverage(bool): whether to disable strict coverage | 289 disable_strict_coverage(bool): whether to disable strict coverage |
| 290 (http://crbug.com/693058) | 290 (http://crbug.com/693058) |
| 291 """ | 291 """ |
| 292 with in_directory(repo['root']): | 292 with in_directory(repo['root']): |
| 293 module_dir = os.path.join('recipe_modules', name) | 293 module_dir = os.path.join('recipe_modules', name) |
| 294 if not os.path.exists(module_dir): | 294 if not os.path.exists(module_dir): |
| 295 os.makedirs(module_dir) | 295 os.makedirs(module_dir) |
| 296 with open(os.path.join(module_dir, '__init__.py'), 'w') as f: | 296 with open(os.path.join(module_dir, '__init__.py'), 'w') as f: |
| 297 f.write('DEPS = []') | 297 f.write("DEPS = ['recipe_engine/step']") |
| 298 if disable_strict_coverage: | 298 if disable_strict_coverage: |
| 299 f.write('\nDISABLE_STRICT_COVERAGE = True') | 299 f.write('\nDISABLE_STRICT_COVERAGE = True') |
| 300 with open(os.path.join(module_dir, 'api.py'), 'w') as f: | 300 with open(os.path.join(module_dir, 'api.py'), 'w') as f: |
| 301 f.write('\n'.join([ | 301 f.write('\n'.join([ |
| 302 'from recipe_engine import recipe_api', | 302 'from recipe_engine import recipe_api', |
| 303 '', | 303 '', |
| 304 'class MyApi(recipe_api.RecipeApi):', | 304 'class MyApi(recipe_api.RecipeApi):', |
| 305 ' step_client = recipe_api.RequireClient(\'step\')', | 305 ' step_client = recipe_api.RequireClient(\'step\')', |
| 306 ] + [ | 306 ] + [ |
| 307 '\n'.join([ | 307 '\n'.join([ |
| 308 '', | 308 '', |
| 309 ' def %s(self):' % m_name, | 309 ' def %s(self):' % m_name, |
| 310 ' return self.step_client.run_step(%r)' % { | 310 ' return self.m.step(**%r)' % { |
| 311 'name': m_name, | 311 'name': m_name, |
| 312 'cmd': m_cmd, | 312 'cmd': m_cmd, |
| 313 'ok_ret': [0], | 313 'ok_ret': [0], |
| 314 'infra_step': False | 314 'infra_step': False |
| 315 }, | 315 }, |
| 316 '', | 316 '', |
| 317 ]) for m_name, m_cmd in methods.iteritems() | 317 ]) for m_name, m_cmd in methods.iteritems() |
| 318 ])) | 318 ])) |
| 319 | 319 |
| 320 examples_dir = os.path.join(module_dir, 'examples') | 320 examples_dir = os.path.join(module_dir, 'examples') |
| (...skipping 17 matching lines...) Expand all Loading... |
| 338 shutil.rmtree(examples_dir) | 338 shutil.rmtree(examples_dir) |
| 339 | 339 |
| 340 self.train_recipes(repo) | 340 self.train_recipes(repo) |
| 341 | 341 |
| 342 subprocess.check_call(['git', 'add', module_dir]) | 342 subprocess.check_call(['git', 'add', module_dir]) |
| 343 message = ' '.join( | 343 message = ' '.join( |
| 344 ['update %r recipe_module: ' % name] + | 344 ['update %r recipe_module: ' % name] + |
| 345 ['%s(%s)' % t for t in methods.iteritems()] | 345 ['%s(%s)' % t for t in methods.iteritems()] |
| 346 ) | 346 ) |
| 347 return self.commit_in_repo(repo, message) | 347 return self.commit_in_repo(repo, message) |
| OLD | NEW |