Esempio n. 1
0
  def test_list_goals_graph(self):
    Phase.clear()

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()

    self.assert_console_output(
      'digraph G {\n  rankdir=LR;\n  graph [compound=true];',
      '  subgraph cluster_goals {\n    node [style=filled];\n    color = blue;\n    label = "goals";',
      '    goals_goals [label="goals"];',
      '  }',
      '  subgraph cluster_llama {\n    node [style=filled];\n    color = blue;\n    label = "llama";',
      '    llama_llama [label="llama"];',
      '  }',
      '  subgraph cluster_alpaca {\n    node [style=filled];\n    color = blue;\n    label = "alpaca";',
      '    alpaca_alpaca [label="alpaca"];',
      '  }',
      '  alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];',
      '}',
      args=['--test-graph'],
    )
Esempio n. 2
0
  def test_list_goals(self):
    Phase.clear()
    self.assert_console_output(self._INSTALLED_HEADER)

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
    )

    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )

    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )
Esempio n. 3
0
  def test_list_goals_graph(self):
    Phase.clear()

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()

    self.assert_console_output(
      'digraph G {\n  rankdir=LR;\n  graph [compound=true];',
      '  subgraph cluster_goals {\n    node [style=filled];\n    color = blue;\n    label = "goals";',
      '    goals_goals [label="goals"];',
      '  }',
      '  subgraph cluster_llama {\n    node [style=filled];\n    color = blue;\n    label = "llama";',
      '    llama_llama [label="llama"];',
      '  }',
      '  subgraph cluster_alpaca {\n    node [style=filled];\n    color = blue;\n    label = "alpaca";',
      '    alpaca_alpaca [label="alpaca"];',
      '  }',
      '  alpaca_alpaca -> llama_llama [ltail=cluster_alpaca lhead=cluster_llama];',
      '}',
      args=['--test-graph'],
    )
Esempio n. 4
0
def print_help(goals=None):
  if goals:
    for goal in goals:
      phase = Phase(goal)
      if not phase.goals():
        print('\nUnknown goal: %s' % goal)
      else:
        parser = OptionParser(add_help_option=False)
        phase.setup_parser(parser, [], [phase])
        print('\n%s: %s' % (phase.name, phase.description))
        _print_flags(parser, phase.name)
  else:
    print(pants_release())
    print('\nUsage:')
    print('  ./pants goal [option ...] [goal ...] [target...]  Attempt the specified goals.')
    print('  ./pants goal help                                 Get help.')
    print('  ./pants goal help [goal]                          Get help for the specified goal.')
    print('  ./pants goal goals                                List all installed goals.')
    print('')
    print('  [target] accepts two special forms:')
    print('    dir:  to include all targets in the specified directory.')
    print('    dir:: to include all targets found recursively under the directory.')

    print('\nFriendly docs:\n  http://pantsbuild.github.io/')

    _print_global_flags()
Esempio n. 5
0
def print_help(goals=None):
    if goals:
        for goal in goals:
            phase = Phase(goal)
            if not phase.goals():
                print('\nUnknown goal: %s' % goal)
            else:
                parser = OptionParser(add_help_option=False)
                phase.setup_parser(parser, [], [phase])
                print('\n%s: %s' % (phase.name, phase.description))
                _print_flags(parser, phase.name)
    else:
        print('Pants %s' % version.VERSION)
        print('\nUsage:')
        print(
            '  ./pants goal [option ...] [goal ...] [target...]  Attempt the specified goals.'
        )
        print('  ./pants goal help                                 Get help.')
        print(
            '  ./pants goal help [goal]                          Get help for the specified goal.'
        )
        print(
            '  ./pants goal goals                                List all installed goals.'
        )
        print('')
        print('  [target] accepts two special forms:')
        print('    dir:  to include all targets in the specified directory.')
        print(
            '    dir:: to include all targets found recursively under the directory.'
        )

        print('\nFriendly docs:\n  http://pantsbuild.github.io/')

        _print_global_flags()
