paks package

Submodules

paks.cli module

paks.cli.get_parser()[source]
paks.cli.run_main()[source]

paks.cli.run module

paks.cli.run.main(args, parser, extra, subparser)[source]

paks.cli.config module

paks.cli.config.main(args, parser, extra, subparser)[source]

paks.client module

class paks.client.PakClient(*args, **kwargs)[source]

Bases: object

Paks has a main controller for interacting with paks.

run(image, registry=None, shell=None, container_tech=None)[source]

Run a paks image

paks.defaults module

paks.schemas module

paks.settings module

class paks.settings.EmptySettings[source]

Bases: object

add(key, value)[source]

Add a value to a list parameter

change_validate(key, value)[source]

A courtesy function to validate a new config addition.

delete(key)[source]
edit()[source]

Interactively edit a config file.

get(key, default=None)[source]

Get a settings value, doing appropriate substitution and expansion.

get_settings_file(settings_file=None)[source]

Get the preferred used settings file.

inituser()[source]

Create a user specific config in user’s home.

load(settings_file=None)[source]

Load the settings file into the settings object

remove(key, value)[source]

Remove a value from a list parameter

save(filename=None)[source]

Save settings, but do not change order of anything.

set(key, value)[source]

Set a setting based on key and value. If the key has :, it’s nested

validate()[source]

Validate the loaded settings with jsonschema

class paks.settings.Settings(settings_file, validate=True)[source]

Bases: paks.settings.EmptySettings

The settings class is a wrapper for easily parsing a settings.yml file.

We parse into a query-able class. It also gives us control to update settings, meaning we change the values and then write them to file. It’s basically a dictionary-like class with extra functions.

paks.version module

paks.logger module

class paks.logger.ColorizingStreamHandler(nocolor=False, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, use_threads=False)[source]

Bases: logging.StreamHandler

BLACK = 0
BLUE = 4
BOLD_SEQ = '\x1b[1m'
COLOR_SEQ = '\x1b[%dm'
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
RESET_SEQ = '\x1b[0m'
WHITE = 7
YELLOW = 3
can_color_tty()[source]
colors = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'WARNING': 3}
decorate(record)[source]
emit(record)[source]

Emit a record.

If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.

property is_tty
class paks.logger.Logger[source]

Bases: object

cleanup()[source]
debug(msg)[source]
error(msg)[source]
exit(msg, return_code=1)[source]
handler(msg)[source]
info(msg)[source]
location(msg)[source]
progress(done=None, total=None)[source]
set_level(level)[source]
set_stream_handler(stream_handler)[source]
shellcmd(msg)[source]
text_handler(msg)[source]

The default snakemake log handler. Prints the output to the console. :param msg: the log message dictionary :type msg: dict

warning(msg)[source]
paks.logger.setup_logger(quiet=False, printshellcmds=False, nocolor=False, stdout=False, debug=False, use_threads=False, wms_monitor=None)[source]

paks.backends module

paks.backends.get_container_backend(name, settings=None)[source]

paks.backends.base module

class paks.backends.base.ContainerName(raw)[source]

Bases: object

Parse a container name into named parts

property extended_name
property name
parse(raw)[source]

Parse a name into known pieces

property slug
class paks.backends.base.ContainerTechnology(settings=None)[source]

Bases: object

A base class for a container technology

clean(string_input)[source]
encode(msg)[source]
get_history(line, openpty)[source]

Given an input with some number of up/down and newline, derive command.

interactive_command(cmd)[source]

Ensure we always restore original TTY otherwise terminal gets messed up

run_executor(string_input, openpty)[source]

Given a string input, run executor

welcome(openpty)[source]

Welcome the user and clear terminal

paks.backends.docker module

class paks.backends.docker.DockerContainer(image, settings=None)[source]

Bases: paks.backends.base.ContainerTechnology

A Docker container controller.

add_registry(uri)[source]

Given a “naked” name, add the registry if it’s Docker Hub

command = 'docker'
run(shell)[source]

Interactive shell into a container image.

paks.backends.podman module

class paks.backends.podman.PodmanContainer(image, settings=None)[source]

Bases: paks.backends.docker.DockerContainer

A Podman container controller, which is the same as Docker.

command = 'podman'
shell(image)[source]

Interactive shell into a container image.

paks.commands module

class paks.commands.DockerCommands(container_tech)[source]

Bases: object

get_executor(name, out=None)[source]

Backend is required to update history

has_command(name)[source]
property history
parse_name(cmd)[source]
required = ['container_name', 'name']

paks.commands.command module

class paks.commands.command.Command(tech, required=None, out=None)[source]

