def get_primary_variable(variable):
    """If :obj:`variable` is distributed, returns the primary component."""
    for attribute_name in ('primary', '_primary'):
        attribute = getattr(variable, attribute_name, None)
        if attribute is not None:
            return attribute
    return variable
