コード例 #1
0
    def make_found_candidates(
            self,
            candidates,  # type: List[InstallationCandidate]
            specifier=None,  # type: Optional[specifiers.BaseSpecifier]
    ):
        # type: (...) -> FoundCandidates
        """
        Create and return a `FoundCandidates` instance.

        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.
        """
        if specifier is None:
            specifier = specifiers.SpecifierSet()

        # Using None infers from the specifier instead.
        allow_prereleases = self.allow_all_prereleases or None
        versions = {
            str(v)
            for v in specifier.filter(
                # We turn the version object into a str here because otherwise
                # when we're debundled but setuptools isn't, Python will see
                # packaging.version.Version and
                # pkg_resources._vendor.packaging.version.Version as different
                # types. This way we'll use a str as a common data interchange
                # format. If we stop using the pkg_resources provided specifier
                # and start using our own, we can drop the cast to str().
                (str(c.version) for c in candidates),
                prereleases=allow_prereleases,
            )
        }
        return FoundCandidates(candidates, versions=versions, evaluator=self)
コード例 #2
0
ファイル: package_finder.py プロジェクト: uranusjr/pip
    def create(
            cls,
            project_name,  # type: str
            target_python=None,  # type: Optional[TargetPython]
            prefer_binary=False,  # type: bool
            allow_all_prereleases=False,  # type: bool
            specifier=None,  # type: Optional[specifiers.BaseSpecifier]
            hashes=None,  # type: Optional[Hashes]
    ):
        # type: (...) -> CandidateEvaluator
        """Create a CandidateEvaluator object.

        :param target_python: The target Python interpreter to use when
            checking compatibility. If None (the default), a TargetPython
            object will be constructed from the running Python.
        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.
        :param hashes: An optional collection of allowed hashes.
        """
        if target_python is None:
            target_python = TargetPython()
        if specifier is None:
            specifier = specifiers.SpecifierSet()

        supported_tags = target_python.get_tags()

        return cls(
            project_name=project_name,
            supported_tags=supported_tags,
            specifier=specifier,
            prefer_binary=prefer_binary,
            allow_all_prereleases=allow_all_prereleases,
            hashes=hashes,
        )
コード例 #3
0
ファイル: __init__.py プロジェクト: uranusjr/petpeeve
 def handle_starttag(self, tag, attrs):
     if tag != 'a':
         return
     url_parts = None
     python_specifier = packaging_specifiers.SpecifierSet('')
     for attr, value in attrs:
         if attr == 'href':
             url_parts = six.moves.urllib_parse.urlsplit(value)
             replacements = {
                 fn: part
                 for fn, part in zip(url_parts._fields, url_parts)
                 if part or fn == 'fragment'
             }
             url_parts = self.base_url_parts._replace(**replacements)
         elif attr == 'data-requires-python':
             python_specifier = packaging_specifiers.SpecifierSet(value)
     if not url_parts:
         return
     try:
         link = parse_link(url_parts, python_specifier)
     except UnwantedLink:
         return
     self.links.append(link)
コード例 #4
0
ファイル: utils.py プロジェクト: mayeut/drop-python
def requires_python_supports(requires_python, version):
    """
    Check if a given Python version matches the `requires_python` specifier.

    Returns "yes" if the version of Python matches the requirement.
    Returns "no" if the version of Python does not matches the requirement.
    Returns "maybe" if there's no requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None or requires_python == "":
        # The package provides no information
        return "maybe"
    requires_python_specifier = specifiers.SpecifierSet(requires_python)

    return "yes" if version in requires_python_specifier else "no"
コード例 #5
0
def check_requires_python(requires_python):
    """
    Check if the python version in use match the `requires_python` specifier.

    Returns `True` if the version of python in use matches the requirement.
    Returns `False` if the version of python in use does not matches the
    requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    requires_python_specifier = specifiers.SpecifierSet(requires_python)
    # We only use major.minor.micro
    python_version = version.parse('{0}.{1}.{2}'.format(*sys.version_info[:3]))
    return python_version in requires_python_specifier
