hpcflow.sdk.submission.shells.powershell.WindowsPowerShell#

class hpcflow.sdk.submission.shells.powershell.WindowsPowerShell(executable=None, os_args=None)#

Bases: Shell

Class to represent using PowerShell on Windows to generate and submit a jobscript.

Methods

format_array

Format construction of a shell array.

format_array_get_item

Format retrieval of a shell array item at a specified index.

format_commands_file

Format the commands file.

format_env_var_get

Format retrieval of a shell environment variable.

format_save_parameter

Produce code to save a parameter's value into the workflow persistent store.

format_source_functions_file

Format sourcing (i.e.

format_stream_assignment

Produce code to assign the output of the command to a shell variable.

get_command_file_launch_command

Get the command for launching the commands file for a given run.

get_direct_submit_command

Get the command for submitting a non-scheduled jobscript.

get_version_info

Get powershell version information.

get_wait_command

Get the command to wait for a workflow.

prepare_JS_path

Prepare the jobscript path for use.

prepare_element_run_dirs

Prepare the element run directory names for use.

process_JS_header_args

Process the application invocation key in the jobscript header arguments.

process_app_invoc_executable

Perform any post-processing of an application invocation command name.

Attributes

os_args

Arguments to pass to the shell.

DEFAULT_EXE

Default for executable name.

JS_ACT_MULTI

Template for the action-run processing loop in a jobscript.

JS_ACT_SINGLE

Template for the single-action-run execution in a jobscript.

JS_BLOCK_HEADER

Template for a jobscript-block header.

JS_BLOCK_LOOP

Template for the jobscript block loop in a jobscript.

JS_DIRECT_HEADER

Template for the jobscript header when directly executed.

JS_ELEMENT_MULTI_LOOP

Template for the element processing loop in a jobscript.

JS_ELEMENT_SINGLE

Template for single-element execution.

JS_ENV_SETUP_INDENT

Indent for environment setup.

JS_EXT

File extension for jobscripts.

JS_FOOTER

Template for the jobscript footer.

JS_FUNCS

Template for the jobscript functions file.

JS_HEADER

Template for the common part of the jobscript header.

JS_INDENT

Basic indent.

JS_MAIN

Template for setting up environment variables and running one or more action-runs.

JS_RUN

Template for setting up run environment variables and executing the run.

JS_RUN_CMD

Template for the run execution command.

JS_RUN_CMD_COMBINED

Template for the execution command for multiple combined runs.

JS_RUN_LOG_PATH_DISABLE

Template for disabling writing of the app log.

JS_RUN_LOG_PATH_ENABLE

Template for enabling writing of the app log.

JS_SHEBANG

Template for the jobscript shebang line.

executable

The executable to use plus any mandatory arguments.

shebang_executable

The executable to use in a shebang line.

JS_SCHEDULER_HEADER

Template for the jobscript header when scheduled.

JS_ELEMENT_MULTI_ARRAY

Template for the array handling code in a jobscript.

Parameters:
  • executable (str | None) –

  • os_args (dict[str, str] | None) –

DEFAULT_EXE: ClassVar[str] = 'powershell.exe'#

Default for executable name.

JS_ACT_MULTI: ClassVar[str] = 'for ($block_act_idx = 0; $block_act_idx -lt {num_actions}; $block_act_idx += 1) {{        \n{run_block}\n}}\n'#

Template for the action-run processing loop in a jobscript.

JS_ACT_SINGLE: ClassVar[str] = '$block_act_idx = 0        \n{run_block}\n'#

Template for the single-action-run execution in a jobscript.

JS_BLOCK_HEADER: ClassVar[str] = '$block_idx = 0\n$env:{app_caps}_BLOCK_IDX = 0\n'#

Template for a jobscript-block header.

JS_BLOCK_LOOP: ClassVar[str] = '$num_elements = {num_elements}\n$num_actions = {num_actions}\n$block_start_elem_idx = 0\nfor ($block_idx = 0; $block_idx -lt {num_blocks}; $block_idx += 1 ) {{\n    $env:{app_caps}_BLOCK_IDX = $block_idx\n{element_loop}\n    $block_start_elem_idx += $num_elements[$block_idx]\n}}\n'#

Template for the jobscript block loop in a jobscript.

JS_DIRECT_HEADER: ClassVar[str] = '{shebang}\n{header}\n{wait_command}\n'#

Template for the jobscript header when directly executed.

JS_ELEMENT_MULTI_ARRAY: ClassVar[str]#

Template for the array handling code in a jobscript.

JS_ELEMENT_MULTI_LOOP: ClassVar[str] = 'for ($JS_elem_idx = {block_start_elem_idx}; $JS_elem_idx -lt ({block_start_elem_idx} + {num_elements}); $JS_elem_idx += 1) {{            \n{main}\n}}\n'#

Template for the element processing loop in a jobscript.

JS_ELEMENT_SINGLE: ClassVar[str] = '$JS_elem_idx = {block_start_elem_idx}\n{main}\n'#

Template for single-element execution.

JS_ENV_SETUP_INDENT: ClassVar[str] = '        '#

Indent for environment setup.

JS_EXT: ClassVar[str] = '.ps1'#

File extension for jobscripts.

Template for the jobscript footer.

JS_FUNCS: ClassVar[str] = 'function {workflow_app_alias} {{\n    & {{\n{env_setup}{app_invoc} `\n            --with-config log_file_path "$env:{app_caps}_LOG_PATH" `\n            --config-dir "{config_dir}" `\n            --config-key "{config_invoc_key}" `\n            $args\n    }} @args\n}}\n\nfunction get_nth_line($file, $line) {{\n    Get-Content $file | Select-Object -Skip $line -First 1\n}}\n'#

Template for the jobscript functions file.

JS_HEADER: ClassVar[str] = '$ErrorActionPreference = \'Stop\'\n\nfunction JoinMultiPath {{\n    $numArgs = $args.Length\n    $path = $args[0]\n    for ($i = 1; $i -lt $numArgs; $i++) {{\n        $path = Join-Path $path $args[$i]\n    }}\n    return $path\n}}        \n\n$WK_PATH = $(Get-Location)\n$WK_PATH_ARG = $WK_PATH\n$SUB_IDX = {sub_idx}\n$JS_IDX = {js_idx}\n\n$SUB_DIR = JoinMultiPath $WK_PATH artifacts submissions $SUB_IDX\n$JS_FUNCS_PATH = JoinMultiPath $SUB_DIR {jobscript_functions_dir} {jobscript_functions_name}\n. $JS_FUNCS_PATH\n\n$EAR_ID_FILE = JoinMultiPath $SUB_DIR {run_IDs_file_dir} {run_IDs_file_name}\n$SUB_TMP_DIR = Join-Path $SUB_DIR {tmp_dir_name}\n$SUB_LOG_DIR = Join-Path $SUB_DIR {log_dir_name}\n$SUB_STD_DIR = Join-Path $SUB_DIR {app_std_dir_name}\n$SUB_SCRIPTS_DIR = Join-Path $SUB_DIR {scripts_dir_name}        \n\n$env:{app_caps}_WK_PATH = $WK_PATH\n$env:{app_caps}_WK_PATH_ARG = $WK_PATH_ARG\n$env:{app_caps}_SUB_IDX = {sub_idx}\n$env:{app_caps}_SUB_SCRIPTS_DIR = $SUB_SCRIPTS_DIR\n$env:{app_caps}_SUB_TMP_DIR = $SUB_TMP_DIR\n$env:{app_caps}_SUB_LOG_DIR = $SUB_LOG_DIR\n$env:{app_caps}_SUB_STD_DIR = $SUB_STD_DIR                \n$env:{app_caps}_LOG_PATH = Join-Path $SUB_LOG_DIR "js_$JS_IDX.log"\n$env:{app_caps}_JS_FUNCS_PATH = $JS_FUNCS_PATH\n$env:{app_caps}_JS_IDX = {js_idx}\n$env:{app_caps}_RUN_ID_FILE = $EAR_ID_FILE\n'#

Template for the common part of the jobscript header.

JS_INDENT: ClassVar[str] = '    '#

Basic indent.

JS_MAIN: ClassVar[str] = '$block_elem_idx = ($JS_elem_idx - {block_start_elem_idx})\n$elem_EAR_IDs = get_nth_line $EAR_ID_FILE $JS_elem_idx\n$env:{app_caps}_JS_ELEM_IDX = $JS_elem_idx\n$env:{app_caps}_BLOCK_ELEM_IDX = $block_elem_idx\n\n{action}\n'#

Template for setting up environment variables and running one or more action-runs.

JS_RUN: ClassVar[str] = '$EAR_ID = ($elem_EAR_IDs -split "{EAR_files_delimiter}")[$block_act_idx]\nif ($EAR_ID -eq -1) {{\n    continue\n}}\n\n$env:{app_caps}_RUN_ID = $EAR_ID\n$env:{app_caps}_RUN_LOG_PATH = {run_log_enable_disable}\n$env:{app_caps}_LOG_PATH = $env:{app_caps}_RUN_LOG_PATH\n$env:{app_caps}_RUN_STD_PATH = Join-Path $SUB_STD_DIR "$env:{app_caps}_RUN_ID.txt"\n$env:{app_caps}_BLOCK_ACT_IDX = $block_act_idx            \n\nSet-Location $SUB_TMP_DIR\n\n{run_cmd}\n'#

Template for setting up run environment variables and executing the run.

JS_RUN_CMD: ClassVar[str] = '{workflow_app_alias} internal workflow $WK_PATH execute-run $SUB_IDX $JS_IDX $block_idx $block_act_idx $EAR_ID\n'#

Template for the run execution command.

JS_RUN_CMD_COMBINED: ClassVar[str] = '{workflow_app_alias} internal workflow $WK_PATH execute-combined-runs $SUB_IDX $JS_IDX\n'#

Template for the execution command for multiple combined runs.

JS_RUN_LOG_PATH_DISABLE: ClassVar[str] = '" "'#

Template for disabling writing of the app log.

JS_RUN_LOG_PATH_ENABLE: ClassVar[str] = 'Join-Path $SUB_LOG_DIR "{run_log_file_name}"'#

Template for enabling writing of the app log.

JS_SCHEDULER_HEADER: ClassVar[str]#

Template for the jobscript header when scheduled.

JS_SHEBANG: ClassVar[str] = ''#

Template for the jobscript shebang line.

property executable: list[str]#

The executable to use plus any mandatory arguments.

format_array(lst)#

Format construction of a shell array.

Parameters:

lst (list) –

Return type:

str

format_array_get_item(arr_name, index)#

Format retrieval of a shell array item at a specified index.

Parameters:
Return type:

str

format_commands_file(app_name, commands)#

Format the commands file.

Parameters:
  • app_name (str) –

  • commands (str) –

Return type:

str

format_env_var_get(var)#

Format retrieval of a shell environment variable.

Parameters:

var (str) –

Return type:

str

format_save_parameter(workflow_app_alias, param_name, shell_var_name, cmd_idx, stderr, app_name)#

Produce code to save a parameter’s value into the workflow persistent store.

Parameters:
  • workflow_app_alias (str) –

  • param_name (str) –

  • shell_var_name (str) –

  • cmd_idx (int) –

  • stderr (bool) –

  • app_name (str) –

Return type:

str

format_source_functions_file(app_name, commands)#

Format sourcing (i.e. invocation) of the jobscript functions file.

Parameters:
  • app_name (str) –

  • commands (str) –

Return type:

str

format_stream_assignment(shell_var_name, command)#

Produce code to assign the output of the command to a shell variable.

Parameters:
  • shell_var_name (str) –

  • command (str) –

Return type:

str

get_command_file_launch_command(cmd_file_path)#

Get the command for launching the commands file for a given run.

Parameters:

cmd_file_path (str) –

Return type:

list[str]

get_direct_submit_command(js_path)#

Get the command for submitting a non-scheduled jobscript.

Parameters:

js_path (str) –

Return type:

list[str]

get_version_info(exclude_os=False)#

Get powershell version information.

Parameters:

exclude_os (bool) – If True, exclude operating system information.

Return type:

VersionInfo

get_wait_command(workflow_app_alias, sub_idx, deps)#

Get the command to wait for a workflow.

Parameters:
  • workflow_app_alias (str) –

  • sub_idx (int) –

  • deps (Mapping[int, Any]) –

os_args#

Arguments to pass to the shell.

prepare_JS_path(js_path)#

Prepare the jobscript path for use.

Parameters:

js_path (Path) –

Return type:

str

prepare_element_run_dirs(run_dirs)#

Prepare the element run directory names for use.

Parameters:

run_dirs (list[list[Path]]) –

Return type:

list[list[str]]

process_JS_header_args(header_args)#

Process the application invocation key in the jobscript header arguments.

Parameters:

header_args (JobscriptHeaderArgs) –

Return type:

JobscriptHeaderArgs

static process_app_invoc_executable(app_invoc_exe)#

Perform any post-processing of an application invocation command name.

Parameters:

app_invoc_exe (str) –

Return type:

str

property shebang_executable: list[str]#

The executable to use in a shebang line.