Skip to main content

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) -> 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

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) -> 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 payload
  • path - path to save
  • file_name - name of file (will be appended with .spock.cfg.file_extension) -- falls back to uuid if None
  • create_save_path - boolean to create the path if non-existent
  • extra_info - boolean to write extra info
  • file_extension - what type of file to write
  • tuner_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 payload
  • remove_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_output#

def _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_list#

def _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 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) -> List

Finds lists of spock classes and handles changing them to a writeable format

Arguments:

  • val - current value that is a list
  • key - current dictionary key in the payload
  • all_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) -> 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 dictionary
  • parent_name - name of the parent spock class if nested
  • all_cls - all top level spock class definitions

Returns:

  • out_dict - modified dictionary with the cleaned data