Bases: object

Class method to invoke shell commands and retrieve output and error. This class is inspired and derived from utils functions in https://github.com/vsoch/scif

check(**kwargs)[source]

Check ensures that:

  1. The container tech of the command matches the class
  2. Required arguments are provided.
decode(line)[source]

Given a line of output (error or regular) decode using the system default, if appropriate

do_print(line, clear=True)[source]
encode(line)[source]
execute(cmd)[source]

Execute a command to the container

execute_get(runcmd, getcmd)[source]

Execute and get runs a command inside the container (pipes to temporary file) and then loads from the outside.

execute_host(cmd)[source]

Execute a command to the host, return out and error

get_args(cmd)[source]

Once we get here, we only care about additional command args.

parse_command(cmd)[source]

this is called when a new command is provided to ensure we have a list. We don’t check that the executable is on the path, as the initialization might not occur in the runtime environment.

parse_kwargs = True
pre_message = None
return_failure(message, out=None, err=None)[source]

Return a failed result (requires a message)

return_success(message=None, out=None, err=None)[source]

Return a successful result

run_command(cmd, output='output')[source]

Wrapper to stream a command, which handles returning a result on error.

run_hidden(cmd)[source]

Run a hidden command.

stream_command(cmd, output='output')[source]

Stream a command and use output or error.

supported_tech = ['docker', 'podman', 'singularity']
class paks.commands.command.Result(out=None, err=None, retval=0, msg=None)[source]

Bases: object

A Result objet holds output and error, and a return value and message

paks.commands.state module

class paks.commands.state.SaveContainer(tech, required=None, out=None)[source]

Bases: paks.commands.command.Command

pre_message = 'Saving container...'
run(**kwargs)[source]

Save a temporary container name back to the main container name Available after check - validated self.kwargs

supported_for = ['docker', 'podman']

paks.utils module

paks.utils.fileio module

paks.utils.fileio.copyfile(source, destination, force=True)[source]

Copy a file from a source to its destination.

paks.utils.fileio.get_file_hash(image_path, algorithm='sha256')[source]

Return an sha256 hash of the file based on a criteria level.

paks.utils.fileio.get_tmpdir(tmpdir=None, prefix='', create=True)[source]

Get a temporary directory for an operation.

paks.utils.fileio.get_tmpfile(tmpdir=None, prefix='')[source]

Get a temporary file with an optional prefix.

paks.utils.fileio.mkdir_p(path)[source]

mkdir_p attempts to get the same functionality as mkdir -p :param path: the path to create.

paks.utils.fileio.mkdirp(dirnames)[source]

Create one or more directories

paks.utils.fileio.print_json(json_obj)[source]

Print json pretty

paks.utils.fileio.read_file(filename, mode='r')[source]

Read a file.

paks.utils.fileio.read_json(filename)[source]
paks.utils.fileio.read_yaml(filename)[source]
paks.utils.fileio.recursive_find(base, pattern=None)[source]

Find filenames that match a particular pattern, and yield them.

paks.utils.fileio.workdir(dirname)[source]

Provide context for a working directory, e.g.,

with workdir(name):
# do stuff
paks.utils.fileio.write_file(filename, content, mode='w')[source]

Write content to a filename

paks.utils.fileio.write_json(content, filename)[source]

paks.utils.names module

class paks.utils.names.RobotNamer[source]

Bases: object

generate(delim='-', length=4, chars='0123456789')[source]
Generate a robot name. Inspiration from Haikunator, but much more
poorly implemented ;)
generate_badge(length=4, chars='0123456789', link=None)[source]

Generate a robot name badge (in markdown).

paks.utils.terminal module

paks.utils.terminal.check_install(software, quiet=True, command='--version')[source]

check_install will attempt to run the singularity command, and return True if installed. The command line utils will not run without this check.

Parameters:
  • software (the software to check if installed) –
  • quiet (should we be quiet? (default True)) –
  • command (the command to use to check (defaults to --version)) –
paks.utils.terminal.confirm_action(question, force=False)[source]

confirm if the user wants to perform a certain action

Parameters:
  • question (the question that will be asked) –
  • force (if the user wants to skip the prompt) –
paks.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

paks.utils.terminal.get_username()[source]
paks.utils.terminal.run_command(cmd, stream=False)[source]

run_command uses subprocess to send a command to the terminal.

Parameters:
  • cmd (the command to send, should be a list for subprocess) –
  • error_message (the error message to give to user if fails,) –
  • failed. (if none specified, will alert that command) –
paks.utils.terminal.which(software, strip_newline=True)[source]

get_install will return the path to where Singularity (or another executable) is installed.