Skip to content

Utils


GlobalImport

Convenient context manager for lazy importing of modules within a Pipe declaration. Since the lazily loaded modules are added to globals(), you can reference them anywhere in your pipeline runtime so long as the reference occurs after the context manager.

Examples:

# After the next two lines, `os` will be available for reference globally.
with GlobalImport(globals()):
    import os

__init__(self, gbls) special

Parameters:

Name Type Description Default
gbls dict

You must pass globals() upon use.

required

function_call_stack()

Returns the function call stack context. source: https://stackoverflow.com/a/2654130

hash_path(path)

Creates a UTF-8 SHA1 hash of an input string.

Parameters:

Name Type Description Default
path str

The string value to hash.

required

Returns:

Type Description
str

UTF-8 SHA1 hash of path.

load_config_file(path)

Load a YAML file into a dict. Extensions accepted are {.yml, .yaml}.

Parameters:

Name Type Description Default
path str

The relative path to the YAML file to load.

required

Returns:

Type Description
Dict[str, Any]

A dict version of the YAML file.

pickle(path, value)

Function that pickles an object to the location specified by path.

Parameters:

Name Type Description Default
path str

The file path for the pickle file that will be created.

required
value Any

The object to pickle.

required

recursive_update(default, custom)

Recursively update nested dict default with the values of nested dict custom. Values present in custom but not present in default will be added to default.

NOTE: this function operates inplace in default.

Parameters:

Name Type Description Default
default Dict[str, Any]

The dict whose values will be updated by the matching values of custom.

required
custom Dict[str, Any]

The dict whose values will update the matching values of default.

required

Returns:

Type Description
Dict[str, Any]

Updated version of default containing the values of custom.

unpickle(path)

Function that loads a pickle file generated by pickle(path).

Parameters:

Name Type Description Default
path str

File path to a valid pickle file.

required

Returns:

Type Description
Any

The unpickled object.