cache.py

This module is responsible for accumulating all loaded objects and making sure they are available in the xxx.db virtual module. It is used extensively in load_conf.load_conf.

class hutch_python.cache.LoadCache(module, hutch_dir=None, **objs)

Class that accumulates objects in a virtual module.

This virtual module can be imported from as if it were a normal module.

Parameters:
  • module (str) – Name of the virtual module to create. If the module has the same name as a real module, the real module will be masked.

  • hutch_dir (Path, optional) – This allows us to write a db.txt file to let the user know what objects get imported.

  • **objs (kwargs) – Initial objects to place into the namespace

objs

This is a namespace containing all the objects that have been attached to the LoadCache.

Type:

HelpfulNamespace

__call__(**objs)

Add objects to the namespace.

Parameters:

**objs (kwargs) – The key will is the namespace-accessible name, and the object is the object we are adding.

doc(**docs)

Add docstrings to the cached objects.

Parameters:

**objs (kwargs) – The key should be the object name, the value should be documentation about that object and why it is included.

spoof_module(module_name)

Create a fake module that is actually self.objs

write_file()

Write a db.txt file in the hutch’s directory. This file informs the user which objects get loaded by hutch-python.