def _make_context(self, target_roots): return Context(self.config, options={}, run_tracker=None, target_roots=target_roots, build_graph=self.build_graph, build_file_parser=self.build_file_parser)
def create_context(config='', options=None, target_roots=None, **kwargs): """Creates a ``Context`` with no config values, options, or targets by default. :param config: Either a ``Context`` object or else a string representing the contents of the pants.ini to parse the config from. :param options: An optional dict of of option values. :param target_roots: An optional list of target roots to seed the context target graph from. :param ``**kwargs``: Any additional keyword arguments to pass through to the Context constructor. """ config = config if isinstance(config, Config) else create_config(config) run_tracker = create_run_tracker() target_roots = maybe_list(target_roots, Target) if target_roots else [] return Context(config, create_options(options or {}), run_tracker, target_roots, **kwargs)
def run(self, lock): # TODO(John Sirois): Consider moving to straight python logging. The divide between the # context/work-unit logging and standard python logging doesn't buy us anything. # Enable standard python logging for code with no handle to a context/work-unit. if self.options.log_level: LogOptions.set_stderr_log_level((self.options.log_level or 'info').upper()) logdir = self.options.logdir or self.config.get( 'goals', 'logdir', default=None) if logdir: safe_mkdir(logdir) LogOptions.set_log_dir(logdir) log.init('goals') else: log.init() # Update the reporting settings, now that we have flags etc. def is_console_task(): for phase in self.phases: for goal in phase.goals(): if issubclass(goal.task_type, ConsoleTask): return True return False is_explain = self.options.explain update_reporting(self.options, is_console_task() or is_explain, self.run_tracker) context = Context(self.config, self.options, self.run_tracker, self.targets, requested_goals=self.requested_goals, build_graph=self.build_graph, build_file_parser=self.build_file_parser, lock=lock) unknown = [] for phase in self.phases: if not phase.goals(): unknown.append(phase) if unknown: context.log.error('Unknown goal(s): %s\n' % ' '.join(phase.name for phase in unknown)) return 1 engine = GroupEngine() return engine.execute(context, self.phases)
def testPartitioning(self): # Target e has conflicts; in this test, we want to check that partitioning # of valid targets works to prevent conflicts in chunks, so we only use a-d. a, b, c, d, _ = self.setupTargets() context = Context(self.config, options={}, run_tracker=None, target_roots=[a, b, c, d]) context.products.require_data('exclusives_groups') with temporary_dir() as workdir: check_exclusives_task = CheckExclusives(context, workdir, signal_error=True) check_exclusives_task.execute([a, b, c, d]) egroups = context.products.get_data('exclusives_groups') self.assertEquals(egroups.get_targets_for_group_key("a=1"), set([a, b, d])) self.assertEquals(egroups.get_targets_for_group_key("a=2"), set([c]))
def prepare_task(task_type, config=None, args=None, targets=None, build_graph=None, build_file_parser=None, **kwargs): """Prepares a Task for execution. task_type: The class of the Task to create. config: An optional string representing the contents of a pants.ini config. args: optional list of command line flags, these should be prefixed with '--test-'. targets: optional list of Target objects passed on the command line. **kwargs: Any additional args the Task subclass constructor takes beyond the required context. Returns a new Task ready to execute. """ assert issubclass( task_type, Task), 'task_type must be a Task subclass, got %s' % task_type config = create_config(config or '') workdir = os.path.join(config.getdefault('pants_workdir'), 'test', task_type.__name__) parser = OptionParser() option_group = OptionGroup(parser, 'test') mkflag = Mkflag('test') task_type.setup_parser(option_group, args, mkflag) options, _ = parser.parse_args(args or []) run_tracker = create_run_tracker() context = Context(config, options, run_tracker, targets or [], build_graph=build_graph, build_file_parser=build_file_parser) return task_type(context, workdir, **kwargs)
def create_context(self, **kwargs): return Context(self.config, build_graph=self.build_graph, build_file_parser=self.build_file_parser, run_tracker=None, **kwargs)