def test_build_dependency_graph_include_ignored_content(self, id_set):
        """
        Given
            - A pack name which depends on unsupported content.
        When
            - Building dependency graph for pack.
        Then
            - Extracting the pack dependencies with unsupported content.
        """

        pack_name = "ImpossibleTraveler"
        found_graph = PackDependencies.build_dependency_graph(
            pack_id=pack_name,
            id_set=id_set,
            verbose_file=VerboseFile(),
            exclude_ignored_dependencies=False)
        root_of_graph = [
            n for n in found_graph.nodes if found_graph.in_degree(n) == 0
        ][0]
        pack_dependencies = [
            n for n in found_graph.nodes if found_graph.in_degree(n) > 0
        ]

        assert root_of_graph == pack_name
        assert len(pack_dependencies) > 0
        assert 'NonSupported' in pack_dependencies
Пример #2
0
def main():
    """ Main function for iterating over existing packs folder in content repo and creating json of all
    packs dependencies. The logic of pack dependency is identical to sdk find-dependencies command.

    """
    option = option_handler()
    output_path = option.output_path
    id_set_path = option.id_set_path
    IGNORED_FILES.append(
        GCPConfig.BASE_PACK)  # skip dependency calculation of Base pack
    # loading id set json
    with open(id_set_path, 'r') as id_set_file:
        id_set = json.load(id_set_file)

    pack_dependencies_result = {}

    print("Starting dependencies calculation")
    # starting iteration over pack folders
    for pack in os.scandir(PACKS_FULL_PATH):
        if not pack.is_dir() or pack.name in IGNORED_FILES:
            print_warning(
                f"Skipping dependency calculation of {pack.name} pack.")
            continue  # skipping ignored packs
        print(f"Calculating {pack.name} pack dependencies.")

        try:
            dependency_graph = PackDependencies.build_dependency_graph(
                pack_id=pack.name,
                id_set=id_set,
                verbose_file=VerboseFile(''),
            )
            first_level_dependencies, all_level_dependencies = parse_for_pack_metadata(
                dependency_graph, pack.name)

        except Exception as e:
            print_error(
                f"Failed calculating {pack.name} pack dependencies. Additional info:\n{e}"
            )
            continue

        pack_dependencies_result[pack.name] = {
            "dependencies": first_level_dependencies,
            "displayedImages": list(first_level_dependencies.keys()),
            "allLevelDependencies": all_level_dependencies,
            "path": os.path.join(PACKS_FOLDER, pack.name),
            "fullPath": pack.path
        }

    print(
        f"Number of created pack dependencies entries: {len(pack_dependencies_result.keys())}"
    )
    # finished iteration over pack folders
    print_color("Finished dependencies calculation", LOG_COLORS.GREEN)

    with open(output_path, 'w') as pack_dependencies_file:
        json.dump(pack_dependencies_result, pack_dependencies_file, indent=4)

    print_color(f"Created packs dependencies file at: {output_path}",
                LOG_COLORS.GREEN)
Пример #3
0
    def test_build_dependency_graph(self, id_set):
        pack_name = "ImpossibleTraveler"
        found_graph = PackDependencies.build_dependency_graph(pack_id=pack_name, id_set=id_set)
        root_of_graph = [n for n in found_graph.nodes if found_graph.in_degree(n) == 0][0]
        pack_dependencies = [n for n in found_graph.nodes if found_graph.in_degree(n) > 0]

        assert root_of_graph == pack_name
        assert len(pack_dependencies) > 0