def list(): """Lists all addresses under the current build root subject to `--spec-excludes` constraints.""" build_root = get_buildroot() options, build_config = OptionsInitializer().setup() aliases = build_config.registered_aliases() symbol_table = {alias: Target for alias in aliases.target_types} object_table = aliases.objects def per_path_symbol_factory(path, global_symbols): per_path_symbols = {} symbols = global_symbols.copy() for alias, target_macro_factory in aliases.target_macro_factories.items( ): for target_type in target_macro_factory.target_types: symbols[ target_type] = lambda *args, **kwargs: per_path_symbols[ alias](*args, **kwargs) parse_context = ParseContext(rel_path=os.path.relpath( os.path.dirname(path), build_root), type_aliases=symbols) for alias, object_factory in aliases.context_aware_object_factories.items( ): per_path_symbols[alias] = object_factory(parse_context) for alias, target_macro_factory in aliases.target_macro_factories.items( ): target_macro = target_macro_factory.target_macro(parse_context) per_path_symbols[alias] = target_macro for target_type in target_macro_factory.target_types: per_path_symbols[target_type] = target_macro return per_path_symbols parser = legacy_python_callbacks_parser( symbol_table, object_table=object_table, per_path_symbol_factory=per_path_symbol_factory) mapper = AddressMapper(build_root, parser=parser) spec_excludes = options.for_global_scope().spec_excludes for address, obj in mapper.walk_addressables(path_excludes=spec_excludes): print(address.spec)
def _run(self): # Bootstrap options and logging. options_bootstrapper = self._options_bootstrapper or OptionsBootstrapper( env=self._env, args=self._args) options, build_config = OptionsInitializer( options_bootstrapper, exiter=self._exiter).setup() # Apply exiter options. self._exiter.apply_options(options) # Option values are usually computed lazily on demand, # but command line options are eagerly computed for validation. for scope in options.scope_to_flags.keys(): options.for_scope(scope) # Verify the configs here. if options.for_global_scope().verify_config: options_bootstrapper.verify_configs_against_options(options) # Launch RunTracker as early as possible (just after Subsystem options are initialized). run_tracker, reporting = ReportingInitializer().setup() try: # Determine the build root dir. root_dir = get_buildroot() # Capture a repro of the 'before' state for this build, if needed. repro = Reproducer.global_instance().create_repro() if repro: repro.capture(run_tracker.run_info.get_as_dict()) # Setup and run GoalRunner. goal_runner = GoalRunner.Factory(root_dir, options, build_config, run_tracker, reporting, exiter=self._exiter).setup() result = goal_runner.run() if repro: # TODO: Have Repro capture the 'after' state (as a diff) as well? repro.log_location_of_repro_file() finally: run_tracker.end() self._exiter.exit(result)
def _run(exiter): # Bootstrap options and logging. options, build_config = OptionsInitializer().setup() # Apply exiter options. exiter.apply_options(options) # Launch RunTracker as early as possible (just after Subsystem options are initialized). run_tracker, reporting = ReportingInitializer().setup() try: # Determine the build root dir. root_dir = get_buildroot() # Capture a repro of the 'before' state for this build, if needed. repro = Reproducer.global_instance().create_repro() if repro: repro.capture(run_tracker.run_info.get_as_dict()) # Set up and run GoalRunner. goal_runner = GoalRunner.Factory(root_dir, options, build_config, run_tracker, reporting).setup() result = goal_runner.run() if repro: # TODO: Have Repro capture the 'after' state (as a diff) as well? repro.log_location_of_repro_file() finally: run_tracker.end() exiter.do_exit(result)
def setup(options=None): if not options: options, _ = OptionsInitializer(OptionsBootstrapper()).setup() build_root = get_buildroot() cmd_line_spec_parser = CmdLineSpecParser(build_root) spec_roots = [cmd_line_spec_parser.parse_spec(spec) for spec in options.target_specs] storage = Storage.create(debug=False) project_tree = FileSystemProjectTree(build_root) symbol_table_cls = LegacyTable # Register "literal" subjects required for these tasks. # TODO: Replace with `Subsystems`. address_mapper = AddressMapper(symbol_table_cls=symbol_table_cls, parser_cls=LegacyPythonCallbacksParser) # Create a Scheduler containing graph and filesystem tasks, with no installed goals. The ExpGraph # will explicitly request the products it needs. tasks = ( create_legacy_graph_tasks() + create_fs_tasks() + create_graph_tasks(address_mapper, symbol_table_cls) ) return ( LocalScheduler(dict(), tasks, storage, project_tree), storage, options, spec_roots, symbol_table_cls )
def _run(self): # Bootstrap options and logging. options_bootstrapper = self._options_bootstrapper or OptionsBootstrapper(env=self._env, args=self._args) options, build_config = OptionsInitializer(options_bootstrapper, exiter=self._exiter).setup() # Apply exiter options. self._exiter.apply_options(options) # Option values are usually computed lazily on demand, # but command line options are eagerly computed for validation. for scope in options.scope_to_flags.keys(): options.for_scope(scope) # Verify the configs here. if options.for_global_scope().verify_config: options_bootstrapper.verify_configs_against_options(options) # Launch RunTracker as early as possible (just after Subsystem options are initialized). run_tracker, reporting = ReportingInitializer().setup() try: # Determine the build root dir. root_dir = get_buildroot() # Capture a repro of the 'before' state for this build, if needed. repro = Reproducer.global_instance().create_repro() if repro: repro.capture(run_tracker.run_info.get_as_dict()) # Setup and run GoalRunner. goal_runner = GoalRunner.Factory(root_dir, options, build_config, run_tracker, reporting, exiter=self._exiter).setup() result = goal_runner.run() if repro: # TODO: Have Repro capture the 'after' state (as a diff) as well? repro.log_location_of_repro_file() finally: run_tracker.end() self._exiter.exit(result)
def list(): """Lists all addresses under the current build root subject to `--spec-excludes` constraints.""" build_root = get_buildroot() options, build_config = OptionsInitializer().setup() aliases = build_config.registered_aliases() symbol_table = {alias: Target for alias in aliases.target_types} object_table = aliases.objects def per_path_symbol_factory(path, global_symbols): per_path_symbols = {} symbols = global_symbols.copy() for alias, target_macro_factory in aliases.target_macro_factories.items(): for target_type in target_macro_factory.target_types: symbols[target_type] = lambda *args, **kwargs: per_path_symbols[alias](*args, **kwargs) parse_context = ParseContext(rel_path=os.path.relpath(os.path.dirname(path), build_root), type_aliases=symbols) for alias, object_factory in aliases.context_aware_object_factories.items(): per_path_symbols[alias] = object_factory(parse_context) for alias, target_macro_factory in aliases.target_macro_factories.items(): target_macro = target_macro_factory.target_macro(parse_context) per_path_symbols[alias] = target_macro for target_type in target_macro_factory.target_types: per_path_symbols[target_type] = target_macro return per_path_symbols parser = legacy_python_callbacks_parser(symbol_table, object_table=object_table, per_path_symbol_factory=per_path_symbol_factory) mapper = AddressMapper(build_root, parser=parser) spec_excludes = options.for_global_scope().spec_excludes for address, obj in mapper.walk_addressables(path_excludes=spec_excludes): print(address.spec)
def _run(exiter): # Bootstrap options and logging. options, build_config = OptionsInitializer().setup() # Apply exiter options. exiter.apply_options(options) # Launch RunTracker as early as possible (just after Subsystem options are initialized). run_tracker, reporting = ReportingInitializer().setup() # Determine the build root dir. root_dir = get_buildroot() # Capture a repro of the 'before' state for this build, if needed. repro = Reproducer.global_instance().create_repro() if repro: repro.capture(run_tracker.run_info.get_as_dict()) # Set up and run GoalRunner. def run(): goal_runner = GoalRunner.Factory(root_dir, options, build_config, run_tracker, reporting).setup() return goal_runner.run() # Run with profiling, if requested. profile_path = os.environ.get('PANTS_PROFILE') if profile_path: import cProfile profiler = cProfile.Profile() try: result = profiler.runcall(run) finally: profiler.dump_stats(profile_path) print('Dumped profile data to {}'.format(profile_path)) view_cmd = green( 'gprof2dot -f pstats {path} | dot -Tpng -o {path}.png && ' 'open {path}.png'.format(path=profile_path)) print('Use, e.g., {} to render and view.'.format(view_cmd)) else: result = run() if repro: # TODO: Have Repro capture the 'after' state (as a diff) as well? repro.log_location_of_repro_file() exiter.do_exit(result)
def test_version_request(version_flag): class ExitException(Exception): def __init__(self, exit_code): self.exit_code = exit_code with temporary_dir() as build_root: def exiter(exit_code): raise ExitException(exit_code) options_bootstrapper = OptionsBootstrapper(args=[version_flag]) with pytest.raises(ExitException) as excinfo: OptionsInitializer(options_bootstrapper, WorkingSet(), exiter=exiter).setup() assert 0 == excinfo.value.exit_code
def _run(exiter): # We want to present warnings to the user, set this up early to ensure all warnings are seen. # The "default" action displays a warning for a particular file and line number exactly once. # See https://docs.python.org/2/library/warnings.html#the-warnings-filter for the complete action # list. warnings.simplefilter('default') # Bootstrap options and logging. options, build_config = OptionsInitializer().setup() # Apply exiter options. exiter.apply_options(options) # Launch RunTracker as early as possible (just after Subsystem options are initialized). run_tracker, reporting = ReportingInitializer().setup() # Determine the build root dir. root_dir = get_buildroot() # Setup and run GoalRunner. goal_runner = GoalRunner.Factory(root_dir, options, build_config, run_tracker, reporting).setup() result = goal_runner.run() exiter.do_exit(result)
def test_invalid_version(): options_bootstrapper = OptionsBootstrapper( args=['--pants-version=99.99.9999']) with pytest.raises(BuildConfigurationError): OptionsInitializer(options_bootstrapper, WorkingSet()).setup()
def aliases(cls): """TODO: This is a nasty escape hatch to pass aliases to LegacyPythonCallbacksParser.""" _, build_config = OptionsInitializer(OptionsBootstrapper()).setup() return build_config.registered_aliases()