Build the order of component based on their priority and predecessors

        :rtype: list of Component
341647
def build_component_order(self):
        
        present_components = [item for item in self.__dict__.values() if isinstance(item, Component) and item.enabled]
        result = [None] * len(present_components)
        used_prios = set()
        for component in present_components:
            index = component.priority % len(present_components)
            if index in used_prios:
                raise ValueError("Duplicate priority: {}".format(component.priority))
            used_prios.add(index)

            result[index] = component

        # Check if predecessors are valid
        for i, component in enumerate(result):
            if any(i < result.index(pre) for pre in component.predecessors):
                raise ValueError("Component {} comes before at least one of its predecessors".format(component))

        return result
638040
def dict2orderedlist(dic, order_list, default='', **kwargs):
    
    result = []
    for key_order in order_list:
        value = get_element(dic, key_order, **kwargs)
        result.append(value if value is not None else default)
    return result
240063
def get_priority(self) -> int:
        
        dtype = self.get_type()
        if dtype & DeltaType.PRE:
            return 1
        elif dtype & DeltaType.POST:
            return 3
        else:
            return 2
148943
def ancestors(self):
    
    ret = []
    workunit = self
    while workunit is not None:
      ret.append(workunit)
      workunit = workunit.parent
    return ret
1345595
def order (self, objects):
        
        # The algorithm used is the same is standard transitive closure,
        # except that we're not keeping in-degree for all vertices, but
        # rather removing edges.
        result = []

        if not objects:
            return result

        constraints = self.__eliminate_unused_constraits (objects)

        # Find some library that nobody depends upon and add it to
        # the 'result' array.
        obj = None
        while objects:
            new_objects = []
            while objects:
                obj = objects [0]

                if self.__has_no_dependents (obj, constraints):
                    # Emulate break ;
                    new_objects.extend (objects [1:])
                    objects = []

                else:
                    new_objects.append (obj)
                    obj = None
                    objects = objects [1:]

            if not obj:
                raise BaseException ("Circular order dependencies")

            # No problem with placing first.
            result.append (obj)

            # Remove all containts where 'obj' comes first,
            # since they are already satisfied.
            constraints = self.__remove_satisfied (constraints, obj)

            # Add the remaining objects for further processing
            # on the next iteration
            objects = new_objects

        return result
1335420
def getTopologicalOrderingOfJobs(self):
        
        ordering = []
        visited = set()
        def getRunOrder(job):
            #Do not add the job to the ordering until all its predecessors have been
            #added to the ordering
            for p in job._directPredecessors:
                if p not in visited:
                    return
            if job not in visited:
                visited.add(job)
                ordering.append(job)
                list(map(getRunOrder, job._children + job._followOns))
        getRunOrder(self)
        return ordering
218074
def list_engines_by_priority(engines=None):
    
    if engines is None:
        engines = ENGINES

    return sorted(engines, key=operator.methodcaller("priority"))
221193
function getPrecedenceList (obj) {
  var precedenceList = []
  var nextObj = obj
  while (nextObj) {
    precedenceList.push(nextObj)
    nextObj = Object.getPrototypeOf(nextObj)
  }
  return precedenceList
}
699307
def get_ordered_children(self):
        
        ordered_keys = self.element.ordered_children if self.element.ordered_children is not None else []
        children = [self.indexes.get(k, None) for k in ordered_keys]
        return children
705434
def defaults(self):
        
        default = self._defaults
        # if require and no default, the first component as default
        if not len(default) and self.required and len(self._components):
            default = [six.next(six.itervalues(self._components)).name]
        return default
1170558
def get_report_order(self):
        ''' 
        '''
        order_list = []
        for x in self.__priority:
            order_list.append([x, self[x]])
        for x in sorted(list(self.keys())):
            if x not in self.__priority:
                order_list.append([x, self[x]])
        return order_list
572135
def _start_priority_containers(self, groups, group_orders, tool_d):
        
        vent_cfg = Template(self.path_dirs.cfg_file)
        cfg_groups = vent_cfg.option('groups', 'start_order')
        if cfg_groups[0]:
            cfg_groups = cfg_groups[1].split(',')
        else:
            cfg_groups = []
        all_groups = sorted(set(groups))
        s_conts = []
        f_conts = []
        # start tools in order of group defined in vent.cfg
        for group in cfg_groups:
            # remove from all_groups because already checked out
            if group in all_groups:
                all_groups.remove(group)
            if group in group_orders:
                for cont_t in sorted(group_orders[group]):
                    if cont_t[1] not in s_conts:
                        s_conts, f_conts = self._start_container(cont_t[1],
                                                                 tool_d,
                                                                 s_conts,
                                                                 f_conts)
        # start tools that haven't been specified in the vent.cfg, if any
        for group in all_groups:
            if group in group_orders:
                for cont_t in sorted(group_orders[group]):
                    if cont_t[1] not in s_conts:
                        s_conts, f_conts = self._start_container(cont_t[1],
                                                                 tool_d,
                                                                 s_conts,
                                                                 f_conts)
        return (s_conts, f_conts)
501097
def precedence(item):
    """"""
    try:
        mro = item.__class__.__mro__
    except AttributeError:
        return PRECEDENCE["Atom"]
    for i in mro:
        n = i.__name__
        if n in PRECEDENCE_FUNCTIONS:
            return PRECEDENCE_FUNCTIONS[n](item)
        elif n in PRECEDENCE_VALUES:
            return PRECEDENCE_VALUES[n]
    return PRECEDENCE["Atom"]
1092204
def orderered_methods(self):
        

        oms = []

        self.methods.reverse()

        if self.main:
            oms = [self.main]

        for m in self.methods:

            if m == self.main:
                continue
            oms.append(m)

        return oms
213715
function (listItemContainers, node) {
        var isOrdered = node.nodeName === 'OL';
        var startIndex = parseInt(node.getAttribute('start'), 10) || 1; // only applicable to ordered lists
        var blocks = (listItemContainers || []).map((listItemContainer, listItemIndex) => {
            var listItemElems = unwrap(listItemContainer);
            var firstListItemElem = listItemElems[0];
            if (firstListItemElem && isTextBlock(firstListItemElem)) {
                let firstListItemPrefix = isOrdered ? `${startIndex + listItemIndex}. ` : `- `;
                firstListItemElem.text = firstListItemPrefix + firstListItemElem.text;
            }
            return listItemElems;
        }).reduce((prevBlocks, listItemBlocks) => {
            return prevBlocks.concat(listItemBlocks);
        }, []);
        return wrap(blocks);
    }
1269668
def build_ordered_cliques(cliques, next_cliques):
    """"""
    def sort_key(clique):
        return -len(clique[1])

    if not cliques:
        return list(sorted(
            list(next_cliques.values())[0].items(),
            key=sort_key))

    ordered_cliques = []
    for _, clique in enumerate(cliques):
        parent, _ = clique

        # If this fork continues
        if parent in next_cliques:
            # Sort the cliques in descending order of the size of the
            # clique, so that the main chain tends to the left
            ordered_cliques.extend(
                sorted(next_cliques[parent].items(), key=sort_key))

        # Else drop it

    return ordered_cliques
768923
def in_order(self) -> Iterator["BSP"]:
        
        if self.children:
            yield from self.children[0].in_order()
            yield self
            yield from self.children[1].in_order()
        else:
            yield self