mlos_bench.services.local.temp_dir_context

Helper functions to work with temp files locally on the scheduler side.

Classes

TempDirContextService

A base service class that provides a method to create a temporary directory

Module Contents

class mlos_bench.services.local.temp_dir_context.TempDirContextService(config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: mlos_bench.services.base_service.Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)[source]

Bases: mlos_bench.services.base_service.Service

A base service class that provides a method to create a temporary directory context for local scripts.

It is inherited by LocalExecService and MockLocalExecService. This class is not supposed to be used as a standalone service.

Create a new instance of a service that provides temporary directory context for local exec service.

Parameters:
  • config (dict) – Free-format dictionary that contains parameters for the service. (E.g., root path for config files, etc.)

  • global_config (dict) – Free-format dictionary of global parameters.

  • parent (Service) – An optional parent service that can provide mixin functions.

  • methods (Union[Dict[str, Callable], List[Callable], None]) – New methods to register with the service.

temp_dir_context(path: str | None = None) tempfile.TemporaryDirectory | contextlib.nullcontext[source]

Create a temp directory or use the provided path.

Parameters:

path (str) – A path to the temporary directory. Create a new one if None.

Returns:

temp_dir_context – Temporary directory context to use in the with clause.

Return type:

tempfile.TemporaryDirectory