# cwltool.pathmapper

## Classes

`MapperEnt` | Mapper entries.
`PathMapper` | Mapping of files from relative path provided in the file to a tuple.

## Module Contents

class cwltool.pathmapper.MapperEnt

  Bases: `NamedTuple`

  Mapper entries.

  resolved: str

    The “real” path on the local file system (after resolving relative paths and traversing symlinks

  target: str

    The path on the target file system (under stagedir)

  type: str | None

    The object type. One of “File”, “Directory”, “CreateFile”, “WritableFile”, or “CreateWritableFile”.

  staged: bool | None

    If the File has been staged yet.

class cwltool.pathmapper.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 (collections.abc.MutableSequence[cwl_utils.types.CWLFileType | cwl_utils.types.CWLDirectoryType])

    - basedir (str)

    - stagedir (str)

    - separateDirs (bool)

  stagedir
  separateDirs = True
  visitlisting(listing, stagedir, basedir, copy=False, staged=False)
    Parameters:

      - listing (collections.abc.MutableSequence[cwl_utils.types.CWLFileType | cwl_utils.types.CWLDirectoryType])

      - stagedir (str)

      - basedir (str)

      - copy (bool)

      - staged (bool)

    Return type:

      None

  visit(obj, stagedir, basedir, copy=False, staged=False)
    Parameters:

      - obj (cwl_utils.types.CWLFileType | cwl_utils.types.CWLDirectoryType)

      - stagedir (str)

      - basedir (str)

      - copy (bool)

      - staged (bool)

    Return type:

      None

  setup(referenced_files, basedir)

    For each file, set the target to its own directory.

    Also processes secondary files into that same directory.

    Parameters:

      - referenced_files (collections.abc.MutableSequence[cwl_utils.types.CWLFileType | cwl_utils.types.CWLDirectoryType])

      - basedir (str)

    Return type:

      None

  mapper(src)
    Parameters:

      src (str)

    Return type:

      MapperEnt

  files()

    Return a dictionary keys view of locations.

    Return type:

      collections.abc.KeysView[str]

  items()

    Return a dictionary items view.

    Return type:

      collections.abc.ItemsView[str, MapperEnt]

  items_exclude_children()

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

    Return type:

      collections.abc.ItemsView[str, MapperEnt]

  reversemap(target)

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

    Parameters:

      target (str)

    Return type:

      tuple[str, str] | None

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

    Update an existing entry.

    Parameters:

      - key (str)

      - resolved (str)

      - target (str)

      - ctype (str | None)

      - stage (bool | None)

    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:

      collections.abc.Iterator[MapperEnt]