backend.builder
Handles the building/saving of the configurations from the Spock config classes
#
BaseBuilder Objectsclass BaseBuilder(ABC)
Base class for building the backend specific builders
This class handles the interface to the backend with the generic ConfigArgBuilder so that different backends can be used to handle processing
Attributes
_input_classes: list of input classes that link to a backend_graph: Graph, graph of the dependencies between spock classes_max_indent: maximum to indent between help prints_module_name: module name to register in the spock module spacesave_path: list of path(s) to save the configs to_lazy: attempts to lazily find @spock decorated classes registered withinsys.modules["spock"].backend.config_salt: salt use for crypto purposes_key: key used for crypto purposes
#
__init__def __init__(*args, *, max_indent: int = 4, module_name: str, lazy: bool, salt: str, key: ByteString, **kwargs, ,)
Init call for BaseBuilder
Arguments:
*args
- iterable of @spock decorated classesmax_indent
- max indent for pretty print of helpmodule_name
- module name to register in the spock module spacelazy
- lazily find @spock decorated classessalt
- cryptographic saltkey
- cryptographic key**kwargs
- keyword args
#
input_classes@propertydef input_classes()
Returns the graph of dependencies between spock classes
#
dag@propertydef dag()
Returns the underlying graph DAG
#
graph@propertydef graph()
Returns the underlying graph object
#
_make_group_override_parser@staticmethod@abstractmethoddef _make_group_override_parser(parser: argparse.ArgumentParser, class_obj: _C, class_name: str) -> argparse.ArgumentParser
Makes a name specific override parser for a given class obj
Takes a class object of the backend and adds a new argument group with argument names given with name Class.name so that individual parameters specific to a class can be overridden.
Arguments:
parser
- argument parserclass_obj
- instance of a backend classclass_name
- used for module matching
Returns:
parser
- argument parser with new class specific overrides
#
handle_help_infodef handle_help_info() -> None
Handles walking through classes to get help info
For each class this function will search doc and attempt to pull out help information for both the class itself and each attribute within the class
Returns:
None
#
generatedef generate(dict_args: Dict) -> Spockspace
Method to auto-generate the actual class instances from the generated args
Based on the generated arguments groups and the args read in from the config file(s) this function instantiates the classes with the necessary field or attr values
Arguments:
dict_args
- dictionary of arguments from the configs
Returns:
namespace containing automatically generated instances of the classes
#
resolve_spock_space_kwargsdef resolve_spock_space_kwargs(graph: Graph, dict_args: Dict) -> Dict
Build the dictionary that will define the spock space.
This is essentially the meat of the builder. Handles both the cls dep graph and the ref def graph. Based on that merge of the two dependency graphs it cal traverse the dep structure correct to resolve both cls references and var refs
Arguments:
graph
- Dependency graph of nested spock configurationsdict_args
- dictionary of arguments from the configs
Returns:
dictionary containing automatically generated instances of the classes
#
_cast_all_maps@staticmethoddef _cast_all_maps(cls, cls_fields: Dict, changed_vars: Set) -> None
Casts all the resolved references to the requested type
Arguments:
cls
- current spock classcls_fields
- current fields dictionary to attempt cast withinchanged_vars
- set of resolved variables that need to be cast
#
_clean_up_cls_refs@staticmethoddef _clean_up_cls_refs(fields: Dict, spock_space: Dict) -> Dict
Swaps in the newly created cls if it hasn't been instantiated yet
Arguments:
fields
- current field dictionaryspock_space
- current spock space dictionary
Returns:
updated fields dictionary
#
build_override_parsersdef build_override_parsers(parser: argparse.ArgumentParser) -> argparse.ArgumentParser
Creates parsers for command-line overrides
Builds the basic command line parser for configs and help then iterates through each attr instance to make namespace specific cmd line override parsers
Arguments:
parser
- argument parser
Returns:
parser
- argument parser with new class specific overrides
#
_extract_other_typesdef _extract_other_types(typed: _T, module_name: str) -> List
Takes a high level type and recursively extracts any enum or class types
Arguments:
typed
- highest level typemodule_name
- name of module to match
Returns:
return_list
- list of nums (dot notation of module_path.enum_name or module_path.class_name)
#
_extract_fnc@abstractmethoddef _extract_fnc(val, module_name)
Function that gets the nested lists within classes
Arguments:
val
- current attrmodule_name
- matching module name
Returns:
list of any nested classes/enums
#
AttrBuilder Objectsclass AttrBuilder(BaseBuilder)
Attr specific builder
Class that handles building for the attr backend
Attributes
input_classes: list of input classes that link to a backend_configs: None or List of configs to read from_create_save_path: boolean to make the path to save to_desc: description for the arg parser_no_cmd_line: flag to force no command line readssave_path: list of path(s) to save the configs to
#
__init__def __init__(*args, **kwargs)
AttrBuilder init
Arguments:
*args
- list of input classes that link to a backend**kwargs
- any extra keyword args
#
_make_group_override_parser@staticmethoddef _make_group_override_parser(parser: argparse.ArgumentParser, class_obj: _C, class_name: str) -> argparse.ArgumentParser
Makes a name specific override parser for a given class obj
Takes a class object of the backend and adds a new argument group with argument names given with name Class.name so that individual parameters specific to a class can be overridden.
Arguments:
parser
- argument parserclass_obj
- instance of a backend classclass_name
- used for module matching
Returns:
parser
- argument parser with new class specific overrides
#
_extract_fncdef _extract_fnc(val, module_name)
Function that gets the nested lists within classes
Arguments:
val
- current attrmodule_name
- matching module name
Returns:
list of any nested classes/enums