def _update_init_all(module_path, r):
    """Add or update __all__ in __init__.py file."""
    module_dir_path = os.path.split(module_path)[0]
    module_list = []
    for item_name in os.listdir(module_dir_path):
        item_path = os.path.join(module_dir_path, item_name)
        if os.path.isfile(item_path) and item_name in ('__init__.py', 'setup.py'):
            continue
        if os.path.isfile(item_path) and not item_name.endswith('.py'):
            continue
        # if os.path.isdir(item_path) and not os.path.isfile(
        #     os.path.join(item_path, '__init__.py')
        # ):
        #   continue
        if os.path.isdir(item_path):
            continue
        module_list.append(re.sub(r'.py$', '', item_name).encode('utf-8'))
    module_literal_str = str(sorted(module_list))

    assignment_node_list = r('AssignmentNode', recursive=False)
    for n in assignment_node_list:
        if n.type == 'assignment' and n.target.value == '__all__':
            n.value = module_literal_str
            break
    else:
        r.node_list.append(
            redbaron.RedBaron('__all__ = {}\n'.format(module_literal_str))
        )
    return r
Add or update __all__ in __init__.py file.