Exemple #1
0
    def _get_linked_req_hashes(self, req: InstallRequirement) -> Hashes:
        # By the time this is called, the requirement's link should have
        # been checked so we can tell what kind of requirements req is
        # and raise some more informative errors than otherwise.
        # (For example, we can raise VcsHashUnsupported for a VCS URL
        # rather than HashMissing.)
        if not self.require_hashes:
            return req.hashes(trust_internet=True)

        # We could check these first 2 conditions inside unpack_url
        # and save repetition of conditions, but then we would
        # report less-useful error messages for unhashable
        # requirements, complaining that there's no hash provided.
        if req.link.is_vcs:
            raise VcsHashUnsupported()
        if req.link.is_existing_dir():
            raise DirectoryUrlHashUnsupported()

        # Unpinned packages are asking for trouble when a new version
        # is uploaded.  This isn't a security check, but it saves users
        # a surprising hash mismatch in the future.
        # file:/// URLs aren't pinnable, so don't complain about them
        # not being pinned.
        if req.original_link is None and not req.is_pinned:
            raise HashUnpinned()

        # If known-good hashes are missing for this requirement,
        # shim it with a facade object that will provoke hash
        # computation and then raise a HashMissing exception
        # showing the user what the hash should be.
        return req.hashes(trust_internet=False) or MissingHashes()
Exemple #2
0
 def __and__(self, other: InstallRequirement) -> "Constraint":
     if not isinstance(other, InstallRequirement):
         return NotImplemented
     specifier = self.specifier & other.specifier
     hashes = self.hashes & other.hashes(trust_internet=False)
     links = self.links
     if other.link:
         links = links.union([other.link])
     return Constraint(specifier, hashes, links)
Exemple #3
0
 def from_ireq(cls, ireq: InstallRequirement) -> "Constraint":
     links = frozenset([ireq.link]) if ireq.link else frozenset()
     return Constraint(ireq.specifier, ireq.hashes(trust_internet=False),
                       links)