Esempio n. 6
0
  def test_list_goals(self):
    Phase.clear()
    self.assert_console_output(self._INSTALLED_HEADER)

    Goal(name=self._LIST_GOALS_NAME, action=ListGoals)\
      .install().with_description(self._LIST_GOALS_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
    )

    Goal(name=self._LLAMA_NAME, action=ListGoalsTest.LlamaTask)\
      .install().with_description(self._LLAMA_DESC)
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )

    Goal(name=self._ALPACA_NAME, action=ListGoalsTest.AlpacaTask, dependencies=[self._LLAMA_NAME])\
      .install()
    self.assert_console_output(
      self._INSTALLED_HEADER,
      '  %s: %s' % (self._LIST_GOALS_NAME, self._LIST_GOALS_DESC),
      '  %s: %s' % (self._LLAMA_NAME, self._LLAMA_DESC),
    )
Esempio n. 7
0
  def setUp(self):
    Phase.clear()
    self.real_build_root = BuildRoot().path
    self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
    BuildRoot().path = self.build_root

    self.create_file('pants.ini')

    build_configuration = BuildConfiguration()
    build_configuration.register_aliases(self.alias_groups)
    self.build_file_parser = BuildFileParser(build_configuration, self.build_root)

    self.build_graph = BuildGraph()
Esempio n. 8
0
  def install(self, phase=None, first=False, replace=False, before=None, after=None):
    """Install this goal in the specified phase (or a new phase with the same name as this Goal).

    The placement of the goal in the execution list of the phase defaults to the end but can be
    influence by specifying exactly one of the following arguments:

    :param first: Places this goal 1st in the phase's execution list
    :param replace: Replaces any existing goals in the phase with this goal
    :param before: Places this goal before the named goal in the phase's execution list
    :param after: Places this goal after the named goal in the phase's execution list
    """
    phase = Phase(phase or self.name)
    phase.install(self, first, replace, before, after)
    return phase
Esempio n. 9
0
  def test_load_valid_partial_goals(self):
    def register_goals():
      Phase('jack').install(Goal('jill', lambda: 42))

    with self.create_register(register_goals=register_goals) as backend_package:
      Phase.clear()
      self.assertEqual(0, len(Phase.all()))

      load_backend(self.build_configuration, backend_package)
      self.assert_empty_aliases()
      self.assertEqual(1, len(Phase.all()))

      goals = Phase('jack').goals()
      self.assertEqual(1, len(goals))

      goal = goals[0]
      self.assertEqual('jill', goal.name)
Esempio n. 10
0
    def install(self,
                phase=None,
                first=False,
                replace=False,
                before=None,
                after=None):
        """Install this goal in the specified phase (or a new phase with the same name as this Goal).

    The placement of the goal in the execution list of the phase defaults to the end but can be
    influence by specifying exactly one of the following arguments:

    :param first: Places this goal 1st in the phase's execution list
    :param replace: Replaces any existing goals in the phase with this goal
    :param before: Places this goal before the named goal in the phase's execution list
    :param after: Places this goal after the named goal in the phase's execution list
    """
        phase = Phase(phase or self.name)
        phase.install(self, first, replace, before, after)
        return phase
Esempio n. 11
0
    def graph():
      def get_cluster_name(phase):
        return 'cluster_%s' % phase.name.replace('-', '_')

      def get_goal_name(phase, goal):
        name = '%s_%s' % (phase.name, goal.name)
        return name.replace('-', '_')

      phase_by_phasename = {}
      for phase, goals in Phase.all():
        phase_by_phasename[phase.name] = phase

      yield '\n'.join([
        'digraph G {',
        '  rankdir=LR;',
        '  graph [compound=true];',
        ])
      for phase, installed_goals in Phase.all():
        yield '\n'.join([
          '  subgraph %s {' % get_cluster_name(phase),
          '    node [style=filled];',
          '    color = blue;',
          '    label = "%s";' % phase.name,
        ])
        for installed_goal in installed_goals:
          yield '    %s [label="%s"];' % (get_goal_name(phase, installed_goal),
                                          installed_goal.name)
        yield '  }'

      edges = set()
      for phase, installed_goals in Phase.all():
        for installed_goal in installed_goals:
          for dependency in installed_goal.dependencies:
            tail_goal = phase_by_phasename.get(dependency.name).goals()[-1]
            edge = 'ltail=%s lhead=%s' % (get_cluster_name(phase),
                                          get_cluster_name(Phase.of(tail_goal)))
            if edge not in edges:
              yield '  %s -> %s [%s];' % (get_goal_name(phase, installed_goal),
                                          get_goal_name(Phase.of(tail_goal), tail_goal),
                                          edge)
            edges.add(edge)
      yield '}'
