Behaviors

class omnifig.behaviors.base.Behavior(project, **kwargs)

Bases: AbstractBehavior

Recommended parent class for meta rules.

name = None
code = None
priority = 0
num_args = 0
description = None
parse_argv(meta, argv, script_name=None)

Optionally modifies the arguments when the project’s main() is called.

Parameters:
  • meta (Dict[str, Any]) – Meta-data extracted from the argv so far (can be modified here).

  • argv (List[str]) – List of arguments to parse (expected to be sys.argv[1:]).

  • script_name (Optional[str]) – Manually specified name of the script (if not provided, it will be parsed from argv).

Return type:

Optional[List[str]]

Returns:

Modified list of arguments (or None if no modification is needed).

include(meta)

Checks if the current behavior should be included before running the given config.

Parameters:

config – Config object to use.

Return type:

bool

Returns:

True if the behavior should be included, False otherwise.

class omnifig.behaviors.help.Help(project, **kwargs)

Bases: Behavior

When activated, this behavior prints the help message for the current project (and then exits the program).

classmethod format_selected_script(config, entry, verbose=False)

Formats the help message about the selected script.

Return type:

str

classmethod format_scripts(config, entries, verbose=False)

Formats the help message about the available scripts.

Return type:

str

classmethod format_behaviors(config, entries, verbose=False)

Formats the help message about the available behaviors.

Return type:

str

static format_configs(config, entries, verbose=False)

Formats the help message about the available configs.

Return type:

str

classmethod pre_run(meta, config)

When activated, this behavior prints the help message for the current project (and then exits the program).

Parameters:
  • meta (AbstractConfig) – The meta config object (used to check if the behavior is activated with the quiet key)

  • config (AbstractConfig) – The config object to be modified

Return type:

None

Returns:

None

Raises:

TerminationFlag – if the rule is activated, to prevent the script from running

code = 'h'
description = 'Display this help message'
name = 'help'
num_args = 0
priority = 99
class omnifig.behaviors.debug.Debug(project, **kwargs)

Bases: Behavior

When activated, this behavior updates the config object with the config file debug. If for any reason the config file debug has already been loaded, this behavior will do nothing.

Note that only a local debug config is merged, so the debug config file must be registered with the current project.

__init__(project, **kwargs)

Sets up the debug behavior, including setting up a flag to make sure the debug config is only loaded once.

Parameters:
  • project (AbstractProject) – used to create the debug config

  • **kwargs (Any) – passed to super

pre_run(meta, config)

When activated, this behavior updates the config object with the config file debug.

If for any reason the config file debug has already been loaded, this behavior will do nothing.

Parameters:
  • meta (AbstractConfig) – The meta config object (used to check if the behavior is activated with the debug key)

  • config (AbstractConfig) – Config object which will be passed to the script.

Return type:

Optional[AbstractConfig]

Returns:

the config object possibly updated with the debug config file

Raises:

ConfigNotFoundError – if the config file debug does not exist

code = 'd'
description = 'Switch to debug mode'
name = 'debug'
num_args = 0
priority = 100
class omnifig.behaviors.quiet.Quiet(project, **kwargs)

Bases: Behavior

When activated, this behavior sets the config object to silent mode, which means pulls/pushes are not printed to stdout

__init__(project, **kwargs)

Sets the attribute to keep track of what the previous value of config.silent was

pre_run(meta, config)

When activated, this will set the config object to silent mode

Parameters:
  • meta (AbstractConfig) – The meta config object (used to check if the rule is activated with the quiet key)

  • config (AbstractConfig) – The config object to be modified

Return type:

None

Returns:

None

post_run(meta, config, output)

When activated, this rule sets the config back to its previous value

Parameters:
  • meta (AbstractConfig) – The meta config object (not used)

  • config (AbstractConfig) – Config object used to run the script.

  • output (Any) – Output of the script.

Return type:

None

Returns:

None

code = 'q'
description = 'Set config to silent'
name = 'quiet'
num_args = 0
priority = 10