def neglect_submodule_templates()

in taskcat/_common_utils.py [0:0]


def neglect_submodule_templates(project_root, template_list):
    template_dict = {}
    # one template object per path.
    for template in template_list:
        template_dict[template.template_path] = template
        for template_descendent in template.descendents:
            template_dict[template_descendent.template_path] = template_descendent

    # Removing those within a submodule.
    submodule_path_prefixes = []
    try:
        gitmodule_config = ConfigFile.from_path(Path(project_root / ".gitmodules"))
    except FileNotFoundError:
        return template_list

    for submodule_path, _, _ in parse_submodules(gitmodule_config):
        submodule_path_prefixes.append(
            Path(project_root / submodule_path.decode("utf-8"))
        )

    finalized_templates = []
    for template_obj in list(template_dict.values()):
        gitmodule_template = False
        for gm_path in submodule_path_prefixes:
            if gm_path in template_obj.template_path.parents:
                gitmodule_template = True
        if not gitmodule_template:
            finalized_templates.append(template_obj)
    return finalized_templates