Esempio n. 1
0
def test_merge_requirements(r1, r2, exp):
    req1, req2 = pkg_resources.parse_requirements((r1, r2))
    if isinstance(exp, type) and Exception in exp.__bases__:
        with pytest.raises(exp):
            dependency.merge_requirements(req1, req2)
    else:
        assert dependency.merge_requirements(req1, req2).hashCmp == parse_req(exp).hashCmp
def test_merge_requirements(r1, r2, exp):
    req1, req2 = pkg_resources.parse_requirements((r1, r2))
    if isinstance(exp, type) and Exception in exp.__bases__:
        with pytest.raises(exp):
            dependency.merge_requirements(req1, req2)
    else:
        assert dependency.merge_requirements(req1, req2).hashCmp == parse_req(exp).hashCmp
Esempio n. 3
0
    def check_previous_requirement(self, req, dist, prev_req):
        log.debug(" -- checking previously found requirements: %s vs %s",
                  prev_req, req)
        # Here is where we can possibly backtrack in our graph walking.

        # We need to check if we can merge the new requirement with ones
        # that we found previously. This merging is done on the rules of
        # specificity - ie, creating a new requirement that is bounded
        # by the most specific specs from both old and new.
        try:
            merged_req = dependency.merge_requirements(prev_req, req)
        except dependency.CannotMergeError:
            log.debug(" --- cannot merge requirements")
            raise VersionConflict(pkg_resources.VersionConflict(dist, req),
                                  self.ws, prev_req, self.best, self.req_graph)
        log.debug(" --- merged requirement: %s" % merged_req)

        if dist is None:
            log.debug(' --- purging unsatisfied requirement %s' % prev_req)
            self.purge_req(prev_req)
            return None, merged_req

        log.debug(' --- already have dist: %r' % dist)
        if not self.use_existing and all(op != '=='
                                         for op, _ in merged_req.specs):
            avail = next((dist
                          for dist in self.installer._satisfied(merged_req)
                          if dist is not None), None)
            if avail is not None and avail != dist:
                # There is a better version available; use it.
                log.debug(' --- upgrading %r to %r' % (dist, avail))
                self.backout_requirement(prev_req)
                dist = self._get_dist(merged_req)

        if prev_req.hashCmp in (req.hashCmp, merged_req.hashCmp):
            # The req is the same as one we know about; probably it was in the
            # original working set.
            log.debug(
                " --- prev req {0} was more specific, ignoring {1}".format(
                    prev_req, req))
            return dist, None

        if dist in merged_req:
            # The dist we've already picked matches the more new req
            log.debug(" --- upgrading to more specific requirement %s -> %s",
                      prev_req, merged_req)

            # Add a new node in our graph for the merged requirement.
            self.req_graph.add_node(merged_req)
            for i in self.req_graph.successors(prev_req):
                log.debug(" ---- adding edge from %s to %s" % (merged_req, i))
                self.req_graph.add_edge(merged_req, i)
            return dist, merged_req

        # The dist doesn't match, back it out and send the merged req back for
        # another pass.
        log.debug(" *** overriding requirement %r with %r" % (prev_req, req))
        self.backout_requirement(prev_req)
        return None, merged_req
Esempio n. 4
0
    def check_previous_requirement(self, req, dist, prev_req):
        log.debug(" -- checking previously found requirements: %s vs %s",
                  prev_req, req)
        # Here is where we can possibly backtrack in our graph walking.

        # We need to check if we can merge the new requirement with ones
        # that we found previously. This merging is done on the rules of
        # specificity - ie, creating a new requirement that is bounded
        # by the most specific specs from both old and new.
        try:
            merged_req = dependency.merge_requirements(prev_req, req)
        except dependency.CannotMergeError:
            log.debug(" --- cannot merge requirements")
            raise VersionConflict(pkg_resources.VersionConflict(dist, req),
                                  self.ws, prev_req, self.best, self.req_graph)
        log.debug(" --- merged requirement: %s" % merged_req)

        if dist is None:
            log.debug(' --- purging unsatisfied requirement %s' % prev_req)
            self.purge_req(prev_req)
            return None, merged_req

        log.debug(' --- already have dist: %r' % dist)
        if not self.use_existing and all(op != '=='
                                         for op, _ in merged_req.specs):
            avail = next((dist
                          for dist in self.installer._satisfied(merged_req)
                          if dist is not None), None)
            if avail is not None and avail != dist:
                # There is a better version available; use it.
                log.debug(' --- upgrading %r to %r' % (dist, avail))
                self.backout_requirement(prev_req)
                dist = self._get_dist(merged_req)

        if prev_req.hashCmp in (req.hashCmp, merged_req.hashCmp):
            # The req is the same as one we know about; probably it was in the
            # original working set.
            log.debug(" --- prev req {0} was more specific, ignoring {1}"
                      .format(prev_req, req))
            return dist, None

        if dist in merged_req:
            # The dist we've already picked matches the more new req
            log.debug(" --- upgrading to more specific requirement %s -> %s",
                      prev_req, merged_req)

            # Add a new node in our graph for the merged requirement.
            self.req_graph.add_node(merged_req)
            for i in self.req_graph.successors(prev_req):
                log.debug(" ---- adding edge from %s to %s" % (merged_req, i))
                self.req_graph.add_edge(merged_req, i)
            return dist, merged_req

        # The dist doesn't match, back it out and send the merged req back for
        # another pass.
        log.debug(" *** overriding requirement %r with %r" % (prev_req, req))
        self.backout_requirement(prev_req)
        return None, merged_req