def write_requirements(sources=None, fixed_requirements=None, output_file=None,
                       skip=None):
    skip = skip or []

    requirements = merge_source_requirements(sources)
    fixed = load_requirements(locate_file(fixed_requirements, must_exist=True))

    # Make sure there are no duplicate / conflicting definitions
    fixedreq_hash = {}
    for req in fixed:
        project_name = req.req.project_name

        if not req.req:
            continue

        if project_name in fixedreq_hash:
            raise ValueError('Duplicate definition for dependency "%s"' % (project_name))

        fixedreq_hash[project_name] = req

    lines_to_write = []
    links = set()
    for req in requirements:
        if req.req.project_name in skip:
            continue

        # we don't have any idea how to process links, so just add them
        if req.link and req.link not in links:
            links.add(req.link)
            rline = str(req.link)
        elif req.req:
            project = req.req.project_name
            if project in fixedreq_hash:
                rline = str(fixedreq_hash[project].req)
            else:
                rline = str(req.req)

        lines_to_write.append(rline)

    # Sort the lines to guarantee a stable order
    lines_to_write = sorted(lines_to_write)
    data = '\n'.join(lines_to_write) + '\n'
    with open(output_file, 'w') as fp:
        fp.write('# Don\'t edit this file. It\'s generated automatically!\n')
        fp.write(data)

    print('Requirements written to: {0}'.format(output_file))
Write resulting requirements taking versions from the fixed_requirements.
dataset/ETHPy150Open StackStorm/st2/scripts/fixate-requirements.py/write_requirements