def trace_requirements(requirements):
requirements = tuple(pretty_req(r) for r in requirements)<EOL>working_set = fresh_working_set()<EOL>from collections import deque<EOL>queue = deque(requirements)<EOL>queued = {_package_req_to_pkg_resources_req(req.req) for req in queue}<EOL>errors = []<EOL>result = []<EOL>while queue:<EOL><INDENT>req = queue.popleft()<EOL>logger.debug('<STR_LIT>', req)<EOL>try:<EOL><INDENT>dist = working_set.find_normalized(_package_req_to_pkg_resources_req(req.req))<EOL><DEDENT>except pkg_resources.VersionConflict as conflict:<EOL><INDENT>dist = conflict.args[<NUM_LIT:0>]<EOL>errors.append('<STR_LIT>'.format(<EOL>dist, timid_relpath(dist.location), req<EOL>))<EOL><DEDENT>assert dist is not None, '<STR_LIT>'<EOL>result.append(dist_to_req(dist))<EOL>extras = [extra for extra in req.extras if extra in dist.extras]<EOL>for sub_req in sorted(dist.requires(extras=extras), key=lambda req: req.key):<EOL><INDENT>sub_req = InstallRequirement(sub_req, req)<EOL>if req_cycle(sub_req):<EOL><INDENT>logger.warning('<STR_LIT>', sub_req)<EOL>continue<EOL><DEDENT>elif sub_req.req in queued:<EOL><INDENT>logger.debug('<STR_LIT>', sub_req)<EOL>continue<EOL><DEDENT>else:<EOL><INDENT>logger.debug('<STR_LIT>', sub_req)<EOL>queue.append(sub_req)<EOL>queued.add(sub_req.req)<EOL><DEDENT><DEDENT><DEDENT>if errors:<EOL><INDENT>raise InstallationError('<STR_LIT:\n>'.join(errors))<EOL><DEDENT>return result<EOL>
given an iterable of pip InstallRequirements,
    return the set of required packages, given their transitive requirements.