backend.saver
Handles prepping and saving the Spock config
#
BaseSaver Objectsclass BaseSaver(BaseHandler)
Base class for saving configs
Contains methods to build a correct output payload and then writes to file based on the file extension
Attributes:
_writers
- maps file extension to the correct i/o handler_s3_config
- optional S3Config object to handle s3 access
#
__init__def __init__(s3_config: Optional[_T] = None)
Init function for base class
Arguments:
s3_config
- optional s3Config object for S3 support
#
dict_payloaddef dict_payload(payload: Spockspace) -> Dict
Clean up the config payload so that it can be returned as a dict representation
Arguments:
payload
- dirty payload
Returns:
clean_dict
- cleaned output payload
#
savedef save(payload: Spockspace, path: str, file_name: Optional[str] = None, create_save_path: bool = False, extra_info: bool = True, file_extension: str = ".yaml", tuner_payload: Optional[Spockspace] = None, fixed_uuid: Optional[str] = None) -> None
Writes Spock config to file
Cleans and builds an output payload and then correctly writes it to file based on the specified file extension
Arguments:
payload
- current config payloadpath
- path to savefile_name
- name of file (will be appended with .spock.cfg.file_extension) -- falls back to uuid if Nonecreate_save_path
- boolean to create the path if non-existentextra_info
- boolean to write extra infofile_extension
- what type of file to writetuner_payload
- tuner level payload (unsampled)fixed_uuid
- fixed uuid to allow for file overwrite
Returns:
None
#
_clean_up_values@abstractmethoddef _clean_up_values(payload: Spockspace, remove_crypto: bool = True) -> Dict
Clean up the config payload so it can be written to file
Arguments:
payload
- dirty payloadremove_crypto
- try and remove crypto values if present
Returns:
clean_dict
- cleaned output payload
#
_clean_tuner_values@abstractmethoddef _clean_tuner_values(payload: Spockspace) -> Dict
Cleans up the base tuner payload that is not sampled
Arguments:
payload
- dirty payload
Returns:
clean_dict
- cleaned output payload
#
_clean_outputdef _clean_output(out_dict: Dict) -> Dict
Clean up the dictionary such that it can be written to file
Arguments:
out_dict
- pre-cleaned dictionary
Returns:
clean_dict
- cleaned output payload
#
_recursive_tuple_2_listdef _recursive_tuple_2_list(val: Any) -> Any
Recursively find tuples and cast them to lists
Arguments:
val
- current value of various types
Returns:
modified version of val
#
AttrSaver Objectsclass AttrSaver(BaseSaver)
Base class for saving configs for the attrs backend
Contains methods to build a correct output payload and then writes to file based on the file extension
Attributes:
_writers
- maps file extension to the correct i/o handler
#
__init__def __init__(s3_config: Optional[_T] = None)
Init for AttrSaver class
Arguments:
s3_config
- s3Config object for S3 support
#
_check_list_of_spock_classes@staticmethoddef _check_list_of_spock_classes(val: List, key: str, all_cls: Set) -> List
Finds lists of spock classes and handles changing them to a writeable format
Arguments:
val
- current value that is a listkey
- current dictionary key in the payloadall_cls
- set of all spock classes
#
_recursively_handle_cleandef _recursively_handle_clean(payload: Spockspace, out_dict: Dict, parent_name: Optional[str] = None, all_cls: Optional[Set] = None) -> Dict
Recursively works through spock classes and adds clean data to a dictionary
Given a payload (Spockspace) work recursively through items that don't have parents to catch all parameter definitions while correctly mapping nested class definitions to their base level class thus allowing the output markdown to be a valid input file
Arguments:
payload
- current payload (namespace)out_dict
- output dictionaryparent_name
- name of the parent spock class if nestedall_cls
- all top level spock class definitions
Returns:
out_dict
- modified dictionary with the cleaned data