def workspace_info()

in lib/ramble/ramble/cmd/workspace.py [0:0]


def workspace_info(args):
    ws = ramble.cmd.require_active_workspace(cmd_name="workspace info")

    # Enable verbose mode
    if args.verbose >= 1:
        args.software = True
        args.tags = True
        args.templates = True

    if args.verbose >= 2:
        args.expansions = True
        args.phases = True

    color.cprint(rucolor.section_title("Workspace: ") + ws.name)
    color.cprint("")
    color.cprint(rucolor.section_title("Location: ") + ws.path)

    # Print workspace templates that currently exist
    if args.templates:
        color.cprint("")
        color.cprint(rucolor.section_title("Workspace Templates:"))
        for template, _ in ws.all_templates():
            color.cprint("    %s" % template)

    # Print workspace variables information
    workspace_vars = ws.get_workspace_vars()

    ws.software_environments = ramble.software_environments.SoftwareEnvironments(ws)
    software_environments = ws.software_environments

    # Build experiment set
    experiment_set = ws.build_experiment_set()

    if args.tags:
        color.cprint("")
        all_tags = experiment_set.all_experiment_tags()
        color.cprint(rucolor.section_title("All experiment tags:"))
        color.cprint(colified(all_tags, indent=4))

    # Print experiment information
    # We built a "print_experiment_set" to access the scopes of variables for each
    # experiment, rather than having merged scopes as we do in the base experiment_set.
    # The base experiment_set is used to list *all* experiments.
    all_pipelines = {}
    color.cprint("")
    color.cprint(rucolor.section_title("Experiments:"))
    for workloads, application_context in ws.all_applications():
        for experiments, workload_context in ws.all_workloads(workloads):
            for _, experiment_context in ws.all_experiments(experiments):
                print_experiment_set = ramble.experiment_set.ExperimentSet(ws)
                print_experiment_set.set_application_context(application_context)
                print_experiment_set.set_workload_context(workload_context)
                print_experiment_set.set_experiment_context(experiment_context)
                print_experiment_set.build_experiment_chains()

                # Reindex the experiments in the print set to match the overall set
                for exp_name, print_app_inst, _ in print_experiment_set.all_experiments():
                    app_inst = experiment_set.get_experiment(exp_name)
                    experiment_index = app_inst.expander.expand_var_name(
                        app_inst.keywords.experiment_index
                    )

                    print_app_inst.define_variable(
                        print_app_inst.keywords.experiment_index, experiment_index
                    )

                print_header = True
                # Define variable printing groups.
                var_indent = "        "
                var_group_names = [
                    rucolor.config_title("Config"),
                    rucolor.section_title("Workspace"),
                    rucolor.nested_1("Application"),
                    rucolor.nested_2("Workload"),
                    rucolor.nested_3("Experiment"),
                ]
                header_base = rucolor.nested_4("Variables from")
                config_vars = ramble.config.config.get("config:variables")

                # Construct filters here...
                filters = ramble.filters.Filters(
                    phase_filters=[],
                    include_where_filters=args.where,
                    exclude_where_filters=args.exclude_where,
                    tags=args.filter_tags,
                )

                for exp_name, _, _ in print_experiment_set.filtered_experiments(filters):
                    app_inst = experiment_set.get_experiment(exp_name)
                    if app_inst.package_manager is not None:
                        software_environments.render_environment(
                            app_inst.expander.expand_var("{env_name}"),
                            app_inst.expander,
                            app_inst.package_manager,
                            require=app_inst.package_manager.requires_software_environment,
                        )
                        # Track this env as used, for printing purposes
                        software_environments.use_environment(
                            app_inst.package_manager, app_inst.expander.expand_var("{env_name}")
                        )

                    if print_header:
                        color.cprint(
                            rucolor.nested_1("  Application: ") + application_context.context_name
                        )
                        color.cprint(
                            rucolor.nested_2("    Workload: ") + workload_context.context_name
                        )
                        print_header = False

                    # Aggregate pipeline phases
                    for pipeline in app_inst._pipelines:
                        if pipeline not in all_pipelines:
                            all_pipelines[pipeline] = set()
                        for phase in app_inst.get_pipeline_phases(pipeline):
                            all_pipelines[pipeline].add(phase)

                    experiment_index = app_inst.expander.expand_var_name(
                        app_inst.keywords.experiment_index
                    )

                    if app_inst.is_template:
                        color.cprint(
                            rucolor.nested_3(f"      Template Experiment {experiment_index}: ")
                            + exp_name
                        )
                    elif app_inst.repeats.is_repeat_base:
                        color.cprint(
                            rucolor.nested_3(f"      Repeat Base Experiment {experiment_index}: ")
                            + exp_name
                        )
                    else:
                        color.cprint(
                            rucolor.nested_3(f"      Experiment {experiment_index}: ") + exp_name
                        )

                    if args.tags:
                        color.cprint("        Experiment Tags: " + str(app_inst.experiment_tags))

                    if args.expansions:
                        var_groups = [
                            config_vars,
                            workspace_vars,
                            application_context.variables,
                            workload_context.variables,
                            experiment_context.variables,
                        ]

                        # Print each group that has variables in it
                        for group, name in zip(var_groups, var_group_names):
                            if group:
                                header = f"{header_base} {name}"
                                app_inst.print_vars(
                                    header=header, vars_to_print=group, indent=var_indent
                                )

                        app_inst.print_internals(indent=var_indent)
                        app_inst.print_chain_order(indent=var_indent)

    if args.phases:
        for pipeline in sorted(all_pipelines.keys()):
            color.cprint("")
            color.cprint(rucolor.section_title(f"Phases for {pipeline} pipeline:"))
            colify(all_pipelines[pipeline], indent=4)

    # Print software stack information
    if args.software or args.all_software:
        color.cprint("")
        color.cprint(rucolor.section_title("Software Stack:"))
        only_used_software = args.software
        color.cprint(
            software_environments.info(
                verbosity=args.verbose, indent=4, color_level=1, only_used=only_used_software
            )
        )