code: def sort(self):
          if self.sorted:
              return
          def key(variant):
              requested_key = []
              names = set()
              for i, request in enumerate(self.solver.request_list):
                  if not request.conflict:
                      req = variant.requires_list.get(request.name)
                      if req is not None:
                          requested_key.append((-i, req.range))
                          names.add(req.name)
              additional_key = []
              for request in variant.requires_list:
                  if not request.conflict and request.name not in names:
                      additional_key.append((request.range, request.name))
              if (VariantSelectMode[config.variant_select_mode] ==
                      VariantSelectMode.version_priority):
                  k = (requested_key,
                       -len(additional_key),
                       additional_key,
                       variant.index)
              else:
                  k = (len(requested_key),
                       requested_key,
                       -len(additional_key),
                       additional_key,
                       variant.index)
              return k
          self.variants.sort(key=key, reverse=True)
          self.sorted = True