earthkit.data.core.temporary

Classes

TmpDirectory

Create and return a temporary directory. This has the same

TmpEnv

A context manager that temporarily sets environment variables.

TmpFile

The TmpFile objects are designed to be used for temporary files.

Functions

temp_directory([dir])

temp_env(**kwargs)

temp_file([extension])

Create a temporary file with the given extension .

Module Contents

class earthkit.data.core.temporary.TmpDirectory(*args, **kwargs)

Bases: tempfile.TemporaryDirectory

Create and return a temporary directory. This has the same behavior as mkdtemp but can be used as a context manager. For example:

with TemporaryDirectory() as tmpdir:

Upon exiting the context, the directory and everything contained in it are removed.

property path
class earthkit.data.core.temporary.TmpEnv(**kwargs)

A context manager that temporarily sets environment variables.

Usage: >>> import os >>> with TmpEnv(CLIMETLAB_TESTS_FOO=”123”, CLIMETLAB_TESTS_BAR=”456”): … print(os.environ[“CLIMETLAB_TESTS_FOO”]) … print(os.environ[“CLIMETLAB_TESTS_BAR”]) … 123 456 >>> print(os.environ.get(“CLIMETLAB_TESTS_FOO”)) None

kwargs
previous
class earthkit.data.core.temporary.TmpFile(path)

The TmpFile objects are designed to be used for temporary files. It ensures that the file is unlinked when the object is out-of-scope (with __del__).

Parameters:

path (str) – Actual path of the file.

cleanup()
path
earthkit.data.core.temporary.temp_directory(dir=None)
earthkit.data.core.temporary.temp_env(**kwargs)
earthkit.data.core.temporary.temp_file(extension='.tmp')

Create a temporary file with the given extension .

Parameters:

extension (str, optional) – By default “.tmp”

Return type:

TmpFile