def resolve(self, requirements, env=None, installer=None,<EOL>replace_conflicting=False, extras=None):
<EOL>requirements = list(requirements)[::-<NUM_LIT:1>]<EOL>processed = {}<EOL>best = {}<EOL>to_activate = []<EOL>req_extras = _ReqExtras()<EOL>required_by = collections.defaultdict(set)<EOL>while requirements:<EOL><INDENT>req = requirements.pop(<NUM_LIT:0>)<EOL>if req in processed:<EOL><INDENT>continue<EOL><DEDENT>if not req_extras.markers_pass(req, extras):<EOL><INDENT>continue<EOL><DEDENT>dist = best.get(req.key)<EOL>if dist is None:<EOL><INDENT>dist = self.by_key.get(req.key)<EOL>if dist is None or (dist not in req and replace_conflicting):<EOL><INDENT>ws = self<EOL>if env is None:<EOL><INDENT>if dist is None:<EOL><INDENT>env = Environment(self.entries)<EOL><DEDENT>else:<EOL><INDENT>env = Environment([])<EOL>ws = WorkingSet([])<EOL><DEDENT><DEDENT>dist = best[req.key] = env.best_match(<EOL>req, ws, installer,<EOL>replace_conflicting=replace_conflicting<EOL>)<EOL>if dist is None:<EOL><INDENT>requirers = required_by.get(req, None)<EOL>raise DistributionNotFound(req, requirers)<EOL><DEDENT><DEDENT>to_activate.append(dist)<EOL><DEDENT>if dist not in req:<EOL><INDENT>dependent_req = required_by[req]<EOL>raise VersionConflict(dist, req).with_context(dependent_req)<EOL><DEDENT>new_requirements = dist.requires(req.extras)[::-<NUM_LIT:1>]<EOL>requirements.extend(new_requirements)<EOL>for new_requirement in new_requirements:<EOL><INDENT>required_by[new_requirement].add(req.project_name)<EOL>req_extras[new_requirement] = req.extras<EOL><DEDENT>processed[req] = True<EOL><DEDENT>return to_activate<EOL>
List all distributions needed to (recursively) meet `requirements`

        `requirements` must be a sequence of ``Requirement`` objects.  `env`,
        if supplied, should be an ``Environment`` instance.  If
        not supplied, it defaults to all distributions available within any
        entry or distribution in the working set.  `installer`, if supplied,
        will be invoked with each requirement that cannot be met by an
        already-installed distribution; it should return a ``Distribution`` or
        ``None``.

        Unless `replace_conflicting=True`, raises a VersionConflict exception
        if
        any requirements are found on the path that have the correct name but
        the wrong version.  Otherwise, if an `installer` is supplied it will be
        invoked to obtain the correct version of the requirement and activate
        it.

        `extras` is a list of the extras to be used with these requirements.
        This is important because extra requirements may look like `my_req;
        extra = "my_extra"`, which would otherwise be interpreted as a purely
        optional requirement.  Instead, we want to be able to assert that these
        requirements are truly required.