rez.serialise#

Read and write data from file. File caching via a memcached server is supported.

class rez.serialise.FileFormat#

Bases: Enum

py = ('py',)#
yaml = ('yaml',)#
txt = ('txt',)#
rez.serialise.open_file_for_write(filepath, mode=None)#

Writes both to given filepath, and tmpdir location.

This is to get around the problem with some NFS’s where immediately reading a file that has just been written is problematic. Instead, any files that we write, we also write to /tmp, and reads of these files are redirected there.

Parameters:
  • filepath (str) – File to write.

  • mode (int) – Same mode arg as you would pass to os.chmod.

Yields:

File-like object.

rez.serialise.load_from_file(filepath, format_=FileFormat.py, update_data_callback=None, disable_memcache=False)#

Load data from a file.

Note

Any functions from a .py file will be converted to SourceCode objects.

Parameters:
  • filepath (str) – File to load.

  • format (FileFormat) – Format of file contents.

  • update_data_callback (Callable) – Used to change data before it is returned or cached.

  • disable_memcache (bool) – If True, don’t r/w to memcache.

Return type:

dict

rez.serialise.get_objects()#

Get currently bound variables for evaluation of early-bound attribs.

Returns:

dict.

rez.serialise.set_objects(objects)#

Set the objects made visible to early-bound attributes.

For example, objects might be used to set a ‘build_variant_index’ var, so that an early-bound ‘private_build_requires’ can change depending on the currently-building variant.

Parameters:

objects (dict) – Variables to set.

rez.serialise.load_py(stream, filepath=None)#

Load python-formatted data from a stream.

Parameters:

stream (IO) –

Return type:

dict

class rez.serialise.EarlyThis#

Bases: object

The this object for @early bound functions.

Just exposes raw package data as object attributes.

__init__(data)#
rez.serialise.process_python_objects(data, filepath=None)#

Replace certain values in the given package data dict.

Does things like:

  • evaluates @early decorated functions, and replaces with return value;

  • converts functions into SourceCode instances so they can be serialized out to installed packages, and evaluated later;

  • strips some values (modules, __-leading variables) that are never to be part of installed packages.

Returns:

Updated dict.

Return type:

dict

rez.serialise.load_yaml(stream, **kwargs)#

Load yaml-formatted data from a stream.

Parameters:

stream (IO) –

Return type:

dict

rez.serialise.load_txt(stream, **kwargs)#

Load text data from a stream.

Parameters:

stream (IO) –

Return type:

str

rez.serialise.clear_file_caches()#

Clear any cached files.