cwltool.context

Shared context objects that replace use of kwargs.

Attributes

DEFAULT_TMP_PREFIX

CWLObjectType

Typical raw dictionary found in lightly parsed CWL.

ResolverType

default_make_tool

Classes

MpiConfig

PathMapper

Mapping of files from relative path provided in the file to a tuple.

StdFsAccess

Local filesystem implementation.

HasReqsHints

Base class for get_requirement().

ContextBase

Shared kwargs based initializer for RuntimeContext and LoadingContext.

LoadingContext

Shared kwargs based initializer for RuntimeContext and LoadingContext.

RuntimeContext

Shared kwargs based initializer for RuntimeContext and LoadingContext.

Functions

make_tool_notimpl(toolpath_object, loadingContext)

Fake implementation of the make tool function.

log_handler(outdir, base_path_logs, stdout_path, ...)

Move logs from log location to final output.

set_log_dir(outdir, log_dir, subdir_name)

Set the log directory.

getdefault(val, default)

Return the val using the default as backup in case the val is None.

Module Contents

class cwltool.context.MpiConfig(runner='mpirun', nproc_flag='-n', default_nproc=1, extra_flags=None, env_pass=None, env_pass_regex=None, env_set=None)
Parameters:
  • runner (str)

  • nproc_flag (str)

  • default_nproc (Union[int, str])

  • extra_flags (Optional[List[str]])

  • env_pass (Optional[List[str]])

  • env_pass_regex (Optional[List[str]])

  • env_set (Optional[Mapping[str, str]])

classmethod load(config_file_name)

Create the MpiConfig object from the contents of a YAML file.

The file must contain exactly one object, whose attributes must be in the list allowed in the class initialiser (all are optional).

Parameters:

config_file_name (str)

Return type:

MpiConfigT

pass_through_env_vars(env)

Take the configured list of environment variables and pass them to the executed process.

Parameters:

env (MutableMapping[str, str])

Return type:

None

set_env_vars(env)

Set some variables to the value configured.

Parameters:

env (MutableMapping[str, str])

Return type:

None

class cwltool.context.PathMapper(referenced_files, basedir, stagedir, separateDirs=True)

Mapping of files from relative path provided in the file to a tuple.

(absolute local path, absolute container path)

The tao of PathMapper:

The initializer takes a list of class: File and class: Directory objects, a base directory (for resolving relative references) and a staging directory (where the files are mapped to).

The purpose of the setup method is to determine where each File or Directory should be placed on the target file system (relative to stagedir).

If separatedirs=True, unrelated files will be isolated in their own directories under stagedir. If separatedirs=False, files and directories will all be placed in stagedir (with the possibility for name collisions…)

The path map maps the “location” of the input Files and Directory objects to a tuple (resolved, target, type). The “resolved” field is the “real” path on the local file system (after resolving relative paths and traversing symlinks). The “target” is the path on the target file system (under stagedir). The type is the object type (one of File, Directory, CreateFile, WritableFile, CreateWritableFile).

The latter three (CreateFile, WritableFile, CreateWritableFile) are used by InitialWorkDirRequirement to indicate files that are generated on the fly (CreateFile and CreateWritableFile, in this case “resolved” holds the file contents instead of the path because they file doesn’t exist) or copied into the output directory so they can be opened for update (“r+” or “a”) (WritableFile and CreateWritableFile).

Parameters:
  • referenced_files (List[cwltool.utils.CWLObjectType])

  • basedir (str)

  • stagedir (str)

  • separateDirs (bool)

visitlisting(listing, stagedir, basedir, copy=False, staged=False)
Parameters:
  • listing (List[cwltool.utils.CWLObjectType])

  • stagedir (str)

  • basedir (str)

  • copy (bool)

  • staged (bool)

Return type:

None

visit(obj, stagedir, basedir, copy=False, staged=False)
Parameters:
  • obj (cwltool.utils.CWLObjectType)

  • stagedir (str)

  • basedir (str)

  • copy (bool)

  • staged (bool)

Return type:

None

setup(referenced_files, basedir)
Parameters:
  • referenced_files (List[cwltool.utils.CWLObjectType])

  • basedir (str)

Return type:

None

mapper(src)
Parameters:

src (str)

Return type:

MapperEnt

files()

Return a dictionary keys view of locations.

Return type:

KeysView[str]

items()

