mframework package¶
Submodules¶
mframework._docgen module¶
Documentation generator for user models
-
mframework._docgen.doc2rst(mspec, dir_path=None)¶ Convert model documentation to RST
- Args:
- mspec
(obj) model specification
- Returns:
- rst
(str) RST documentation
- file_path
(str) output file
-
mframework._docgen.gen_feature_graph(mspec)¶ Generate a graph listing all the available features
- Args:
- mspec
(obj) model specification
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.gen_graph_property_relation(prop_name, parent_feature)¶ Return a graph showing the relation between a property and parent feature
- Args:
- prop_name
(str) name of the property
- parent_feature
(str) name of the parent feature
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.get_header(string, level=0)¶ Make a header
- Args:
- string
(str) header
- level
(int) header level
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.get_section_link(header)¶ Add a section link
- Args:
- header
(str) section header
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.model_user_space_doc(mspec, header='Model', intro='')¶ Auto-generate user documentation from a model specification
- Args:
- mspec
(obj) model specification
- header
(str) page header
- intro
(str) introduction below header
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.rst_add_icon(icon_type)¶ Add an icon
- Args:
- icon_type
(str) key from ‘ICONS’ dict
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.schemadict2rst(sd)¶ Return a readable presentation of a property schema
- Args:
- sd
(dict) ‘schemadict’
- Returns:
- rst
(str) RST documentation
-
mframework._docgen.write2file(file_path, text)¶
mframework._log module¶
Logger for debug purposes
mframework._mframework module¶
Model framework¶
| User space | Specification
| ---------- | -------------
| |
| Model | <--- ModelSpec
| | | |
| | | |
| Feature | (<---) FeatureSpec
| | |
| | |
| (Properties) |
-
class
mframework._mframework.FeatureSpec¶ Bases:
mframework._mframework._BaseSpec-
add_prop_spec(key, schema, *, required=1, max_items=inf, doc='', uid_required=False)¶ Add a property specification entry
- Args:
- key
(str) name of property to specify
- schema
(obj) specification (primitive type, or ‘schemadict’)
- required
(int) number of required items
- max_items
(int) maximum number of items
- doc
(str) documentation
- uid_required
(str) if True, UID must be set
-
property
user_class¶ Return a ‘Feature’ class with user and user methods
-
-
class
mframework._mframework.ModelSpec¶ Bases:
mframework._mframework._BaseSpec-
_abc_impl= <_abc_data object>¶
-
add_feature_spec(key, feature_spec, *, required=1, max_items=inf, doc='', uid_required=False)¶ Add a feature specification entry
- Args:
- key
(str) name of feature to specify
- schema
(obj) specification (instance of FeatureSpec)
- required
(int) number of required items
- max_items
(int) maximum number of items
- doc
(str) documentation
- uid_required
(str) if True, UID must be set
-
property
results¶
-
property
user_class¶ Return a ‘Model’ class with user and user methods
-
-
class
mframework._mframework.SpecDict(*args, **kwargs)¶ Bases:
mframework._utils.UniqueDictSpecification dictionary.
Specification entries can only be defined once.
-
_abc_impl= <_abc_data object>¶
-
class
mframework._mframework.SpecEntry(schema, required=1, max_items=inf, doc='', uid_required=False)¶ Bases:
object-
property
doc¶
-
property
max_items¶
-
property
required¶
-
property
schema¶
-
property
singleton¶
-
property
uid_required¶
-
property
-
class
mframework._mframework._BaseSpec¶ Bases:
object-
_add_item_spec(key, schema, *, required=1, max_items=inf, doc='', uid_required=False)¶ Add a specification entry
- Args:
- key
(str) name of item to specify
- schema
(obj) specification
- required
(int) number of required items
- max_items
(int) maximum number of items
- doc
(str) documentation
- uid_required
(str) if True, UID must be set
- Note:
- ‘schema’ should be a primitive type or a ‘schemadict’ if a this
class describes a feature. It should be an instance of ‘FeatureSpec’ if this class describes a model.
When calling from subclass, add a user input check for ‘schema’
-
_provide_user_class_from_base(base)¶ Return a user space class which subclasses from ‘base’
- Args:
- base
(obj) base class
- Returns:
- UserSpace
(obj) user space class with specification reference
-
get_docs()¶ Return user documentation
- Returns:
- docs
(dict) full documentation
-
property
keys¶ Return all spec keys
-
-
class
mframework._mframework._FeatureUserSpace¶ Bases:
mframework._mframework._UserSpaceBase-
_level= '$feature'¶
-
-
class
mframework._mframework._ModelUserSpace¶ Bases:
mframework._mframework._UserSpaceBase-
_abc_impl= <_abc_data object>¶
-
_check_required_items()¶ Check if user model instance defines all required features and properties
-
_level= '$model'¶
-
_result_user_class= None¶
-
add(key, _)¶ Add a value (non-singleton)
- Args:
- key
(str) name of item to specify
- value
(obj) value of the item to specify
-
add_feature(key, *, uid=None)¶ Add a non-singleton feature
- Args:
- key
(str) name of the feature
- Returns:
- feature
(obj) feature instance
-
from_dict(dictionary)¶ Add user values from a dictionary
- Args:
- dictionary
(dict) key-value pairs
- Returns:
- self
(obj) reference to self
-
abstract
run(*args, **kwargs)¶ The ‘run()’ method is the main entry point for evaluating the user model. This method needs to be overridden in the subclass. The ‘run()’ method should return an instance of ‘_result_user_class’. When implementing ‘run()’ in the subclass, the superclass ‘run()’ method should first be called with ‘super().run()’.
-
set(key, _)¶ Set a value (singleton)
- Args:
- key
(str) name of item to specify
- value
(obj) value of the item to specify
-
set_feature(key)¶ Make a singleton feature
- Args:
- key
(str) name of the feature
- Returns:
- feature
(obj) feature instance
-
to_dict()¶ Represent model as a dictionary
- Returns:
- dictionary
(dict) key-value pairs
-
-
class
mframework._mframework._UserSpaceBase¶ Bases:
object-
_check_against_schema(key, value)¶
-
_check_below_max_items(key)¶
-
_check_key_in_spec(key)¶
-
_check_uid_required(key, uid)¶
-
_level= '$NONE'¶
-
_parent_specs= None¶
-
_parent_uid= None¶
-
add(key, value, uid=None)¶ Add a value (non-singleton)
- Args:
- key
(str) name of item to specify
- value
(obj) value of the item to specify
-
add_many(key, *values)¶ Add multiple items (non-singleton)
Method does not support keys which require UIDs
- Args:
- key
(str) name of property to specify
- values
(obj) values of the item to specify
-
clear()¶
-
from_dict(d)¶ Add user values from a dictionary
- Args:
- d
(dict) key-value pairs
- Returns:
- self
(obj) reference to self
-
get(key, default=None, *, uid=None)¶ Return a value (singleton/non-singleton)
- Args:
- key
(str) name of item
- uid
(str) return a named item
- default
(obj) value returned if value is not found in items
- Returns:
- value
(obj) value of the item
-
get_default(key)¶ Return the model/feature default values
-
get_uid(key, idx)¶
-
iter(key)¶ Return an iterator for values of ‘key’ (non-singleton)
- Args:
- key
(str) name of item
-
iter_uids(key)¶ Return an iterator for values of ‘key’ (non-singleton)
- Args:
- key
(str) name of item
-
property
keys¶ Return all item keys
-
len(key)¶
-
remove()¶
-
set(key, value)¶ Set a value (singleton)
- Args:
- key
(str) name of item to specify
- value
(obj) value of the item to specify
-
singleton(key)¶ Return True if ‘key’ specifies singleton items
- Args:
- key
(str) name of item
-
to_dict()¶ Represent model/feature as a dictionary
- Returns:
- dictionary
(dict) key-value pairs
-
-
mframework._mframework.check_type(var_name, var, exp_type)¶
-
mframework._mframework.is_primitve_type(obj)¶
mframework._serialize module¶
mframework._utils module¶
Utils
-
class
mframework._utils.DictLike(*args, **kwargs)¶ Bases:
collections.abc.MutableMapping-
_abc_impl= <_abc_data object>¶
-
-
class
mframework._utils.ItemDict(*args, **kwargs)¶ Bases:
mframework._utils.UIDDict-
_abc_impl= <_abc_data object>¶
-
-
class
mframework._utils.UIDDict(*args, **kwargs)¶ Bases:
collections.abc.MutableMapping-
_abc_impl= <_abc_data object>¶
-
assign_uid(kmain, uid, idx=- 1)¶ Assign a UID to a specific value
- Args:
- kmain
(str) main key (= type)
- uid
(str) unique identifier
- idx
(int) item index
Note:
By default, the UID will be assigned to the ‘last’ entry
-
get_by_uid(kmain, uid)¶ Return the value for a UID
- Args:
- kmain
(str) main key (= type)
- uid
(str) unique identifier
-
get_uid(kmain, idx, default=None)¶ Return the value for a UID
- Args:
- kmain
(str) main key (= type)
- idx
(int) item index
-
iter_from_to(kmain, uid1, uid2)¶ Yield values from a UID1 to UID2
- Args:
- kmain
(str) main key (= type)
- uid1
(str) first UID
- uid2
(str) second UID
-
iter_uids(kmain)¶ Yield (uid, value) for a main key
- Args:
- kmain
(str) main key (= type)
-
len_of_type(kmain)¶
-
-
class
mframework._utils.UniqueDict(*args, **kwargs)¶ Bases:
mframework._utils.DictLikeValues cannot be reassigned if a key is already in the dictionary.
-
_abc_impl= <_abc_data object>¶
-