コード例 #6
0
def check_requires_python(requires_python, version_info):
    # type: (Optional[str], Tuple[int, ...]) -> bool
    """
    Check if the given Python version matches a "Requires-Python" specifier.

    :param version_info: A 3-tuple of ints representing a Python
        major-minor-micro version to check (e.g. `sys.version_info[:3]`).

    :return: `True` if the given Python version satisfies the requirement.
        Otherwise, return `False`.

    :raises InvalidSpecifier: If `requires_python` has an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    requires_python_specifier = specifiers.SpecifierSet(requires_python)
コード例 #7
0
def check_requires_python(requires_python):
    """
    Check if the python version in use match the `requires_python` specifier.

    Returns `True` if the version of python in use matches the requirement.
    Returns `False` if the version of python in use does not matches the
    requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    requires_python_specifier = specifiers.SpecifierSet(requires_python)
    # We only use major.minor.micro
    python_version = version.parse(os.environ['PIP_PYTHON_VERSION'])
    return python_version in requires_python_specifier
コード例 #8
0
ファイル: packaging.py プロジェクト: CaraFJ/concurrency
def check_requires_python(requires_python):
    # type: (Optional[str]) -> bool
    """
    Check if the python version in use match the `requires_python` specifier.

    Returns `True` if the version of python in use matches the requirement.
    Returns `False` if the version of python in use does not matches the
    requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    requires_python_specifier = specifiers.SpecifierSet(requires_python)

    # We only use major.minor.micro
    python_version = version.parse(".".join(map(str, sys.version_info[:3])))
    return python_version in requires_python_specifier
コード例 #9
0
    def find_candidates(
            self,
            project_name,  # type: str
            specifier=specifiers.SpecifierSet(
            ),  # type: specifiers.BaseSpecifier
    ):
        """Find matches for the given project and specifier.

        If given, `specifier` should implement `filter` to allow version
        filtering (e.g. ``packaging.specifiers.SpecifierSet``).

        Returns a `FoundCandidates` instance.
        """
        return FoundCandidates(
            self.find_all_candidates(project_name),
            specifier=specifier,
            prereleases=(self.allow_all_prereleases or None),
            sort_key=self._candidate_sort_key,
        )
コード例 #10
0
ファイル: index.py プロジェクト: murrayrush/pip
    def find_candidates(
            self,
            project_name,  # type: str
            specifier=None,  # type: Optional[specifiers.BaseSpecifier]
    ):
        """Find matches for the given project and specifier.

        If given, `specifier` should implement `filter` to allow version
        filtering (e.g. ``packaging.specifiers.SpecifierSet``).

        Returns a `FoundCandidates` instance.
        """
        if specifier is None:
            specifier = specifiers.SpecifierSet()
        return FoundCandidates.from_specifier(
            self.find_all_candidates(project_name),
            specifier=specifier,
            prereleases=(self.allow_all_prereleases or None),
            evaluator=self.candidate_evaluator,
        )
コード例 #11
0
def check_requires_python(requires_python, version_info):
    # type: (Optional[str], Tuple[int, ...]) -> bool
    """
    Check if the given Python version matches a `requires_python` specifier.

    :param version_info: A 3-tuple of ints representing the Python
        major-minor-micro version to check (e.g. `sys.version_info[:3]`).

    Returns `True` if the version of python in use matches the requirement.
    Returns `False` if the version of python in use does not matches the
    requirement.

    Raises an InvalidSpecifier if `requires_python` have an invalid format.
    """
    if requires_python is None:
        # The package provides no information
        return True
    requires_python_specifier = specifiers.SpecifierSet(requires_python)

    python_version = version.parse('.'.join(map(str, version_info)))
    return python_version in requires_python_specifier
コード例 #12
0
def version_in_requires_python(requires_python, python_version):
    if requires_python is None:
        return False
    spec = specifiers.SpecifierSet(requires_python)
    return python_version in spec