| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Tool to interact with recipe repositories. | 6 """Tool to interact with recipe repositories. |
| 7 | 7 |
| 8 This tool operates on the nearest ancestor directory containing an | 8 This tool operates on the nearest ancestor directory containing an |
| 9 infra/config/recipes.cfg. | 9 infra/config/recipes.cfg. |
| 10 """ | 10 """ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 universe_view = loader.UniverseView(universe, package_deps.root_package) | 57 universe_view = loader.UniverseView(universe, package_deps.root_package) |
| 58 | 58 |
| 59 # Prevent flakiness caused by stale pyc files. | 59 # Prevent flakiness caused by stale pyc files. |
| 60 package.cleanup_pyc(package_deps.root_package.recipes_dir) | 60 package.cleanup_pyc(package_deps.root_package.recipes_dir) |
| 61 | 61 |
| 62 simulation_test.main( | 62 simulation_test.main( |
| 63 universe_view, args=json.loads(args.args), | 63 universe_view, args=json.loads(args.args), |
| 64 engine_flags=op_args.engine_flags) | 64 engine_flags=op_args.engine_flags) |
| 65 | 65 |
| 66 | 66 |
| 67 def test(package_deps, args, op_args): |
| 68 try: |
| 69 from recipe_engine import test |
| 70 except ImportError: |
| 71 logging.error( |
| 72 'Error while importing testing libraries. You may be missing the pip' |
| 73 ' package "coverage". Install it, or use the --use-bootstrap command' |
| 74 ' line argument when calling into the recipe engine, which will install' |
| 75 ' it for you.') |
| 76 raise |
| 77 |
| 78 from recipe_engine import loader |
| 79 from recipe_engine import package |
| 80 |
| 81 _, config_file = get_package_config(args) |
| 82 universe = loader.RecipeUniverse(package_deps, config_file) |
| 83 universe_view = loader.UniverseView(universe, package_deps.root_package) |
| 84 |
| 85 # Prevent flakiness caused by stale pyc files. |
| 86 package.cleanup_pyc(package_deps.root_package.recipes_dir) |
| 87 |
| 88 return test.main( |
| 89 universe_view, raw_args=args.args, |
| 90 engine_flags=op_args.engine_flags) |
| 91 |
| 92 |
| 67 def lint(package_deps, args): | 93 def lint(package_deps, args): |
| 68 from recipe_engine import lint_test | 94 from recipe_engine import lint_test |
| 69 from recipe_engine import loader | 95 from recipe_engine import loader |
| 70 | 96 |
| 71 _, config_file = get_package_config(args) | 97 _, config_file = get_package_config(args) |
| 72 universe = loader.RecipeUniverse(package_deps, config_file) | 98 universe = loader.RecipeUniverse(package_deps, config_file) |
| 73 universe_view = loader.UniverseView(universe, package_deps.root_package) | 99 universe_view = loader.UniverseView(universe, package_deps.root_package) |
| 74 | 100 |
| 75 lint_test.main(universe_view, args.whitelist or []) | 101 lint_test.main(universe_view, args.whitelist or []) |
| 76 | 102 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 'fetch', | 448 'fetch', |
| 423 description='Fetch and update dependencies.') | 449 description='Fetch and update dependencies.') |
| 424 fetch_p.set_defaults(command='fetch') | 450 fetch_p.set_defaults(command='fetch') |
| 425 | 451 |
| 426 simulation_test_p = subp.add_parser( | 452 simulation_test_p = subp.add_parser( |
| 427 'simulation_test', | 453 'simulation_test', |
| 428 description='Generate or check expectations by simulation') | 454 description='Generate or check expectations by simulation') |
| 429 simulation_test_p.set_defaults(command='simulation_test') | 455 simulation_test_p.set_defaults(command='simulation_test') |
| 430 simulation_test_p.add_argument('args') | 456 simulation_test_p.add_argument('args') |
| 431 | 457 |
| 458 test_p = subp.add_parser( |
| 459 'test', |
| 460 description='Generate or check expectations by simulation (EXPERIMENTAL)') |
| 461 test_p.set_defaults(command='test') |
| 462 test_p.add_argument('args', nargs=argparse.REMAINDER) |
| 463 |
| 432 lint_p = subp.add_parser( | 464 lint_p = subp.add_parser( |
| 433 'lint', | 465 'lint', |
| 434 description='Check recipes for stylistic and hygenic issues') | 466 description='Check recipes for stylistic and hygenic issues') |
| 435 lint_p.set_defaults(command='lint') | 467 lint_p.set_defaults(command='lint') |
| 436 | 468 |
| 437 lint_p.add_argument( | 469 lint_p.add_argument( |
| 438 '--whitelist', '-w', action='append', | 470 '--whitelist', '-w', action='append', |
| 439 help='A regexp matching module names to add to the default whitelist. ' | 471 help='A regexp matching module names to add to the default whitelist. ' |
| 440 'Use multiple times to add multiple patterns,') | 472 'Use multiple times to add multiple patterns,') |
| 441 | 473 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 bootstrap_cache_path = os.path.join(ROOT_DIR, '.bootstrap_cache') | 633 bootstrap_cache_path = os.path.join(ROOT_DIR, '.bootstrap_cache') |
| 602 | 634 |
| 603 logging.debug('Installing bootstrap environment into: %s', env_path) | 635 logging.debug('Installing bootstrap environment into: %s', env_path) |
| 604 subprocess.check_call( | 636 subprocess.check_call( |
| 605 [ | 637 [ |
| 606 sys.executable, | 638 sys.executable, |
| 607 os.path.join(ROOT_DIR, 'bootstrap', 'bootstrap.py'), | 639 os.path.join(ROOT_DIR, 'bootstrap', 'bootstrap.py'), |
| 608 '--deps-file', os.path.join(ROOT_DIR, 'bootstrap', 'deps.pyl'), | 640 '--deps-file', os.path.join(ROOT_DIR, 'bootstrap', 'deps.pyl'), |
| 609 '--cache-root', bootstrap_cache_path, | 641 '--cache-root', bootstrap_cache_path, |
| 610 env_path, | 642 env_path, |
| 611 ], | 643 ] + ([] if args.verbose else ['--quiet']), |
| 612 cwd=ROOT_DIR) | 644 cwd=ROOT_DIR) |
| 613 | 645 |
| 614 # Mark that we're bootstrapping, so the next invocation falls through to | 646 # Mark that we're bootstrapping, so the next invocation falls through to |
| 615 # standard recipe operation. | 647 # standard recipe operation. |
| 616 os.environ['RECIPES_RUN_BOOTSTRAP'] = '1' | 648 os.environ['RECIPES_RUN_BOOTSTRAP'] = '1' |
| 617 args = sys.argv | 649 args = sys.argv |
| 618 return subprocess.call( | 650 return subprocess.call( |
| 619 [ | 651 [ |
| 620 os.path.join(env_path, 'bin', 'python'), | 652 os.path.join(env_path, 'bin', 'python'), |
| 621 os.path.join(ROOT_DIR, 'recipes.py'), | 653 os.path.join(ROOT_DIR, 'recipes.py'), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 # A git checkout failed somewhere. Return 2, which is the sign that this is | 692 # A git checkout failed somewhere. Return 2, which is the sign that this is |
| 661 # an infra failure, rather than a test failure. | 693 # an infra failure, rather than a test failure. |
| 662 return 2 | 694 return 2 |
| 663 | 695 |
| 664 if args.command == 'fetch': | 696 if args.command == 'fetch': |
| 665 # We already did everything in the create() call above. | 697 # We already did everything in the create() call above. |
| 666 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' | 698 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' |
| 667 return 0 | 699 return 0 |
| 668 if args.command == 'simulation_test': | 700 if args.command == 'simulation_test': |
| 669 return simulation_test(package_deps, args, op_args) | 701 return simulation_test(package_deps, args, op_args) |
| 702 elif args.command == 'test': |
| 703 return test(package_deps, args, op_args) |
| 670 elif args.command == 'bundle': | 704 elif args.command == 'bundle': |
| 671 return bundle(package_deps, args) | 705 return bundle(package_deps, args) |
| 672 elif args.command == 'lint': | 706 elif args.command == 'lint': |
| 673 return lint(package_deps, args) | 707 return lint(package_deps, args) |
| 674 elif args.command == 'run': | 708 elif args.command == 'run': |
| 675 return run(package_deps, args, op_args) | 709 return run(package_deps, args, op_args) |
| 676 elif args.command == 'autoroll': | 710 elif args.command == 'autoroll': |
| 677 return autoroll(args) | 711 return autoroll(args) |
| 678 elif args.command == 'depgraph': | 712 elif args.command == 'depgraph': |
| 679 return depgraph(package_deps, args) | 713 return depgraph(package_deps, args) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 | 747 |
| 714 if not isinstance(ret, int): | 748 if not isinstance(ret, int): |
| 715 if ret is None: | 749 if ret is None: |
| 716 ret = 0 | 750 ret = 0 |
| 717 else: | 751 else: |
| 718 print >> sys.stderr, ret | 752 print >> sys.stderr, ret |
| 719 ret = 1 | 753 ret = 1 |
| 720 sys.stdout.flush() | 754 sys.stdout.flush() |
| 721 sys.stderr.flush() | 755 sys.stderr.flush() |
| 722 os._exit(ret) | 756 os._exit(ret) |
| OLD | NEW |