Esempio n. 12
0
def register_goals():
  changed = Phase('changed').with_description('Print the targets changed since some prior commit.')
  changed.install(Goal(name='changed', action=ScmWhatChanged))

  # We always want compile to finish with a checkstyle
  compile = Phase('compile')
  compile.install(Goal(name='checkstyle', action=Checkstyle,
                       dependencies=['gen', 'resolve']))
Esempio n. 13
0
    def __init__(self,
                 name,
                 action,
                 group=None,
                 dependencies=None,
                 serialize=True):
        """
    :param name: the name of the goal.
    :param action: the goal action object to invoke this goal.
    :param dependencies: the names of other goals which must be achieved before invoking this goal.
    :param serialize: a flag indicating whether or not the action to achieve this goal requires
      the global lock. If true, the action will block until it can acquire the lock.
    """
        self.serialize = serialize
        self.name = name
        self.group = group
        self.dependencies = [Phase(d)
                             for d in dependencies] if dependencies else []

        if type(action) == type and issubclass(action, Task):
            self._task = action
        else:
            args, varargs, keywords, defaults = inspect.getargspec(action)
            if varargs or keywords or defaults:
                raise GoalError(
                    'Invalid action supplied, cannot accept varargs, keywords or defaults'
                )
            if len(args) > 2:
                raise GoalError(
                    'Invalid action supplied, must accept 0, 1, or 2 args')

            class FuncTask(Task):
                def __init__(self, context, workdir):
                    super(FuncTask, self).__init__(context, workdir)

                    if not args:
                        self.action = lambda targets: action()
                    elif len(args) == 1:
                        self.action = lambda targets: action(self.context)
                    elif len(args) == 2:
                        self.action = lambda targets: action(
                            self.context, targets)
                    else:
                        raise AssertionError('Unexpected fallthrough')

                def execute(self, targets):
                    self.action(targets)

            self._task = FuncTask
Esempio n. 14
0
 def report():
   yield 'Installed goals:'
   documented_rows = []
   undocumented = []
   max_width = 0
   for phase, _ in Phase.all():
     if phase.description:
       documented_rows.append((phase.name, phase.description))
       max_width = max(max_width, len(phase.name))
     elif self.context.options.goal_list_all:
       undocumented.append(phase.name)
   for name, description in documented_rows:
     yield '  %s: %s' % (name.rjust(max_width), description)
   if undocumented:
     yield ''
     yield 'Undocumented goals:'
     yield '  %s' % ' '.join(undocumented)
