Exemple #1
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()
Exemple #2
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
Exemple #3
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