spython.instance package

Module contents

class spython.instance.Instance(image, start=True, name=None, quiet=True, **kwargs)[source]

Bases: spython.image.ImageBase

RobotNamer = <spython.main.base.generate.RobotNamer object>
debug = False
error_logs(print_logs=False)

For Singularity 3.5 and later, we are able to programatically derive the name of the log. In this case, return the content to the user. See https://github.com/sylabs/singularity/issues/1115#issuecomment-560457918 for when this was added.

Parameters:print_logs (boolean to indicate to print to the screen along with) – return (defaults to False to just return log string)
generate_name(name=None)[source]

generate a Robot Name for the instance to use, if the user doesn’t supply one.

get_uri()[source]

return the image uri (instance://) along with it’s name

instance

alias of spython.instance.Instance

output_logs(print_logs=False)

Get output logs for the user, if they exist.

Parameters:print_logs (boolean to indicate to print to the screen along with) – return (defaults to False to just return log string)
parse_image_name(image)[source]

simply split the uri from the image. Singularity handles parsing of registry, namespace, image.

Parameters:image (the complete image uri to load (e.g., docker://ubuntu))
quiet = False
read_logs_err()[source]

Read error log file, if it exists

read_logs_out()[source]

Read output log file, if it exists

run_command(sudo=False, capture=True, no_newline_regexp='Progess', quiet=False, sudo_options=None, environ=None)

run_command uses subprocess to send a command to the terminal. If capture is True, we use the parent stdout, so the progress bar (and other commands of interest) are piped to the user. This means we don’t return the output to parse.

Parameters:
  • cmd (the command to send, should be a list for subprocess)
  • sudo (if needed, add to start of command)
  • no_newline_regexp (the regular expression to determine skipping a) – newline. Defaults to finding Progress
  • capture (if True, don’t set stdout and have it go to console. This) – option can print a progress bar, but won’t return the lines as output.
  • sudo_options (string or list of strings that will be passed as options to sudo)
start(image=None, name=None, args=None, sudo=False, sudo_options=None, options=None, capture=False, singularity_options=None, environ=None, quiet=True)

start an instance. This is done by default when an instance is created.

Parameters:
  • image (optionally, an image uri (if called as a command from Client))
  • name (a name for the instance)
  • sudo (if the user wants to run the command with sudo)
  • capture (capture output, default is False. With True likely to hang.)
  • args (arguments to provide to the instance (supported Singularity 3.1+))
  • singularity_options (a list of options to provide to the singularity client)
  • quiet (Do not print verbose output.)
  • options (a list of tuples, each an option to give to the start command) – [(“–bind”, “/tmp”),…]
  • USAGE
  • singularity […] instance.start […] <container path> <instance name>
stop(name=None, sudo=False, sudo_options=None, timeout=None, singularity_options=None, quiet=True)

stop an instance. This is done by default when an instance is created.

Parameters:
  • name (a name for the instance)
  • sudo (if the user wants to run the command with sudo)
  • singularity_options (a list of options to provide to the singularity client)
  • quiet (Do not print verbose output.)
  • timeout (forcebly kill non-stopped instance after the) – timeout specified in seconds
  • USAGE
  • singularity […] instance.stop […] <instance name>
version()

Shortcut to get_singularity_version, takes no arguments.