Example #1
0
def _should_cache(
        req,  # type: InstallRequirement
):
    # type: (...) -> Optional[bool]
    """
    Return whether a built InstallRequirement can be stored in the persistent
    wheel cache, assuming the wheel cache is available, and _should_build()
    has determined a wheel needs to be built.
    """
    if req.editable or not req.source_dir:
        # never cache editable requirements
        return False

    if req.link and req.link.is_vcs:
        # VCS checkout. Do not cache
        # unless it points to an immutable commit hash.
        assert not req.editable
        assert req.source_dir
        vcs_backend = vcs.get_backend_for_scheme(req.link.scheme)
        assert vcs_backend
        if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
            return True
        return False

    assert req.link
    base, ext = req.link.splitext()
    if _contains_egg_info(base):
        return True

    # Otherwise, do not cache.
    return False
Example #2
0
    def update_editable(self):

        # type: () -> None

        if not self.link:

            logger.debug(
                "Cannot update repository at %s; repository location is "
                "unknown",
                self.source_dir,
            )

            return

        assert self.editable

        assert self.source_dir

        if self.link.scheme == 'file':

            # Static paths don't get updated

            return

        vcs_backend = vcs.get_backend_for_scheme(self.link.scheme)

        # Editable requirements are validated in Requirement constructors.

        # So here, if it's neither a path nor a valid VCS URL, it's a bug.

        assert vcs_backend, f"Unsupported VCS URL {self.link.url}"

        hidden_url = hide_url(self.link.url)

        vcs_backend.obtain(self.source_dir, url=hidden_url)
Example #3
0
def unpack_vcs_link(link, location):

    # type: (Link, str) -> None

    vcs_backend = vcs.get_backend_for_scheme(link.scheme)

    assert vcs_backend is not None

    vcs_backend.unpack(location, url=hide_url(link.url))
def direct_url_from_link(link: Link,
                         source_dir: Optional[str] = None,
                         link_is_in_wheel_cache: bool = False) -> DirectUrl:
    if link.is_vcs:
        vcs_backend = vcs.get_backend_for_scheme(link.scheme)
        assert vcs_backend
        url, requested_revision, _ = vcs_backend.get_url_rev_and_auth(
            link.url_without_fragment)
        # For VCS links, we need to find out and add commit_id.
        if link_is_in_wheel_cache:
            # If the requested VCS link corresponds to a cached
            # wheel, it means the requested revision was an
            # immutable commit hash, otherwise it would not have
            # been cached. In that case we don't have a source_dir
            # with the VCS checkout.
            assert requested_revision
            commit_id = requested_revision
        else:
            # If the wheel was not in cache, it means we have
            # had to checkout from VCS to build and we have a source_dir
            # which we can inspect to find out the commit id.
            assert source_dir
            commit_id = vcs_backend.get_revision(source_dir)
        return DirectUrl(
            url=url,
            info=VcsInfo(
                vcs=vcs_backend.name,
                commit_id=commit_id,
                requested_revision=requested_revision,
            ),
            subdirectory=link.subdirectory_fragment,
        )
    elif link.is_existing_dir():
        return DirectUrl(
            url=link.url_without_fragment,
            info=DirInfo(),
            subdirectory=link.subdirectory_fragment,
        )
    else:
        hash = None
        hash_name = link.hash_name
        if hash_name:
            hash = f"{hash_name}={link.hash}"
        return DirectUrl(
            url=link.url_without_fragment,
            info=ArchiveInfo(hash=hash),
            subdirectory=link.subdirectory_fragment,
        )
Example #5
0
def should_cache(
        req,  # type: InstallRequirement
        check_binary_allowed,  # type: BinaryAllowedPredicate
):
    # type: (...) -> Optional[bool]
    """
    Return whether a built InstallRequirement can be stored in the persistent
    wheel cache, assuming the wheel cache is available, and should_build()
    has determined a wheel needs to be built.
    """
    if not should_build(
            req, need_wheel=False, check_binary_allowed=check_binary_allowed):
        # never cache if pip install (need_wheel=False) would not have built
        # (editable mode, etc)
        return False

    if req.link and req.link.is_vcs:
        # VCS checkout. Build wheel just for this run
        # unless it points to an immutable commit hash in which
        # case it can be cached.
        assert not req.editable
        assert req.source_dir
        vcs_backend = vcs.get_backend_for_scheme(req.link.scheme)
        assert vcs_backend
        if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
            return True
        return False

    link = req.link
    base, ext = link.splitext()
    if _contains_egg_info(base):
        return True

    # Otherwise, build the wheel just for this run using the ephemeral
    # cache since we are either in the case of e.g. a local directory, or
    # no cache directory is available to use.
    return False
Example #6
0
def test_get_backend_for_scheme():
    assert vcs.get_backend_for_scheme("git+https") is vcs.get_backend("Git")
Example #7
0
        # never cache editable requirements
=======
    if not should_build_for_install_command(
        req, check_binary_allowed=_always_true
    ):
        # never cache if pip install would not have built
        # (editable mode, etc)
>>>>>>> b66a76afa15ab74019740676a52a071b85ed8f71
        return False

    if req.link and req.link.is_vcs:
        # VCS checkout. Do not cache
        # unless it points to an immutable commit hash.
        assert not req.editable
        assert req.source_dir
        vcs_backend = vcs.get_backend_for_scheme(req.link.scheme)
        assert vcs_backend
        if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
            return True
        return False

<<<<<<< HEAD
    assert req.link
=======
>>>>>>> b66a76afa15ab74019740676a52a071b85ed8f71
    base, ext = req.link.splitext()
    if _contains_egg_info(base):
        return True

    # Otherwise, do not cache.
    return False
Example #8
0
def unpack_vcs_link(link: Link, location: str, verbosity: int) -> None:
    vcs_backend = vcs.get_backend_for_scheme(link.scheme)
    assert vcs_backend is not None
    vcs_backend.unpack(location, url=hide_url(link.url), verbosity=verbosity)