backend.saver
Handles prepping and saving the Spock config
BaseSaver Objects#
class 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_payload#
def dict_payload(payload: Spockspace) -> DictClean up the config payload so that it can be returned as a dict representation
Arguments:
payload- dirty payload
Returns:
clean_dict- cleaned output payload
save#
def 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) -> NoneWrites 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) -> DictClean 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) -> DictCleans up the base tuner payload that is not sampled
Arguments:
payload- dirty payload
Returns:
clean_dict- cleaned output payload
_clean_output#
def _clean_output(out_dict: Dict) -> DictClean 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_list#
def _recursive_tuple_2_list(val: Any) -> AnyRecursively find tuples and cast them to lists
Arguments:
val- current value of various types
Returns:
modified version of val
AttrSaver Objects#
class 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) -> ListFinds 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_clean#
def _recursively_handle_clean(payload: Spockspace, out_dict: Dict, parent_name: Optional[str] = None, all_cls: Optional[Set] = None) -> DictRecursively 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