Return a dictionary items view.

Return type:

ItemsView[str, MapperEnt]

items_exclude_children()

Return a dictionary items view minus any entries which are children of other entries.

Return type:

ItemsView[str, MapperEnt]

reversemap(target)

Find the (source, resolved_path) for the given target, if any.

Parameters:

target (str)

Return type:

Optional[Tuple[str, str]]

update(key, resolved, target, ctype, stage)

Update an existine entry.

Parameters:
Return type:

MapperEnt

__contains__(key)

Test for the presence of the given relative path in this mapper.

Parameters:

key (str)

Return type:

bool

__iter__()

Get iterator for the maps.

Return type:

Iterator[MapperEnt]

class cwltool.context.StdFsAccess(basedir)

Local filesystem implementation.

Parameters:

basedir (str)

glob(pattern)
Parameters:

pattern (str)

Return type:

List[str]

open(fn, mode)
Parameters:
Return type:

IO[Any]

exists(fn)
Parameters:

fn (str)

Return type:

bool

size(fn)
Parameters:

fn (str)

Return type:

int

isfile(fn)
Parameters:

fn (str)

Return type:

bool

isdir(fn)
Parameters:

fn (str)

Return type:

bool

listdir(fn)
Parameters:

fn (str)

Return type:

List[str]

join(path, *paths)
Parameters:
Return type:

str

realpath(path)
Parameters:

path (str)

Return type:

str

cwltool.context.DEFAULT_TMP_PREFIX
cwltool.context.CWLObjectType

Typical raw dictionary found in lightly parsed CWL.

class cwltool.context.HasReqsHints

Base class for get_requirement().

get_requirement(feature)

Retrieve the named feature from the requirements field, or the hints field.

Parameters:

feature (str)

Return type:

Tuple[Optional[CWLObjectType], Optional[bool]]

cwltool.context.ResolverType
class cwltool.context.ContextBase(kwargs=None)

Shared kwargs based initializer for RuntimeContext and LoadingContext.

Parameters:

kwargs (Optional[Dict[str, Any]])

cwltool.context.make_tool_notimpl(toolpath_object, loadingContext)

Fake implementation of the make tool function.

Parameters:
  • toolpath_object (ruamel.yaml.comments.CommentedMap)

  • loadingContext (LoadingContext)

Return type:

cwltool.process.Process

cwltool.context.default_make_tool
cwltool.context.log_handler(outdir, base_path_logs, stdout_path, stderr_path)

Move logs from log location to final output.

Parameters:
  • outdir (str)

  • base_path_logs (str)

  • stdout_path (Optional[str])

  • stderr_path (Optional[str])

Return type:

None

cwltool.context.set_log_dir(outdir, log_dir, subdir_name)

Set the log directory.

Parameters:
  • outdir (str)

  • log_dir (str)

  • subdir_name (str)

Return type:

str

class cwltool.context.LoadingContext(kwargs=None)

Bases: ContextBase

Inheritance diagram of cwltool.context.LoadingContext

Shared kwargs based initializer for RuntimeContext and LoadingContext.

Parameters:

kwargs (Optional[Dict[str, Any]])

copy()

Return a copy of this LoadingContext.

Return type:

LoadingContext

class cwltool.context.RuntimeContext(kwargs=None)

Bases: ContextBase

Inheritance diagram of cwltool.context.RuntimeContext

Shared kwargs based initializer for RuntimeContext and LoadingContext.

Parameters:

kwargs (Optional[Dict[str, Any]])

outdir: str | None = None
tmpdir: str = ''
tmpdir_prefix: str
tmp_outdir_prefix: str = ''
stagedir: str = ''
get_outdir()

Return outdir or create one with tmp_outdir_prefix.

Return type:

str

get_tmpdir()

Return tmpdir or create one with tmpdir_prefix.

Return type:

str

get_stagedir()

Return stagedir or create one with tmpdir_prefix.

Return type:

str

create_tmpdir()

Create a temporary directory that respects tmpdir_prefix.

Return type:

str

create_outdir()

Create a temporary directory that respects tmp_outdir_prefix.

Return type:

str

copy()

Return a copy of this RuntimeContext.

Return type:

RuntimeContext

cwltool.context.getdefault(val, default)

Return the val using the default as backup in case the val is None.

Parameters:
  • val (Any)

  • default (Any)

Return type:

Any