Beispiel #1
0
def print_help(goals=None):
    if goals:
        for goal in goals:
            goal = Goal.by_name(goal)
            if not goal.ordered_task_names():
                print('\nUnknown goal: %s' % goal)
            else:
                parser = OptionParser(add_help_option=False)
                Goal.setup_parser(parser, [], [goal])
                print('\n%s: %s' % (goal.name, goal.description))
                _print_flags(parser, goal.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()
Beispiel #2
0
def print_help(goals=None):
  if goals:
    for goal in goals:
      goal = Goal.by_name(goal)
      if not goal.ordered_task_names():
        print('\nUnknown goal: %s' % goal)
      else:
        parser = OptionParser(add_help_option=False)
        Goal.setup_parser(parser, [], [goal])
        print('\n%s: %s' % (goal.name, goal.description))
        _print_flags(parser, goal.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()
Beispiel #3
0
def gen_tasks_goals_reference_data():
  """Generate the template data for the goals reference rst doc."""
  goal_dict = {}
  goal_names = []
  for goal in Goal.all():
    parser = optparse.OptionParser(add_help_option=False)
    Goal.setup_parser(parser, [], [goal])
    options_by_title = defaultdict(lambda: None)
    for group in parser.option_groups:
      options_by_title[group.title] = group
    found_option_groups = set()
    tasks = []
    for task_name in goal.ordered_task_names():
      task_type = goal.task_type_by_name(task_name)
      doc_rst = indent_docstring_by_n(task_type.__doc__ or '', 2)
      doc_html = rst_to_html(dedent_docstring(task_type.__doc__))
      options_title = Goal.scope(goal.name, task_name)
      og = options_by_title[options_title]
      if og:
        found_option_groups.add(options_title)
      impl = '{0}.{1}'.format(task_type.__module__, task_type.__name__)
      tasks.append(TemplateData(
          impl=impl,
          doc_html=doc_html,
          doc_rst=doc_rst,
          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)))
    goal_dict[goal.name] = TemplateData(goal=goal,
                                        tasks=tasks,
                                        leftover_opts=leftover_options,
                                        leftover_ogs=leftover_option_groups)
    goal_names.append(goal.name)

  goals = [goal_dict[name] for name in sorted(goal_names, key=lambda x: x.lower())]
  return goals
Beispiel #4
0
  def print_help(self, msg=None, goals=None, legacy=False):
    """Print a help screen, followed by an optional message.

    Note: Ony useful if called after options have been registered.
    """
    def _maybe_help(scope):
      s = self.format_help(scope, legacy=legacy)
      if s != '':  # Avoid superfluous blank lines for empty strings.
        print(s)

    goals = goals or self.goals
    if goals:
      for goal_name in goals:
        goal = Goal.by_name(goal_name)
        # Register old-style options for the purpose of help-printing.
        Goal.setup_parser(self._legacy_parser, [], [goal])
        if not goal.ordered_task_names():
          print('\nUnknown goal: %s' % goal_name)
        else:
          print('\n{0}: {1}\n'.format(goal.name, goal.description))
          for scope in goal.known_scopes():
            _maybe_help(scope)
    else:
      print(pants_release())
      print('\nUsage:')
      print('  ./pants [option ...] [goal ...] [target...]  Attempt the specified goals.')
      print('  ./pants help                                 Get help.')
      print('  ./pants 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('\nGlobal options:')
      print(self.format_global_help())

    if msg is not None:
      print(msg)
Beispiel #5
0
def gen_tasks_goals_reference_data():
  """Generate the template data for the goals reference rst doc."""
  goal_dict = {}
  goal_names = []
  for goal in Goal.all():
    parser = optparse.OptionParser(add_help_option=False)
    Goal.setup_parser(parser, [], [goal])
    options_by_title = defaultdict(lambda: None)
    for group in parser.option_groups:
      options_by_title[group.title] = group
    found_option_groups = set()
    tasks = []
    for task_name in goal.ordered_task_names():
      task_type = goal.task_type_by_name(task_name)
      doc = indent_docstring_by_n(task_type.__doc__ or '', 2)
      options_title = Goal.option_group_title(goal, task_name)
      og = options_by_title[options_title]
      if og:
        found_option_groups.add(options_title)
      impl = '{0}.{1}'.format(task_type.__module__, task_type.__name__)
      tasks.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)))
    goal_dict[goal.name] = TemplateData(goal=goal,
                                        tasks=tasks,
                                        leftover_opts=leftover_options,
                                        leftover_ogs=leftover_option_groups)
    goal_names.append(goal.name)

  goals = [goal_dict[name] for name in sorted(goal_names, key=_lower)]
  return goals
