def _determin_hit(self, pkg_data, ver_spec, flags=None):
        """
        Find a release for a package matching a specified version.
        :param pkg_data: the package information
        :type pkg_data: dict
        :param ver_spec: the version specification
        :type ver_spec: VersionSpecifier
        :param flags: (distribution) options
        :type flags: int or None
        :return: a version matching the specified version
        :rtype: str
        """
        pkg_name = pkg_data['info']['name']
        latest = self._package_latest_release(pkg_data)
        # create a sorted list of versions, newest fist.
        # we manualle  add the  latest release in front to improve the chances of finding
        # the most recent compatible version
        versions = [latest] + _stash.libversion.sort_versions(self._package_releases(pkg_data))
        for hit in versions:
            # we return the fist matching hit, so we should sort the hits by descending version
            if (flags is not None) and not self._dist_flags_allows_release(flags, pkg_data, hit):
                # hit has no source/binary release and is not allowed by dis
                continue
            if not self._release_matches_py_version(pkg_data, hit):
                # hit contains no compatible releases
                continue
            if ver_spec is None or ver_spec.match(hit):
                # version is allowed
                return hit
        else:
            raise PipError('Version not found: {}{}'.format(pkg_name, ver_spec if ver_spec is not None else ""))

        Find a release for a package matching a specified version.
        :param pkg_data: the package information
        :type pkg_data: dict
        :param ver_spec: the version specification
        :type ver_spec: VersionSpecifier
        :param flags: (distribution) options
        :type flags: int or None
        :return: a version matching the specified version
        :rtype: str
        
bin/pip.py