Esempio n. 15
0
  def execute(self, targets):
    """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
    checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
    if checkstyle_enabled:
      checkstyle_classpath = self.tool_classpath(self.checkstyle_bootstrap_key)
    else:
      checkstyle_classpath = []

    if self.scalac_bootstrap_key:
      scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
    else:
      scalac_classpath = []

    self._project.set_tool_classpaths(checkstyle_classpath, scalac_classpath)

    self.map_internal_jars(targets)
    self.map_external_jars()

    idefile = self.generate_project(self._project)
    if idefile:
      binary_util.ui_open(idefile)
Esempio n. 16
0
def gen_goals_phases_reference_data():
    """Generate the goals reference rst doc."""
    phase_dict = {}
    phase_names = []
    for phase, raw_goals in Phase.all():
        parser = optparse.OptionParser(add_help_option=False)
        phase.setup_parser(parser, [], [phase])
        options_by_title = defaultdict(lambda: None)
        for group in parser.option_groups:
            options_by_title[group.title] = group
        found_option_groups = set()
        goals = []
        for goal in sorted(raw_goals, key=(lambda x: x.name.lower())):
            doc = indent_docstring_by_n(goal.task_type.__doc__ or "", 2)
            options_title = goal.title_for_option_group(phase)
            og = options_by_title[options_title]
            if og:
                found_option_groups.add(options_title)
            goals.append(
                TemplateData(name=goal.task_type.__name__,
                             doc=doc,
                             ogroup=gref_template_data_from_options(og)))

        leftover_option_groups = []
        for group in parser.option_groups:
            if group.title in found_option_groups: continue
            leftover_option_groups.append(
                gref_template_data_from_options(group))
        leftover_options = []
        for option in parser.option_list:
            leftover_options.append(TemplateData(st=str(option)))
        phase_dict[phase.name] = TemplateData(
            phase=phase,
            goals=goals,
            leftover_opts=leftover_options,
            leftover_ogs=leftover_option_groups)
        phase_names.append(phase.name)

    phases = [phase_dict[name] for name in sorted(phase_names, key=_lower)]
    return phases
Esempio n. 17
0
def gen_goals_phases_reference_data():
  """Generate the template data for the goals reference rst doc."""
  phase_dict = {}
  phase_names = []
  for phase, raw_goals in Phase.all():
    parser = optparse.OptionParser(add_help_option=False)
    phase.setup_parser(parser, [], [phase])
    options_by_title = defaultdict(lambda: None)
    for group in parser.option_groups:
      options_by_title[group.title] = group
    found_option_groups = set()
    goals = []
    for goal in sorted(raw_goals, key=(lambda x: x.name.lower())):
      doc = indent_docstring_by_n(goal.task_type.__doc__ or "", 2)
      options_title = goal.title_for_option_group(phase)
      og = options_by_title[options_title]
      if og:
        found_option_groups.add(options_title)
      impl = "{0}.{1}".format(goal.task_type.__module__, goal.task_type.__name__)
      goals.append(TemplateData(
          impl=impl,
          doc=doc,
          ogroup=gref_template_data_from_options(og)))

    leftover_option_groups = []
    for group in parser.option_groups:
      if group.title in found_option_groups: continue
      leftover_option_groups.append(gref_template_data_from_options(group))
    leftover_options = []
    for option in parser.option_list:
      leftover_options.append(TemplateData(st=str(option)))
    phase_dict[phase.name] = TemplateData(phase=phase,
                                          goals=goals,
                                          leftover_opts=leftover_options,
                                          leftover_ogs=leftover_option_groups)
    phase_names.append(phase.name)

  phases = [phase_dict[name] for name in sorted(phase_names, key=_lower)]
  return phases
Esempio n. 18
0
  def _gen_goals_reference(self):
    """Generate the goals reference rst doc."""
    phase_dict = {}
    phase_names = []
    for phase, raw_goals in Phase.all():
      goals = []
      for g in raw_goals:
        # TODO(lahosken) generalize indent_docstring, use here
        doc = (g.task_type.__doc__ or '').replace('\n\'', ' \'').strip()
        goals.append(TemplateData(name=g.task_type.__name__, doc=doc))
      phase_dict[phase.name] = TemplateData(phase=phase, goals=goals)
      phase_names.append(phase.name)

    phases = [phase_dict[name] for name in sorted(phase_names, key=_lower)]

    template = resource_string(__name__,
                               os.path.join(self._templates_dir, 'goals_reference.mustache'))
    filename = os.path.join(self._outdir, 'goals_reference.rst')
    self.context.log.info('Generating %s' % filename)
    with safe_open(filename, 'w') as outfile:
      generator = Generator(template, phases=phases)
      generator.write(outfile)
Esempio n. 19
0
    def execute(self, targets):
        """Stages IDE project artifacts to a project directory and generates IDE configuration files."""
        checkstyle_enabled = len(Phase.goals_of_type(Checkstyle)) > 0
        if checkstyle_enabled:
            checkstyle_classpath = self.tool_classpath(
                self.checkstyle_bootstrap_key)
        else:
            checkstyle_classpath = []

        if self.scalac_bootstrap_key:
            scalac_classpath = self.tool_classpath(self.scalac_bootstrap_key)
        else:
            scalac_classpath = []

        self._project.set_tool_classpaths(checkstyle_classpath,
                                          scalac_classpath)

        self.map_internal_jars(targets)
        self.map_external_jars()

        idefile = self.generate_project(self._project)
        if idefile:
            binary_util.ui_open(idefile)
Esempio n. 20
0
def register_goals():
  resources = Phase('resources')
  resources.install(Goal(name='args-apt', action=ResourceMapper,
                         dependencies=['compile']))
Esempio n. 21
0
 def tearDown(self):
   super(GoalTest, self).tearDown()
   Phase.clear()
Esempio n. 22
0
 def tearDown(self):
   Phase.clear()