Return buildout parts matching the given query

def get_buildout_parts(buildout, query=None):
    """Return buildout parts matching the given query
    """
    parts = names = (buildout['buildout'].get('parts') or '').split('\n')
    for name in names:
        part = buildout.get(name) or {}
        for key, value in (query or {}).items():
            if value not in (part.get(key) or ''):
                parts.remove(name)
                break
    return parts