def create(cls, options=None, args=None, build_root=None, change_calculator=None): """ :param Options options: An `Options` instance to use, if available. :param string args: Raw cli args to use for parsing if an `Options` instance isn't available. :param string build_root: The build root. :param ChangeCalculator change_calculator: A `ChangeCalculator` for calculating changes. """ if not options: assert args is not None, 'must pass `args` if not passing `options`' options, _ = OptionsInitializer(OptionsBootstrapper(args=args)).setup(init_logging=False) # Determine the literal target roots. spec_roots = cls.parse_specs(options.target_specs, build_root) # Determine `Changed` arguments directly from options to support pre-`Subsystem` initialization paths. changed_options = options.for_scope('changed') changed_request = ChangedRequest.from_options(changed_options) logger.debug('args are: %s', args) logger.debug('spec_roots are: %s', spec_roots) logger.debug('changed_request is: %s', changed_request) if change_calculator and changed_request.is_actionable(): if spec_roots: # We've been provided spec roots (e.g. `./pants list ::`) AND a changed request. Error out. raise InvalidSpecConstraint('cannot provide changed parameters and target specs!') # We've been provided no spec roots (e.g. `./pants list`) AND a changed request. Compute # alternate target roots. changed_addresses = change_calculator.changed_target_addresses(changed_request) logger.debug('changed addresses: %s', changed_addresses) return ChangedTargetRoots(tuple(SingleAddress(a.spec_path, a.target_name) for a in changed_addresses)) return LiteralTargetRoots(spec_roots)
def parse_commandline_to_spec_roots(options=None, args=None, build_root=None): if not options: options, _ = OptionsInitializer(OptionsBootstrapper(args=args), init_logging=False).setup() cmd_line_spec_parser = CmdLineSpecParser(build_root or get_buildroot()) spec_roots = [ cmd_line_spec_parser.parse_spec(spec) for spec in options.target_specs ] return spec_roots
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() global_options = options.for_global_scope() # 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 global_options.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, self._daemon_build_graph, self._exiter).setup() goal_runner_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_result = run_tracker.end() # Take the exit code with higher abs value in case of negative values. final_exit_code = goal_runner_result if abs(goal_runner_result) > abs(run_tracker_result) else run_tracker_result self._exiter.exit(final_exit_code)
def aliases(cls): """TODO: This is a nasty escape hatch to pass aliases to LegacyPythonCallbacksParser.""" _, build_config = OptionsInitializer(OptionsBootstrapper()).setup(init_logging=False) return build_config.registered_aliases()
def test_invalid_version(): options_bootstrapper = OptionsBootstrapper(args=['--pants-version=99.99.9999']) with pytest.raises(BuildConfigurationError): OptionsInitializer(options_bootstrapper, WorkingSet()).setup()
def test_invalid_version(self): options_bootstrapper = OptionsBootstrapper(args=['--pants-version=99.99.9999']) initializer = OptionsInitializer(options_bootstrapper, WorkingSet()) with self.assertRaises(BuildConfigurationError): initializer.setup()