def _candidate_sort_key(self, candidate, ignore_compatibility=True):<EOL>
support_num = len(self.valid_tags)<EOL>build_tag = tuple()  <EOL>binary_preference = <NUM_LIT:0><EOL>if candidate.location.is_wheel:<EOL><INDENT>wheel = Wheel(candidate.location.filename)<EOL>if not wheel.supported(self.valid_tags) and not ignore_compatibility:<EOL><INDENT>raise UnsupportedWheel(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % wheel.filename<EOL>)<EOL><DEDENT>if self.prefer_binary:<EOL><INDENT>binary_preference = <NUM_LIT:1><EOL><DEDENT>tags = self.valid_tags if not ignore_compatibility else None<EOL>try:<EOL><INDENT>pri = -(wheel.support_index_min(tags=tags))<EOL><DEDENT>except TypeError:<EOL><INDENT>pri = -(support_num)<EOL><DEDENT>if wheel.build_tag is not None:<EOL><INDENT>match = re.match(r'<STR_LIT>', wheel.build_tag)<EOL>build_tag_groups = match.groups()<EOL>build_tag = (int(build_tag_groups[<NUM_LIT:0>]), build_tag_groups[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>pri = -(support_num)<EOL><DEDENT>return (binary_preference, candidate.version, build_tag, pri)<EOL>
Function used to generate link sort key for link tuples.
The greater the return value, the more preferred it is.
If not finding wheels, then sorted by version only.
If finding wheels, then the sort order is by version, then:
  1. existing installs
  2. wheels ordered via Wheel.support_index_min(self.valid_tags)
  3. source archives
If prefer_binary was set, then all wheels are sorted above sources.
Note: it was considered to embed this logic into the Link
      comparison operators, but then different sdist links
      with the same version, would have to be considered equal