toil.common¶
Attributes¶
Exceptions¶
Common base class for all non-exit exceptions. |
|
Common base class for all non-exit exceptions. |
Classes¶
Class to represent configuration operations for a toil workflow run. |
|
A context manager that represents a Toil workflow. |
|
Functions¶
Ensure that TOIL_HOME_DIR exists. |
|
If the default config file does not exist, create it in the Toil home directory. Create the Toil home directory |
|
|
If the config file at the filepath does not exist, try creating it. |
|
Write a Toil config file to the given path. |
|
|
|
Add all Toil command line options to a parser. |
Return unique ID of the current node (host). The resulting string will be convertible to a uuid.UUID. |
|
|
|
|
This method will return the cumulative number of bytes occupied by the files |
|
Return the free space, and total size of the file system hosting dirPath. |
|
Module Contents¶
- toil.common.UUID_LENGTH = 32¶
- toil.common.logger¶
- class toil.common.Config[source]¶
Class to represent configuration operations for a toil workflow run.
- batch_logs_dir: str | None¶
The backing scheduler will be instructed, if possible, to save logs to this directory, where the leader can read them.
- workflowID: str | None¶
This attribute uniquely identifies the job store and therefore the workflow. It is necessary in order to distinguish between two consecutive workflows for which self.jobStore is the same, e.g. when a job store name is reused after a previous run has finished successfully and its job store has been clean up.
- defaultAccelerators: List[toil.job.AcceleratorRequirement]¶
- prepare_start()[source]¶
After options are set, prepare for initial start of workflow.
- Return type:
None
- prepare_restart()[source]¶
Before restart options are set, prepare for a restart of a workflow. Set up any execution-specific parameters and clear out any stale ones.
- Return type:
None
- setOptions(options)[source]¶
Creates a config object from the options object.
- Parameters:
options (argparse.Namespace)
- Return type:
None
- toil.common.check_and_create_toil_home_dir()[source]¶
Ensure that TOIL_HOME_DIR exists.
Raises an error if it does not exist and cannot be created. Safe to run simultaneously in multiple processes.
- Return type:
None
- toil.common.check_and_create_default_config_file()[source]¶
If the default config file does not exist, create it in the Toil home directory. Create the Toil home directory if needed
Raises an error if the default config file cannot be created. Safe to run simultaneously in multiple processes. If this process runs this function, it will always see the default config file existing with parseable contents, even if other processes are racing to create it.
No process will see an empty or partially-written default config file.
- Return type:
None
- toil.common.check_and_create_config_file(filepath)[source]¶
If the config file at the filepath does not exist, try creating it. The parent directory should be created prior to calling this :param filepath: path to config file :return: None
- Parameters:
filepath (str)
- Return type:
None
- toil.common.generate_config(filepath)[source]¶
Write a Toil config file to the given path.
Safe to run simultaneously in multiple processes. No process will see an empty or partially-written file at the given path.
Set include to “cwl” or “wdl” to include cwl options and wdl options respectfully
- Parameters:
filepath (str)
- Return type:
None
- toil.common.parser_with_common_options(provisioner_options=False, jobstore_option=True, prog=None, default_log_level=None)[source]¶
- toil.common.addOptions(parser, jobstore_as_flag=False, cwl=False, wdl=False)[source]¶
Add all Toil command line options to a parser.
Support for config files if using configargparse. This will also check and set up the default config file.
- Parameters:
jobstore_as_flag (bool) – make the job store option a –jobStore flag instead of a required jobStore positional argument.
cwl (bool) – Whether CWL options are expected. If so, CWL options won’t be suppressed.
wdl (bool) – Whether WDL options are expected. If so, WDL options won’t be suppressed.
parser (argparse.ArgumentParser)
- Return type:
None
- toil.common.getNodeID()[source]¶
Return unique ID of the current node (host). The resulting string will be convertible to a uuid.UUID.
Tries several methods until success. The returned ID should be identical across calls from different processes on the same node at least until the next OS reboot.
The last resort method is uuid.getnode() that in some rare OS configurations may return a random ID each time it is called. However, this method should never be reached on a Linux system, because reading from /proc/sys/kernel/random/boot_id will be tried prior to that. If uuid.getnode() is reached, it will be called twice, and exception raised if the values are not identical.
- Return type:
- class toil.common.Toil(options)[source]¶
Bases:
ContextManager
[Toil
]A context manager that represents a Toil workflow.
Specifically the batch system, job store, and its configuration.
- Parameters:
options (argparse.Namespace)
- options¶
- __enter__()[source]¶
Derive configuration from the command line options.
Then load the job store and, on restart, consolidate the derived configuration with the one from the previous invocation of the workflow.
- Return type:
- __exit__(exc_type, exc_val, exc_tb)[source]¶
Clean up after a workflow invocation.
Depending on the configuration, delete the job store.
- Parameters:
exc_type (Optional[Type[BaseException]])
exc_val (Optional[BaseException])
exc_tb (Optional[types.TracebackType])
- Return type:
Literal[False]
- start(rootJob)[source]¶
Invoke a Toil workflow with the given job as the root for an initial run.
This method must be called in the body of a
with Toil(...) as toil:
statement. This method should not be called more than once for a workflow that has not finished.- Parameters:
rootJob (toil.job.Job) – The root job of the workflow
- Returns:
The root job’s return value
- Return type:
Any
- restart()[source]¶
Restarts a workflow that has been interrupted.
- Returns:
The root job’s return value
- Return type:
Any
- classmethod getJobStore(locator)[source]¶
Create an instance of the concrete job store implementation that matches the given locator.
- Parameters:
locator (str) – The location of the job store to be represent by the instance
- Returns:
an instance of a concrete subclass of AbstractJobStore
- Return type:
- static createBatchSystem(config)[source]¶
Create an instance of the batch system specified in the given config.
- Parameters:
config (Config) – the current configuration
- Returns:
an instance of a concrete subclass of AbstractBatchSystem
- Return type:
- importFile(srcUrl: str, sharedFileName: str, symlink: bool = True) None [source]¶
- importFile(srcUrl: str, sharedFileName: None = None, symlink: bool = True) toil.fileStores.FileID
- import_file(src_uri: str, shared_file_name: str, symlink: bool = True, check_existence: bool = True) None [source]¶
- import_file(src_uri: str, shared_file_name: None = None, symlink: bool = True, check_existence: bool = True) toil.fileStores.FileID
Import the file at the given URL into the job store.
By default, returns None if the file does not exist.
- Parameters:
check_existence – If true, raise FileNotFoundError if the file does not exist. If false, return None when the file does not exist.
See
toil.jobStores.abstractJobStore.AbstractJobStore.importFile()
for a full description
- exportFile(jobStoreFileID, dstUrl)[source]¶
- Parameters:
jobStoreFileID (toil.fileStores.FileID)
dstUrl (str)
- Return type:
None
- export_file(file_id, dst_uri)[source]¶
Export file to destination pointed at by the destination URL.
See
toil.jobStores.abstractJobStore.AbstractJobStore.exportFile()
for a full description- Parameters:
file_id (toil.fileStores.FileID)
dst_uri (str)
- Return type:
None
- static normalize_uri(uri, check_existence=False)[source]¶
Given a URI, if it has no scheme, prepend “file:”.
- static getToilWorkDir(configWorkDir=None)[source]¶
Return a path to a writable directory under which per-workflow directories exist.
This directory is always required to exist on a machine, even if the Toil worker has not run yet. If your workers and leader have different temp directories, you may need to set TOIL_WORKDIR.
- classmethod get_toil_coordination_dir(config_work_dir, config_coordination_dir)[source]¶
Return a path to a writable directory, which will be in memory if convenient. Ought to be used for file locking and coordination.
- Parameters:
- Returns:
Path to the Toil coordination directory. Ought to be on a POSIX filesystem that allows directories containing open files to be deleted.
- Return type:
- static get_workflow_path_component(workflow_id)[source]¶
Get a safe filesystem path component for a workflow.
Will be consistent for all processes on a given machine, and different for all processes on different machines.
- classmethod getLocalWorkflowDir(workflowID, configWorkDir=None)[source]¶
Return the directory where worker directories and the cache will be located for this workflow on this machine.
- classmethod get_local_workflow_coordination_dir(workflow_id, config_work_dir, config_coordination_dir)[source]¶
Return the directory where coordination files should be located for this workflow on this machine. These include internal Toil databases and lock files for the machine.
If an in-memory filesystem is available, it is used. Otherwise, the local workflow directory, which may be on a shared network filesystem, is used.
- Parameters:
- Returns:
Path to the local workflow coordination directory on this machine.
- Return type:
- exception toil.common.ToilRestartException(message)[source]¶
Bases:
Exception
Common base class for all non-exit exceptions.
- Parameters:
message (str)
- exception toil.common.ToilContextManagerException[source]¶
Bases:
Exception
Common base class for all non-exit exceptions.
- class toil.common.ToilMetrics(bus, provisioner=None)[source]¶
- Parameters:
bus (toil.bus.MessageBus)
provisioner (Optional[toil.provisioners.abstractProvisioner.AbstractProvisioner])
- clusterName = 'none'¶
- region = 'us-west-2'¶
- registry¶
- mtailImage¶
- grafanaImage¶
- prometheusImage¶
- nodeExporterProc: subprocess.Popen[bytes] | None = None¶
- TARGETS¶
- MessageType¶
- toil.common.getDirSizeRecursively(dirPath)[source]¶
This method will return the cumulative number of bytes occupied by the files on disk in the directory and its subdirectories.
If the method is unable to access a file or directory (due to insufficient permissions, or due to the file or directory having been removed while this function was attempting to traverse it), the error will be handled internally, and a (possibly 0) lower bound on the size of the directory will be returned.