Beispiel #1
0
 def _link_sort_key(self, link_tuple):
     """
     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()
       3. source archives
     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
     """
     parsed_version, link, _ = link_tuple
     if self.use_wheel:
         support_num = len(supported_tags)
         if link == INSTALLED_VERSION:
             pri = 1
         elif link.ext == wheel_ext:
             wheel = Wheel(link.filename)  # can raise InvalidWheelFilename
             if not wheel.supported():
                 raise UnsupportedWheel(
                     "%s is not a supported wheel for this platform. It can't be sorted."
                     % wheel.filename)
             pri = -(wheel.support_index_min())
         else:  # sdist
             pri = -(support_num)
         return (parsed_version, pri)
     else:
         return parsed_version
Beispiel #2
0
 def _candidate_sort_key(self, candidate):
     """
     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
     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
     """
     support_num = len(self.valid_tags)
     if candidate.location.is_wheel:
         # can raise InvalidWheelFilename
         wheel = Wheel(candidate.location.filename)
         if not wheel.supported(self.valid_tags):
             raise UnsupportedWheel(
                 "%s is not a supported wheel for this platform. It "
                 "can't be sorted." % wheel.filename)
         pri = -(wheel.support_index_min(self.valid_tags))
     else:  # sdist
         pri = -(support_num)
     return (candidate.version, pri)
Beispiel #3
0
 def _link_sort_key(self, link_tuple):
     """
     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()
       3. source archives
     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
     """
     parsed_version, link, _ = link_tuple
     if self.use_wheel:
         support_num = len(supported_tags)
         if link == INSTALLED_VERSION:
             pri = 1
         elif link.ext == wheel_ext:
             wheel = Wheel(link.filename)  # can raise InvalidWheelFilename
             if not wheel.supported():
                 raise UnsupportedWheel(
                     "%s is not a supported wheel for this platform. It "
                     "can't be sorted." % wheel.filename
                 )
             pri = -(wheel.support_index_min())
         else:  # sdist
             pri = -(support_num)
         return (parsed_version, pri)
     else:
         return parsed_version
Beispiel #4
0
 def _candidate_sort_key(self, candidate):
     """
     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()
       3. source archives
     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
     """
     support_num = len(supported_tags)
     if candidate.location.is_wheel:
         # can raise InvalidWheelFilename
         wheel = Wheel(candidate.location.filename)
         if not wheel.supported():
             raise UnsupportedWheel(
                 "%s is not a supported wheel for this platform. It "
                 "can't be sorted." % wheel.filename
             )
         pri = -(wheel.support_index_min())
     else:  # sdist
         pri = -(support_num)
     return (candidate.version, pri)
Beispiel #5
0
    def cached_wheel(self, link, package_name):
        not_cached = (not self._cache_dir or not link or link.is_wheel
                      or not link.is_artifact or not package_name)

        if not_cached:
            return link

        canonical_name = canonicalize_name(package_name)
        formats = pip.index.fmt_ctl_formats(self._format_control,
                                            canonical_name)
        if "binary" not in formats:
            return link
        root = self.get_cache_path_for_link(link)
        try:
            wheel_names = os.listdir(root)
        except OSError as err:
            if err.errno in {errno.ENOENT, errno.ENOTDIR}:
                return link
            raise
        candidates = []
        for wheel_name in wheel_names:
            try:
                wheel = Wheel(wheel_name)
            except InvalidWheelFilename:
                continue
            if not wheel.supported():
                # Built for a different python/arch/etc
                continue
            candidates.append((wheel.support_index_min(), wheel_name))
        if not candidates:
            return link
        candidates.sort()
        path = os.path.join(root, candidates[0][1])
        return pip.index.Link(path_to_url(path))
Beispiel #6
0
    def get(self, link, package_name):
        candidates = []

        for wheel_name in self._get_candidates(link, package_name):
            try:
                wheel = Wheel(wheel_name)
            except InvalidWheelFilename:
                continue
            if not wheel.supported():
                # Built for a different python/arch/etc
                continue
            candidates.append((wheel.support_index_min(), wheel_name))

        if not candidates:
            return link

        return self._link_for_candidate(link, min(candidates)[1])
Beispiel #7
0
    def get(self, link, package_name):
        candidates = []

        for wheel_name in self._get_candidates(link, package_name):
            try:
                wheel = Wheel(wheel_name)
            except InvalidWheelFilename:
                continue
            if not wheel.supported():
                # Built for a different python/arch/etc
                continue
            candidates.append((wheel.support_index_min(), wheel_name))

        if not candidates:
            return link

        return self._link_for_candidate(link, min(candidates)[1])