experimentum.Commands package

Submodules

experimentum.Commands.AbstractCommand module

Easily add CLI commands to the app.

There are to possible ways for defining CLI commands in order for them to be added to the CommandManager.

Decorator

The easiest method to define a command is via the AbstractCommand.command() decorator. The decorator accepts some arguments like description or help text in order to descrine the command while the decorated function handles the command execution. The arguments argument accepts a dictionary which each key is the name of the argument and each value is passed to the argparse.add_argument() method:

@command(
    'Some description about what the command does.',
    arguments={
        'integers': {'help': 'Some Help', 'default': 42, 'nargs': '?'},
        '--bar': {'action': 'store_true', 'help': 'Bar Help'}
    }
    help='Short help text.'
)
def foo(app, args):
    print(args)

Class-based

The other way of defining a command is a class based approach. Your command class has to derived from the AbstractCommand class. Just like the decorator you can define description, arguments and a help text. The handle method handles the command execution:

class FooCommand(AbstractCommand):
    description = 'Some description about what the command does'
    arguments = {
        'integers': {'help': 'Some Help', 'default': 42, 'nargs': '?'},
        '--bar': {'action': 'store_true', 'help': 'Bar Help'}
    }
    help='Short help text.'

    def handle(self, app, args):
        print(args)
class experimentum.Commands.AbstractCommand.AbstractCommand

Bases: object

Abstract Command Class.

description

Description of the command.

Type:str
arguments

Optional aguments for the command.

Type:dict
help

Help Text for the command.

Type:str
args

Dictionary with possible passed arguments.

Type:dict
args = {}
arguments = {}
description = ''
handle(app, args)

Handle the command execution.

Parameters:
  • app (App) – Main App class
  • args (dict) – Dictionary with possible passed arguments.
Raises:

NotImplementedError – must be implemented

help = ''
setup(description='', arguments=None, help='')

Set up the command.

Parameters:
  • description (str, optional) – Defaults to ‘’. Description of the command.
  • arguments (dict, optional) – Defaults to None. Optional aguments for the command.
  • help (str, optional) – Defaults to ‘’. Help Text for the command.
experimentum.Commands.AbstractCommand.command(description='', arguments=None, help='')

Command decorator, creates a Command to use with the CommandManager.

Parameters:
  • description (str, optional) – Defaults to ‘’. Description of the command.
  • arguments (dict, optional) – Defaults to None. Arguments for the command.
  • help (str, optional) – Defaults to ‘’. Help text of the command.
Returns:

Return type:

function

experimentum.Commands.CommandManager module

Adding CLI commands to the app and handle their execution.

class experimentum.Commands.CommandManager.ColoredHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)

Bases: argparse.HelpFormatter

HelpFormatter for argparse to create colored output.

add_usage(usage, actions, groups, prefix=None)

Color in Usage and change format.

class experimentum.Commands.CommandManager.CommandManager(app, prog, description='')

Bases: object

CommandManager class registers and manages commands.

app

Main App class.

Type:App
commands

Registered commands.

Type:dict
add_command(name, cmd)

Add a new command to the parser.

Parameters:
  • name (str) – Name of the command
  • cmd (function, AbstractCommand) – Command Handler
commands = {}
dispatch()

Use dispatch pattern to invoke class and let it handle the command.

experimentum.Commands.ExperimentsCommand module

Experiment CLI commands to allow you to run and manage your experiments.

Running experiments

Use the experiments:run command to run an experiment.

Arguments:

name Name of the experiment

Options:

--config=file Use alternative config file (relative to experiments folder).
--progress Toggle visibility of the progress bar.
--n=number Run the experiment n times.
--hide_performance
 Hides the performance table.
-h, --help Show the help message.

Listing experiments

Use the experiments:list command to list status information about all experiments.

Options:

-h, --help Show the help message.

experimentum.Commands.MigrationCommand module

Migration CLI commands to allow you to version control your database schema.

With Migrations your team is able to easily modify and share the database schema to stay up to date. Migrations are typically paired with the Schema Builder which is inspired by the Laravel Schema Builder to easly manage your database’s schema.

Generating Migrations

Use the migration:make command to create a new Migration. This will create the following new Migration class in your migrations folder. In order to determine the order of the migrations, each migration file name contains a timestamp.

Arguments:

name Name of the migration

Migration Structure

Each Migration class contains two methods: Migration.up() and Migration.down(). In the Migration.up() method you add new tables, columns, or indexes to your database. In the Migration.down() method you should revert those changed made in the Migration.up() method.

Inside the Migration class you have access to the Schema Builder to easily create and modify tables. For more information check out its documentation: Schema

Running Migrations

To run the latest outstanding Migration, just use the migration:up command. To revert the last Migration operation, just use the migration:down command.

To roll back all migrations and then execute all migrations, just use the migration:refresh command. This command effectively re-creates your entire database.

To see the status of the migrations, just use the migration:status command. This would output something like this:

|-------------------------------------------+--------|
| Migration                                 | Ran?   |
|-------------------------------------------+--------|
| 20180814111005_create_users_table         | Yes    |
| 20180815101334_add_avater_to_users_table  | No     |
|-------------------------------------------+--------|

experimentum.Commands.PlotCommand module

Plot CLI commands to allow you to generate your plots and charts.

Generating plots and charts

Use the plots:generate command to generate a plot/chart.

Arguments:

name Name of the plot/chart (plot|chart|graph is omitted from the filename).

Options:

-o Output file where the plot is stored at. When omitted the plot is shown directly.
-h, --help Show the help message.

experimentum.Commands.WebGUICommand module

Dispatch and configure the flask web app.

Starting the Server

Use the `webgui command to dispatch a new server instance (http://flask.pocoo.org/docs/1.0/patterns/appdispatch/#app-dispatch).

Options:

--debug Enable the Debugger.
--port Specifiy the port to run server on.
--no-reload Disable the reload when file changes are detected.
-h, --help Show the help message.

Module contents

Import classes for easier importing by other packages/modules.