def render_spec_file(spec_file, defines):
    """
    Apply the defines to the spec file. We don't use `--define` because
    `mock`'s `--rpmbuild-opts` doesn't apply to `--buildsrpm`

    Returns the path to the rendered spec file
    """
    with open(spec_file) as f:
        spec_content = f.read()

    for k, v in defines.items():
        spec_content = spec_content.replace('%{' + k + '}', v)

    spec_file_out = spec_file.replace('.spec', '.rendered.spec')
    with open(spec_file_out, 'w') as f:
        f.write(spec_content)

    return spec_file_out