def _generate_include_file()

in cookbooks/aws-parallelcluster-slurm/files/default/head_node_slurm/slurm/pcluster_custom_slurm_settings_include_file_generator.py [0:0]


def _generate_include_file(include_target: str, include_file_config: List[Dict], output_directory, dryrun: bool):
    """
    Generate single custom Slurm settings include file at a given level.

    :param include_target: target of the custom Slurm setting include file (e.g. slurm, slurmdbd, cgroup, etc.)
    :param include_file_config: dictionary with relevant custom Slurm settings
    :param output_directory: output directory where the include file is written
    :param dryrun: dryrun
    :return:
    """
    log.info("Generating custom_slurm_settings_include_file_%s.conf", include_target)
    if dryrun:
        return

    filename = path.join(output_directory, f"custom_slurm_settings_include_file_{include_target}.conf")

    # The include_file_config is structured as a list of dictionaries, which can either contain one
    # single key-value pair (simple parameters) or multiple pairs (e.g. partition definitions).
    with open(filename, "w", encoding="utf-8") as output_file:
        output_file.write(INCLUDE_FILE_HEADER + "\n\n")

        # If include_file_config is empty, this function will generate an empty config file with only the header
        # defined in INCLUDE_FILE_HEADER
        if include_file_config:
            for param in include_file_config:
                output_string = _render_parameter(param)
                output_file.write(output_string + "\n")