def write_requirements(
    sources=None, fixed_requirements=None, output_file=None, skip=None
):
    """
    Write resulting requirements taking versions from the fixed_requirements.
    """
    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:
        if hasattr(req, "requirement"):
            parsedreq = parse_req_from_line(req.requirement, req.line_source)
            project_name = parsedreq.requirement.name

            if not req.requirement:
                continue
        else:
            project_name = req.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 hasattr(req, "requirement"):
            parsedreq = parse_req_from_line(req.requirement, req.line_source)
            project_name = parsedreq.requirement.name
            linkreq = parsedreq
        else:
            project_name = req.name
            linkreq = req
        if project_name in skip:
            continue

        # we don't have any idea how to process links, so just add them
        if linkreq.link and linkreq.link not in links:
            links.add(linkreq.link)
            if hasattr(req, "req") and req.req and str(req.req).count("@") == 2:
                # PEP 440 direct reference
                rline = str(linkreq.req)
                # Also write out environment markers
                if linkreq.markers:
                    rline += " ; {}".format(str(linkreq.markers))
            else:
                rline = str(linkreq.link)

            if (hasattr(req, "is_editable") and req.is_editable) or (
                hasattr(req, "editable") and req.editable
            ):
                rline = "-e %s" % (rline)
        elif hasattr(req, "requirement") and req.requirement:
            project = parsedreq.requirement.name
            req_obj = fixedreq_hash.get(project, req)

            rline = str(req_obj.requirement)

            # Markers are included in req_obj.requirement, so no
            # special processing required
        elif hasattr(req, "req") and req.req:
            project = req.name
            req_obj = fixedreq_hash.get(project, req)

            rline = str(req_obj.req)
            # Also write out environment markers
            if req_obj.markers:
                rline += " ; {}".format(str(req_obj.markers))

        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(
            "# If you want to update global dependencies, modify fixed-requirements.txt\n"
        )
        fp.write(
            "# and then run 'make requirements' to update requirements.txt for all\n"
        )
        fp.write("# components.\n")
        fp.write(
            "# If you want to update depdencies for a single component, modify the\n"
        )
        fp.write(
            "# in-requirements.txt for that component and then run 'make requirements' to\n"
        )
        fp.write("# update the component requirements.txt\n")
        fp.write(data)

    print("Requirements written to: {0}".format(output_file))

    Write resulting requirements taking versions from the fixed_requirements.
    
scripts/fixate-requirements.py