hornet.loading – Module Loading

The hornet.loading module provides utilities for the loading of classes and objects dynamically. Most of these tools are used to assist in the loading plugins.

Module author: John Paulett <john.paulett -at- vanderbilt.edu>

hornet.loading.find_instances(module, cls)

Finds the instance of cls in the given module.

>>> instance = find_instance('module', Class) #doctest: +SKIP
hornet.loading.full_import(name)
Returns the modules specified by name. Workaround to import sub-modules, as described in the Python builtin docs.
hornet.loading.load(module, name)

Loads a function or class specified by name from a module.

>>> f = load('hornet.loading', 'load')
>>> f.__module__
'hornet.loading'
>>> f.__name__
'load'
hornet.loading.load_class(filename, cls)

Wrapper for :func:`hornet.loading.find_class’ that finds the cls in a file that is not necessarily on sys.path, specified by filename.

>>> instance = load_class('../config.py', Class) #doctest: +SKIP
hornet.loading.path_components(filename)

Takes a path (relative or absolute) to a file, specified by filename, and returns the full path directory, the name with the extension, and the file extension (including a period), as a tuple.

>>> dir, mod, ext = path_components('loading.py') #doctest: +SKIP
('/home/hornet/', 'loading', '.py')

Previous topic

hornet.file – File Interactions

Next topic

hornet.network – Graph Representations & Interactions

This Page