def find_src_root(metadata):
    """
    Determine source root from src_root or package_dir key.
    Replace package_dir in metadata with src_root.
    Only understands a single root.
    """
    src_root = ''
    if 'package_dir' in metadata:
        try:
            src_root = metadata['package_dir']['']
            del metadata['package_dir']
        except KeyError:
            raise ValueError(
                'Need package_dir mapping "" to a single directory')
    elif 'src_root' in metadata:
        src_root = metadata['src_root']
    metadata['src_root'] = src_root or ''
    return src_root