Beispiel #6
0
    def setup_parser(self, parser, args):
        self.config = Config.load()
        add_global_options(parser)

        # We support attempting zero or more goals.  Multiple goals must be delimited from further
        # options and non goal args with a '--'.  The key permutations we need to support:
        # ./pants goal => goals
        # ./pants goal goals => goals
        # ./pants goal compile src/java/... => compile
        # ./pants goal compile -x src/java/... => compile
        # ./pants goal compile src/java/... -x => compile
        # ./pants goal compile run -- src/java/... => compile, run
        # ./pants goal compile run -- src/java/... -x => compile, run
        # ./pants goal compile run -- -x src/java/... => compile, run

        if not args:
            args.append("help")

        help_flags = set(["-h", "--help", "help"])
        show_help = len(help_flags.intersection(args)) > 0
        non_help_args = filter(lambda f: f not in help_flags, args)

        goals, specs = GoalRunner.parse_args(non_help_args)
        if show_help:
            print_help(goals)
            sys.exit(0)

        self.requested_goals = goals

        with self.run_tracker.new_workunit(name="setup", labels=[WorkUnit.SETUP]):
            # Bootstrap user goals by loading any BUILD files implied by targets.
            spec_parser = CmdLineSpecParser(self.root_dir, self.address_mapper)
            with self.run_tracker.new_workunit(name="parse", labels=[WorkUnit.SETUP]):
                for spec in specs:
                    for address in spec_parser.parse_addresses(spec):
                        self.build_graph.inject_address_closure(address)
                        self.targets.append(self.build_graph.get_target(address))
        self.goals = [Goal.by_name(goal) for goal in goals]

        rcfiles = self.config.getdefault("rcfiles", type=list, default=["/etc/pantsrc", "~/.pants.rc"])
        if rcfiles:
            rcfile = RcFile(rcfiles, default_prepend=False, process_default=True)

            # Break down the goals specified on the command line to the full set that will be run so we
            # can apply default flags to inner goal nodes.  Also break down goals by Task subclass and
            # register the task class hierarchy fully qualified names so we can apply defaults to
            # baseclasses.

            sections = OrderedSet()
            for goal in Engine.execution_order(self.goals):
                for task_name in goal.ordered_task_names():
                    sections.add(task_name)
                    task_type = goal.task_type_by_name(task_name)
                    for clazz in task_type.mro():
                        if clazz == Task:
                            break
                        sections.add("%s.%s" % (clazz.__module__, clazz.__name__))

            augmented_args = rcfile.apply_defaults(sections, args)
            if augmented_args != args:
                # TODO(John Sirois): Cleanup this currently important mutation of the passed in args
                # once the 2-layer of command -> goal is squashed into one.
                del args[:]
                args.extend(augmented_args)
                sys.stderr.write("(using pantsrc expansion: pants goal %s)\n" % " ".join(augmented_args))

        Goal.setup_parser(parser, args, self.goals)
Beispiel #7
0
    def setup_parser(self, parser, args):
        self.config = Config.load()
        add_global_options(parser)

        # We support attempting zero or more goals.  Multiple goals must be delimited from further
        # options and non goal args with a '--'.  The key permutations we need to support:
        # ./pants goal => goals
        # ./pants goal goals => goals
        # ./pants goal compile src/java/... => compile
        # ./pants goal compile -x src/java/... => compile
        # ./pants goal compile src/java/... -x => compile
        # ./pants goal compile run -- src/java/... => compile, run
        # ./pants goal compile run -- src/java/... -x => compile, run
        # ./pants goal compile run -- -x src/java/... => compile, run

        if not args:
            args.append('help')

        help_flags = set(['-h', '--help', 'help'])
        show_help = len(help_flags.intersection(args)) > 0
        non_help_args = filter(lambda f: f not in help_flags, args)

        goals, specs = GoalRunner.parse_args(non_help_args)
        if show_help:
            print_help(goals)
            sys.exit(0)

        self.requested_goals = goals

        with self.run_tracker.new_workunit(name='setup',
                                           labels=[WorkUnit.SETUP]):
            # Bootstrap user goals by loading any BUILD files implied by targets.
            spec_parser = CmdLineSpecParser(self.root_dir, self.address_mapper)
            with self.run_tracker.new_workunit(name='parse',
                                               labels=[WorkUnit.SETUP]):
                for spec in specs:
                    for address in spec_parser.parse_addresses(spec):
                        self.build_graph.inject_address_closure(address)
                        self.targets.append(
                            self.build_graph.get_target(address))
        self.goals = [Goal.by_name(goal) for goal in goals]

        rcfiles = self.config.getdefault(
            'rcfiles', type=list, default=['/etc/pantsrc', '~/.pants.rc'])
        if rcfiles:
            rcfile = RcFile(rcfiles,
                            default_prepend=False,
                            process_default=True)

            # Break down the goals specified on the command line to the full set that will be run so we
            # can apply default flags to inner goal nodes.  Also break down goals by Task subclass and
            # register the task class hierarchy fully qualified names so we can apply defaults to
            # baseclasses.

            sections = OrderedSet()
            for goal in Engine.execution_order(self.goals):
                for task_name in goal.ordered_task_names():
                    sections.add(task_name)
                    task_type = goal.task_type_by_name(task_name)
                    for clazz in task_type.mro():
                        if clazz == Task:
                            break
                        sections.add('%s.%s' %
                                     (clazz.__module__, clazz.__name__))

            augmented_args = rcfile.apply_defaults(sections, args)
            if augmented_args != args:
                # TODO(John Sirois): Cleanup this currently important mutation of the passed in args
                # once the 2-layer of command -> goal is squashed into one.
                del args[:]
                args.extend(augmented_args)
                sys.stderr.write("(using pantsrc expansion: pants goal %s)\n" %
                                 ' '.join(augmented_args))

        Goal.setup_parser(parser, args, self.goals)