modelrunner.model.factory module

Functions for creating models and model classes from other input

cleared_default_model(func)[source]

run the function with a cleared _DEFAULT_MODEL and restore it afterwards

Parameters:

func (TFunc) –

Return type:

TFunc

make_model(func, parameters=None, output=None, *, mode='insert', default=False)[source]

create model from a function and a dictionary of parameters

Parameters:
  • func (callable) – The function that will be turned into a Model

  • parameters (dict) – Paramter values with which the model is initialized

  • output (str) – Path where the output file will be written.

  • mode (str or ModeType) – The file mode with which the storage is accessed, which determines the allowed operations. Common options are “read”, “full”, “append”, and “truncate”.

  • default (bool) – If True, set this model as the default one for the current script

Returns:

An instance of a subclass of ModelBase encompassing func

Return type:

ModelBase

make_model_class(func, *, default=False)[source]

create a model from a function by interpreting its signature

Parameters:
  • func (callable) – The function that will be turned into a Model

  • default (bool) – If True, set this model as the default one for the current script

Returns:

A subclass of ModelBase, which encompasses func

Return type:

ModelBase

set_default(func_or_model)[source]

sets the function or model as the default model

The last model that received this flag will be run automatically. This only affects the behavior when the script is run using modelrunner from the command line, e.g., using python -m modelrunner script.py.

Parameters:

func_or_model (callabel or ModelBase, optional) – The function or model that should be called when the script is run.

Returns:

func_or_model, so the function can be used as a decorator

Return type:

TModel