flint.sclient

Utilities related to running commands in a singularity container

Classes

ContainerCommandResults

Description of the command execution results

Functions

pull_container(→ pathlib.Path)

Download a singularity container from an appropriate uri.

run_singularity_command(→ None)

Executes a command within the context of a nominated singularity

singularity_wrapper(→ Callable)

A decorator function to around another function that when executed

Module Contents

class flint.sclient.ContainerCommandResults[source]

Bases: NamedTuple

Description of the command execution results

attempts: int[source]

Number of attempts the command took

flint.sclient.pull_container(container_directory: pathlib.Path, uri: str, file_name: str) pathlib.Path[source]

Download a singularity container from an appropriate uri.

Parameters:
  • container_directory (Path) – Where to store the output container

  • uri (str) – The reference to the container to pull, e.g. docker://profile/container:tag

  • file_name (str) – The output name of the container

Returns:

Location of the new container

Return type:

Path

flint.sclient.run_singularity_command(image: pathlib.Path, command: str, bind_dirs: pathlib.Path | Collection[pathlib.Path] | None = None, stream_callback_func: Callable | None = None, ignore_logging_output: bool = False, max_retries: int = 2) None[source]

Executes a command within the context of a nominated singularity container

Parameters:
  • image (Path) – The singularity container image to use

  • command (str) – The command to execute

  • bind_dirs (Optional[Union[Path,Collection[Path]]], optional) – Specifies a Path, or list of Paths, to bind to in the container. Defaults to None.

  • stream_callback_func (Optional[Callable], optional) – Provide a function that is applied to each line of output text when singularity is running and stream=True. IF provide it should accept a single (string) parameter. If None, nothing happens. Defaultds to None.

  • ignore_logging_output (bool, optional) – If True output from the executed singularity command is not logged. Defaults to False.

  • max_retries (int, optional) – If a callback handler is specified which raised an AttemptRerunException, this signifies how many attempts should be made. Each rerun will recall run_singularity_command lowering this value. Defaults to 2.

Raises:
  • FileNotFoundError – Thrown when container image not found

  • CalledProcessError – Thrown when the command into the container was not successful

flint.sclient.singularity_wrapper(fn: Callable) Callable[source]

A decorator function to around another function that when executed returns a command to execute within a container. The returned function has the arguments as run_singularity_command, and any unused keywords are passed to the wrapped function.

Parameters:

fn (Callable) – The function that generates the command to execute

Returns:

Wrapper function

Return type:

Callable