qtoolkit.io.base module#

class qtoolkit.io.base.BaseSchedulerIO[source]#

Bases: QTKObject, ABC

Base class for job queues.

CANCEL_CMD: str | None#
SUBMIT_CMD: str | None#
check_convert_qresources(resources: QResources) dict[source]#

Converts a Qresources instance to a dict that will be used to fill in the header of the submission script. Also checks that passed values are declared to be handled by the corresponding subclass.

check_job_ids: bool = True#

Generate the footer for the submission script.

Returns:

The generated footer string.

Return type:

str

generate_header(options: dict | QResources | None) str[source]#

Generate the header (directives) for the submission script.

Parameters:

options – Scheduler options or QResources object.

Returns:

The generated header string.

Return type:

str

generate_ids_list(jobs: list[QJob | int | str] | None) list[str] | None[source]#
generate_run_commands(commands: list[str] | str) str[source]#
get_cancel_cmd(job: QJob | int | str) str[source]#

Get the command used to cancel a given job.

Parameters:

job ((str) job to be cancelled.)

get_job_cmd(job: QJob | int | str) str[source]#

Get the command used to retrieve information about a given job.

Parameters:

job – Job identifier.

Returns:

The command string.

Return type:

str

get_jobs_list_cmd(jobs: list[QJob | int | str] | None, user: str | None) str[source]#

Get the command used to list jobs, optionally filtered by IDs or user.

Parameters:
  • jobs – List of job identifiers.

  • user – Username to filter by.

Returns:

The command string.

Return type:

str

get_submission_script(commands: str | list[str], options: dict | QResources | None = None) str[source]#

Get the submission script for the given commands and options.

get_submit_cmd(script_file: str | Path | None = 'submit.script') str[source]#

Get the command used to submit a given script to the queue.

Parameters:

script_file ((str) path of the script file to use.)

header_template: str#
header_template_file: str | None = None#
is_valid_job_id(job_id: str) bool[source]#

Check if a given job identifier is valid for the current scheduler.

Parameters:

job_id – The job identifier to check.

Returns:

True if the job ID is valid, False otherwise.

Return type:

bool

job_id_regex: str | None = None#
abstractmethod parse_cancel_output(exit_code: int, stdout: str | bytes, stderr: str | bytes) CancelResult[source]#

Parse the output of a cancellation command.

Parameters:
  • exit_code – Exit code of the command.

  • stdout – Standard output of the command.

  • stderr – Standard error of the command.

Returns:

The parsed cancellation result.

Return type:

CancelResult

abstractmethod parse_job_output(exit_code: int, stdout: str | bytes, stderr: str | bytes, job_id: str | None = None) QJob | None[source]#

Parse the output of a command to get a job and return the corresponding QJob object.

Parameters:
  • exit_code – Exit code of the command.

  • stdout – Standard output of the command.

  • stderr – Standard error of the command.

  • job_id – Job ID of the parsed job.

Returns:

The parsed QJob object, or None if not found.

Return type:

QJob or None

abstractmethod parse_jobs_list_output(exit_code: int, stdout: str | bytes, stderr: str | bytes, job_ids: list[str] | None = None) list[QJob][source]#

Parse the output of a command that lists jobs.

Parameters:
  • exit_code (int) – Exit code of the command.

  • stdout (str or bytes) – Standard output of the command.

  • stderr (str or bytes) – Standard error of the command.

  • job_ids (list of str, optional) – List of expected job IDs.

Returns:

List of parsed QJob objects.

Return type:

list of QJob

abstractmethod parse_submit_output(exit_code: int, stdout: str | bytes, stderr: str | bytes) SubmissionResult[source]#

Parse the output of a submission command.

Parameters:
  • exit_code (int) – Exit code of the command.

  • stdout (str or bytes) – Standard output of the command.

  • stderr (str or bytes) – Standard error of the command.

Returns:

The parsed submission result.

Return type:

SubmissionResult

sanitize_job_name: bool = False#
sanitize_options(options: dict) dict[source]#

A function to sanitize the values in the options used to generate the header. Subclasses should implement their own sanitizations.

Parameters:

options – Dictionary of options to sanitize.

Returns:

Sanitized options.

Return type:

dict

shebang: str = '#!/bin/bash'#
property supported_qresources_keys: list#

List of attributes of QResources that are correctly handled by the _convert_qresources method. It is used to validate that the user does not pass an unsupported value, expecting to have an effect.

class qtoolkit.io.base.QTemplate(template)[source]#

Bases: Template

delimiter = '$$'#
get_identifiers() list[source]#

Returns a list of the valid identifiers in the template, in the order they first appear, ignoring any invalid identifiers. Imported from implementation in python 3.11 for backward compatibility.

pattern = re.compile('\n            \\$\\$(?:\n              (?P<escaped>\\$\\$)  |   # Escape sequence of two delimiters\n              (?P<named>(?a:[_a-z][_a-z0-9]*))       |   # delimiter and a Python identifier\n    , re.IGNORECASE|re.VERBOSE)#