Return an attribute from a dotted path name (e.g. "path.to.func").

def import_attribute(name):
    """Return an attribute from a dotted path name (e.g. "path.to.func")."""
    try:
        sep = ':' if ':' in name else '.'  # For backwards compatibility
        module_name, attribute = name.rsplit(sep, 1)
        module = importlib.import_module(module_name)
        return operator.attrgetter(attribute)(module)
    except (ValueError, ImportError, AttributeError) as e:
        raise TaskImportError(e)