hpcflow.sdk.submission.shells.bash.Bash#

class hpcflow.sdk.submission.shells.bash.Bash(executable=None, os_args=None)#

Bases: Shell

Class to represent using bash on a POSIX OS to generate and submit a jobscript.

Methods

format_loop_check

Produce code to check the looping status of part of a workflow.

format_save_parameter

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

format_stream_assignment

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

get_direct_submit_command

Get the command for submitting a non-scheduled jobscript.

get_version_info

Get bash 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.

wrap_in_subshell

Format commands to run within a subshell.

Attributes

os_args

Arguments to pass to the shell.

DEFAULT_EXE

Default for executable name.

JS_DIRECT_HEADER

Template for the jobscript header when directly executed.

JS_ELEMENT_ARRAY

Template for the array handling code in a jobscript.

JS_ELEMENT_LOOP

Template for the element processing loop in a jobscript.

JS_ENV_SETUP_INDENT

Indent for environment setup.

JS_EXT

File extension for jobscripts.

JS_HEADER

Template for the common part of the jobscript header.

JS_INDENT

Basic indent.

JS_MAIN

Template for the jobscript body.

JS_SCHEDULER_HEADER

Template for the jobscript header when scheduled.

JS_SHEBANG

Template for the jobscript shebang line.

executable

The executable to use plus any mandatory arguments.

linux_release_file

The name of the file describing the Linux version.

shebang_executable

The executable to use in a shebang line.

Parameters:
  • executable (str | None) –

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

DEFAULT_EXE: ClassVar[str] = '/bin/bash'#

Default for executable name.

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

Template for the jobscript header when directly executed.

JS_ELEMENT_ARRAY: ClassVar[str] = 'JS_elem_idx=$(({scheduler_array_item_var} - 1))\n{main}\ncd "$WK_PATH"\n'#

Template for the array handling code in a jobscript.

JS_ELEMENT_LOOP: ClassVar[str] = 'for ((JS_elem_idx=0;JS_elem_idx<{num_elements};JS_elem_idx++))\ndo\n{main}\ndone\ncd "$WK_PATH"\n'#

Template for the element processing loop in a jobscript.

JS_ENV_SETUP_INDENT: ClassVar[str] = '    '#

Indent for environment setup.

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

File extension for jobscripts.

JS_HEADER: ClassVar[str] = '{workflow_app_alias} () {{\n(\n{env_setup}{app_invoc}\\\n        --with-config log_file_path "`pwd`/{run_log_file}"\\\n        --config-dir "{config_dir}"\\\n        --config-key "{config_invoc_key}"\\\n        "$@"\n)\n}}\n\nWK_PATH=`pwd`\nWK_PATH_ARG="$WK_PATH"\nSUB_IDX={sub_idx}\nJS_IDX={js_idx}\nEAR_ID_FILE="$WK_PATH/artifacts/submissions/${{SUB_IDX}}/{EAR_file_name}"\nELEM_RUN_DIR_FILE="$WK_PATH/artifacts/submissions/${{SUB_IDX}}/{element_run_dirs_file_path}"\n'#

Template for the common part of the jobscript header.

JS_INDENT: ClassVar[str] = '  '#

Basic indent.

JS_MAIN: ClassVar[str] = 'elem_EAR_IDs=`sed "$((${{JS_elem_idx}} + 1))q;d" "$EAR_ID_FILE"`\nelem_run_dirs=`sed "$((${{JS_elem_idx}} + 1))q;d" "$ELEM_RUN_DIR_FILE"`\n\nfor ((JS_act_idx=0;JS_act_idx<{num_actions};JS_act_idx++))\ndo\n\n  EAR_ID="$(cut -d\'{EAR_files_delimiter}\' -f $(($JS_act_idx + 1)) <<< $elem_EAR_IDs)"\n  if [ "$EAR_ID" = "-1" ]; then\n      continue\n  fi\n\n  run_dir="$(cut -d\'{EAR_files_delimiter}\' -f $(($JS_act_idx + 1)) <<< $elem_run_dirs)"\n  cd "$WK_PATH/$run_dir"\n  app_stream_file="`pwd`/{run_stream_file}"\n\n  skip=`{workflow_app_alias} internal workflow "$WK_PATH_ARG" get-ear-skipped $EAR_ID 2>> "$app_stream_file"`\n  exc_sk=$?\n\n  if [ $exc_sk -eq 0 ]; then\n\n      if [ "$skip" = "1" ]; then\n          continue\n      fi\n\n      {workflow_app_alias} internal workflow "$WK_PATH_ARG" write-commands $SUB_IDX $JS_IDX $JS_act_idx $EAR_ID >> "$app_stream_file" 2>&1\n      exc_wc=$?\n\n      {workflow_app_alias} internal workflow "$WK_PATH_ARG" set-ear-start $EAR_ID >> "$app_stream_file" 2>&1\n      exc_se=$?\n\n      if [ $exc_wc -eq 0 ] && [ $exc_se -eq 0 ]; then\n          . {commands_file_name}\n          exit_code=$?\n      else\n          exit_code=$([ $exc_wc -ne 0 ] && echo "$exc_wc" || echo "$exc_se")\n      fi\n\n  else\n      exit_code=$exc_sk\n  fi\n\n  {workflow_app_alias} internal workflow "$WK_PATH_ARG" set-ear-end $JS_IDX $JS_act_idx $EAR_ID "--" "$exit_code" >> "$app_stream_file" 2>&1\n\ndone\n'#

Template for the jobscript body.

JS_SCHEDULER_HEADER: ClassVar[str] = '{shebang}\n\n{scheduler_options}\n{header}\n'#

Template for the jobscript header when scheduled.

JS_SHEBANG: ClassVar[str] = '#!{shebang_executable} {shebang_args}'#

Template for the jobscript shebang line.

property executable: list[str]#

The executable to use plus any mandatory arguments.

format_loop_check(workflow_app_alias, loop_name, run_ID)#

Produce code to check the looping status of part of a workflow.

Parameters:
  • workflow_app_alias (str) –

  • loop_name (str) –

  • run_ID (int) –

Return type:

str

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

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) –

  • EAR_ID (int) –

  • cmd_idx (int) –

  • stderr (bool) –

static 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_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 bash 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]) –

property linux_release_file: str#

The name of the file describing the Linux version.

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.

wrap_in_subshell(commands, abortable)#

Format commands to run within a subshell.

This assumes commands ends in a newline.

Parameters:
  • commands (str) –

  • abortable (bool) –

Return type:

str