def get_module_group_and_associate_object()

in modular_api/index.py [0:0]


def get_module_group_and_associate_object() -> None:
    modules_path = Path(__file__).parent.resolve() / MODULES_PATH
    global MODULE_GROUP_GROUP_OBJECT_MAPPING
    for module in os.listdir(modules_path):
        module_api_config = os.path.join(modules_path, module,
                                         API_MODULE_FILE)
        with open(module_api_config) as file:
            api_config = json.load(file)

        module_path = os.path.join(modules_path, module)
        if module_path not in sys.path:
            sys.path.append(module_path)

        cli_path = api_config['cli_path']
        mount_point = api_config['mount_point']

        command_group_path = os.path.join(modules_path, module,
                                          *cli_path.split('/'))
        listdir = get_file_names_which_contains_admin_commands(
            path_to_scan=command_group_path)
        for command_group in listdir:
            group_full_name_list, group_name = resolve_group_name(
                group_file=command_group)
            is_private_group = (type(group_full_name_list) == list and
                                group_full_name_list[0] == 'private' or
                                group_full_name_list == 'private')

            group_full_name = '/'.join(group_full_name_list) \
                if type(group_full_name_list) == list else group_full_name_list
            if is_private_group ^ SP.env.is_private_mode_enabled():
                continue
            group_path = get_group_path(mount_point=mount_point,
                                        group_name=group_full_name)
            module_spec = importlib.util.spec_from_file_location(
                group_full_name,
                os.path.join(command_group_path, command_group))
            imported_module = importlib.util.module_from_spec(module_spec)
            module_spec.loader.exec_module(imported_module)
            MODULE_GROUP_GROUP_OBJECT_MAPPING.update(
                {group_path: imported_module})