def group_imports(imports, module_name):
    groups = []

    package_group = module_name[0:3]
    package = module_name[0:module_name.index('_')]

    # grab future imports
    current_group = [i.module for i in imports if i.is_future]

    # merge with required future imports
    current_group = list(set(current_group) | _REQUIRED_FUTURE_IMPORTS)

    # grab the names of the modules into a new list
    imports = [i.module for i in imports]

    push_current_future_group(groups, current_group, imports)

    # grab standard library imports
    current_group = [i for i in imports if '_' not in i]
    push_current_group(groups, current_group, imports)

    # grab external deps
    current_group = [i for i in imports if not i.startswith(package_group)]
    push_current_group(groups, current_group, imports)

    # grab same group, different package deps
    current_group = [i for i in imports if not i.startswith(package)]
    push_current_group(groups, current_group, imports)

    # grab same package deps
    current_group = [i for i in imports if i.startswith(package)]
    push_current_group(groups, current_group, imports)

    # nothing should be left over
    assert not imports

    return groups
dataset/ETHPy150Open bloomberg/phabricator-tools/meta/autofix/fiximports.py/group_imports/original