예제 #1
0
파일: goal.py 프로젝트: sikopet/pants
  def uninstall_task(self, name):
    """Removes the named task from this goal.

    Allows external plugins to modify the execution plan. Use with caution.

    Note: Does not remove goal dependencies or relax a serialization requirement that originated
    from the uninstalled task's install() call.
    TODO(benjy): Should it? We're moving away from explicit goal deps towards a
                 product consumption-production model anyway.
    """
    if name in self._task_type_by_name:
      self._task_type_by_name[name].options_scope = None
      del self._task_type_by_name[name]
      self._ordered_task_names = [x for x in self._ordered_task_names if x != name]
    else:
      raise GoalError('Cannot uninstall unknown task: {0}'.format(name))
예제 #2
0
파일: goal.py 프로젝트: simudream/pants
    def uninstall_task(self, name):
        """Removes the named task from this goal.

    Allows external plugins to modify the execution plan. Use with caution.

    Note: Does not relax a serialization requirement that originated
    from the uninstalled task's install() call.
    """
        if name in self._task_type_by_name:
            self._task_type_by_name[name].options_scope = None
            del self._task_type_by_name[name]
            self._ordered_task_names = [
                x for x in self._ordered_task_names if x != name
            ]
        else:
            raise GoalError('Cannot uninstall unknown task: {0}'.format(name))
예제 #3
0
파일: phase.py 프로젝트: ejconlon/pants
    def install(self,
                goal,
                first=False,
                replace=False,
                before=None,
                after=None):
        """
      Installs the given goal in this phase.  The placement of the goal in this phases' execution
      list defaults to the end but its position can be influence by specifying exactly one of the
      following arguments:

      first: Places the goal 1st in the execution list
      replace: Removes all existing goals in this phase and installs this goal
      before: Places the goal before the named goal in the execution list
      after: Places the goal after the named goal in the execution list
    """

        if [bool(place)
                for place in [first, replace, before, after]].count(True) > 1:
            raise GoalError(
                'Can only specify one of first, replace, before or after')

        Phase._phase_by_goal[goal] = self

        g = self.goals()
        if replace:
            del g[:]
        g_names = map(lambda goal: goal.name, g)
        if first:
            g.insert(0, goal)
        elif before in g_names:
            g.insert(g_names.index(before), goal)
        elif after in g_names:
            g.insert(g_names.index(after) + 1, goal)
        else:
            g.append(goal)
        return self
예제 #4
0
파일: goal.py 프로젝트: neven7/pants
    def install(self,
                task_registrar,
                first=False,
                replace=False,
                before=None,
                after=None):
        """Installs the given task in this goal.

    The placement of the task in this goal's execution list defaults to the end but its position
    can be influenced by specifying exactly one of the following arguments:

    first: Places the task 1st in the execution list.
    replace: Removes all existing tasks in this goal and installs this task.
    before: Places the task before the named task in the execution list.
    after: Places the task after the named task in the execution list.

    :API: public
    """
        if [bool(place)
                for place in [first, replace, before, after]].count(True) > 1:
            raise GoalError(
                'Can only specify one of first, replace, before or after')

        task_name = task_registrar.name
        Optionable.validate_scope_name_component(task_name)
        options_scope = Goal.scope(self.name, task_name)

        # Currently we need to support registering the same task type multiple times in different
        # scopes. However we still want to have each task class know the options scope it was
        # registered in. So we create a synthetic subclass here.
        # TODO(benjy): Revisit this when we revisit the task lifecycle. We probably want to have
        # a task *instance* know its scope, but this means converting option registration from
        # a class method to an instance method, and instantiating the task much sooner in the
        # lifecycle.
        superclass = task_registrar.task_type
        subclass_name = b'{0}_{1}'.format(
            superclass.__name__,
            options_scope.replace('.', '_').replace('-', '_'))
        task_type = type(
            subclass_name, (superclass, ), {
                '__doc__': superclass.__doc__,
                '__module__': superclass.__module__,
                'options_scope': options_scope,
                '_stable_name': superclass.stable_name()
            })

        otn = self._ordered_task_names
        if replace:
            for tt in self.task_types():
                tt.options_scope = None
            del otn[:]
            self._task_type_by_name = {}
        if first:
            otn.insert(0, task_name)
        elif before in otn:
            otn.insert(otn.index(before), task_name)
        elif after in otn:
            otn.insert(otn.index(after) + 1, task_name)
        else:
            otn.append(task_name)

        self._task_type_by_name[task_name] = task_type

        if task_registrar.serialize:
            self.serialize = True

        return self