@staticmethod
def generate(config, spec):
    """Generate Python virtualenv content."""
    spec.macros['venv_cmd'] = '{0} {1}'.format(config.python_venv.cmd, ' '.
        join(config.python_venv.flags if config.python_venv.flags else ()))
    if config.python_venv.python:
        spec.macros['venv_cmd'] = '{0} --python={1}'.format(spec.macros[
            'venv_cmd'], config.python_venv.python)
    spec.macros['venv_name'] = config.python_venv.name
    spec.macros['venv_install_dir'] = '{0}/%{{venv_name}}'.format(config.
        python_venv.path)
    spec.macros['venv_dir'] = '%{buildroot}/%{venv_install_dir}'
    spec.macros['venv_bin'] = '%{venv_dir}/bin'
    spec.macros['venv_python'] = '%{venv_bin}/python'
    spec.macros['venv_pip'
        ] = '%{{venv_python}} %{{venv_bin}}/pip install {0}'.format(' '.
        join(config.python_venv.pip_flags if config.python_venv.pip_flags else
        ()))
    spec.macros['__prelink_undo_cmd'] = '%{nil}'
    spec.globals['__os_install_post'] = (
        "%(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')"
        )
    spec.tags['AutoReq'] = 'No'
    spec.tags['AutoProv'] = 'No'
    spec.blocks.prep.append('mkdir -p %{buildroot}/%{venv_install_dir}')
    spec.blocks.files.append('/%{venv_install_dir}')
    spec.blocks.install.append('%{venv_cmd} %{venv_dir}')
    for requirement in config.python_venv.requirements:
        spec.blocks.install.extend(('cd %{SOURCE0}', '%{{venv_pip}} -r {0}'
            .format(requirement), 'cd -'))
    if config.python_venv.require_setup_py:
        spec.blocks.install.append('cd %{SOURCE0}')
        if config.python_venv.use_pip_install:
            spec.blocks.install.append('%{venv_pip} .')
        else:
            spec.blocks.install.append('%{venv_python} setup.py install')
        spec.blocks.install.append('cd -')
    if config.python_venv.remove_pycache:
        spec.blocks.install.append(
            'find %{venv_dir} -type d -name "__pycache__" -print0 | xargs -0 rm -rf'
            )
    spec.blocks.install.extend((
        '# RECORD files are used by wheels for checksum. They contain path names which'
        ,
        '# match the buildroot and must be removed or the package will fail to build.'
        , 'find %{buildroot} -name "RECORD" -exec rm -rf {} \\;',
        '# Change the virtualenv path to the target installation direcotry.',
        'venvctrl-relocate --source=%{venv_dir} --destination=/%{venv_install_dir}'
        ))
    if config.python_venv.strip_binaries:
        spec.blocks.install.extend((
            '# Strip native modules as they contain buildroot paths intheir debug information'
            , 'find %{venv_dir}/lib -type f -name "*.so" | xargs -r strip'))
    return spec
