flambe.runnable.context

Module Contents

flambe.runnable.context.logger[source]
class flambe.runnable.context.SafeExecutionContext(yaml_file: str)[source]

Context manager handling the experiment’s creation and execution.

Parameters:yaml_file (str) – The experiment filename
__enter__(self)[source]

A SafeExecutionContext should be used as a context manager to handle all possible errors in a clear way.

Examples

>>> with SafeExecutionContext(...) as ex:
>>>     ...
__exit__(self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], tb: Optional[TracebackType])[source]

Exit method for the context manager.

This method will catch any exception, and return True. This means that all exceptions produced in a SafeExecutionContext (used with the context manager) will not continue to raise.

preprocess(self, secrets: Optional[str] = None, download_ext: bool = True, install_ext: bool = False, import_ext: bool = True, check_tags: bool = True, **kwargs)[source]

Preprocess the runnable file.

Looks for syntax errors, import errors, etc. Also injects the secrets into the runnables.

If this method runs and ends without exceptions, then the experiment is ok to be run. If this method raises an Error and the SafeExecutionContext is used as context manager, then the __exit__ method will be executed.

Parameters:
  • secrets (Optional[str]) – Optional path to the secrets file
  • install_ext (bool) – Whether to install the extensions or not. This process also downloads the remote extensions. Defaults to False
  • install_ext – Whether to import the extensions or not. Defaults to True.
  • check_tags (bool) – Whether to check that all tags are valid. Defaults to True.
Returns:

A tuple containing the compiled Runnable and a dict containing the extensions the Runnable uses.

Return type:

Tuple[Runnable, Dict[str, str]]

Raises:

Exception – Depending on the error.

first_parse(self)[source]

Check if valid YAML file and also load config

In this first parse the runnable does not get compiled because it could be a custom Runnable, so it needs the extensions to be imported first.

check_tags(self, content: str)[source]

Check that all the tags are valid.

Parameters:content (str) – The content of the YAML file
Raises:TagError
compile_runnable(self, content: str)[source]

Compiles and returns the Runnable.

IMPORTANT: This method should run after all extensions were registered.

Parameters:content (str) – The runnable, as a YAML string
Returns:The compiled experiment.
Return type:Runnable