Activity Base Class (rever.activity)

Provides basic activity funtionality.

class rever.activity.Activity(*, name=None, deps=frozenset({}), func=None, undo=None, setup=None, check=None, requires=None, args=None, kwargs=None, desc=None)

Activity representing a node in DAG of release tasks.

Parameters
namestr, optional

Name of the activity.

depsset of str, optional

Set of activities that must be completed before this activity is executed.

funccallable, optional

Function to perform as activity when this activities is executed (called).

undocallable, optional

Function to undo this activities behaviour and reset the repo state.

setupcallable, optional

Function to help initialize the activity.

checkcallable, optional

Function to check if the activity can be run sucessfully on the user’s machine, with their credentials, etc. This function should return True if the activity can be run, and False otherwise.

requiresdict or None, optional

A dict of dicts of the following form that specifies the command line utility and import requirements for this activity.

{
    "commands": {"<cli name>": "<package name>", ...}
    "imports": {"<module name>": "<package name>", ...}
}

The top-level keys are both optional, and this will default to an empty dict.

argstuple, optional

Arguments to be supplied to the func(*args), if needed.

kwargsmapping, optional

Keyword arguments to be supplied to the func(**kwargs), if needed.

descstr, optional

A short description of this activity

all_kwargs()

Returns all kwargs for this activity.

check()

Calls this activity’s check() function.

check_requirements()

Checks that an activities requirements are actually available.

checker(check)

Decorator that sets the check function for this activity.

clear_kwargs_from_env()

Removes kwarg from the environment, if they exist.

kwargs_from_env()

Obtains possible func() kwarg from the environment.

setup()

Calls this activity’s setup() initialization function.

setupper(setup)

Decorator that sets the setup function for this activity.

undo()

Reverts to the last instance of this activity. This default implementation uses the revision in the log file from the last time that the activity was started. This may be overridden in a subclass.

undoer(undo)

Decorator that sets the undo function for this activity.

property env_names

Dictionary mapping parameter names to the names of environment varaibles that the activity looks for when it is executed.

class rever.activity.DockerActivity(*, name=None, deps=frozenset({}), func=None, undo=None, requires=None, check=None, desc=None, image=None, lang='xonsh', run_args=('-c'), code=None, env=True, mounts=())

An activity that executes within a docker container.

A Docker activity, by default will respect the following environment variables, if they are set:

$<NAME>_IMAGE

str, Name of the image to run, defaults to $DOCKER_INSTALL_IMAGE. Environment variables will be expanded when the activity is run.

$<NAME>_LANG

str, Language to execute the body in, default xonsh. This may also be a full path to an executable.

$<NAME>_ARGS

sequence of str, Extra arguments to pass in after the executable but before the main body. Defaults to the standard compile flag '-c'.

$<NAME>_ENV

bool or dict, Environment to use. This has the same meaning as in rever.docker.run_in_container(). Please see that function for more details, default True.

$<NAME>_MOUNT

list of dict, Locations to mount in the running container. This has the same meaning as in rever.docker.run_in_container(). Please see that function for more details, default does not mount anything.

Additionally, DockerActivities are macro context managers. This allows you to set the code block by entering the context:

with! DockerActivity(name='myactivity'):
    echo "I will be run in the docker container!"

Entering the context manager will also automatically register the activity in the DAG.

Parameters
namestr, optional

Name of the activity.

depsset of str, optional

Set of activities that must be completed before this activity is executed.

funccallable, optional

Function to perform as activity when this activities is executed (called). The default _func method is good enough for most cases.

undocallable, optional

Function to undo this activities behaviour and reset the repo state.

checkcallable, optional

Function to check if the activity can be run sucessfully on the user’s machine, with their credentials, etc. This function should return True if the activity can be run, and False otherwise.

requiresdict or None, optional

A dict of dicts of the following form that specifies the command line utility and import requirements for this activity.

{
    "commands": {"<cli name>": "<package name>", ...}
    "imports": {"<module name>": "<package name>", ...}
}

The top-level keys are both optional, and this will default to an empty dict. The docker command will be automatically added to the commands dict.

descstr, optional

A short description of this activity

imagestr or None, optional

Name of the image to run, defaults to $DOCKER_INSTALL_IMAGE. Environment variables will be expanded when the activity is run.

langstr, optional

Language to execute the body in, default xonsh. This may also be a full path to an executable.

run_argssequence of str, optional

Extra arguments to pass in after the executable but before the main body. Defaults to the standard compile flag '-c'.

codestr or None, optional

The code to execute in the docker container with lang. If this is None, it may be on the instance itself, passed in when the activity is called, or set by entering the activity as a macro context manager. In this last case, the context block is set as the code.

envbool or dict, optional

Environment to use. This has the same meaning as in rever.docker.run_in_container(). Please see that function for more details, default True.

mountslist of dict, optional

Locations to mount in the running container. This has the same meaning as ing run_in_container(). Please see that function for more details, default does not mount anything.

all_kwargs()

Returns all kwargs for this activity.

check()

Calls this activity’s check() function.

check_requirements()

Checks that an activities requirements are actually available.

checker(check)

Decorator that sets the check function for this activity.

clear_kwargs_from_env()

Removes kwarg from the environment, if they exist.

kwargs_from_env()

Obtains possible func() kwarg from the environment.

setup()

Calls this activity’s setup() initialization function.

setupper(setup)

Decorator that sets the setup function for this activity.

undo()

Reverts to the last instance of this activity. This default implementation uses the revision in the log file from the last time that the activity was started. This may be overridden in a subclass.

undoer(undo)

Decorator that sets the undo function for this activity.

property code

Get’s the code to execute in the docker container.

property env_names

Dictionary mapping parameter names to the names of environment varaibles that the activity looks for when it is executed.

rever.activity.activity(name=None, deps=frozenset({}), undo=None, setup=None, check=None, desc=None)

A decorator that turns the function into an activity. The arguments here have the same meaning as they do in the Activity class constructor. This decorator also registers the activity in the $DAG.

rever.activity.dockeractivity(**kwargs)

Returns a new docker activity. This accepts the same keyword arguments as the DockerActivity class.