Uses algorithm borrowed from networkx graph library to sort a graph in topological order. The method is only used by output plugins, as internal plumbery does not really care about the node order. Also includes a bonobo.util.python.require function that helps importing thing in a package-less context, or when there are conflict with site package names.
23 lines
610 B
Python
23 lines
610 B
Python
import inspect
|
|
import os
|
|
import runpy
|
|
|
|
|
|
class _RequiredModule:
|
|
def __init__(self, dct):
|
|
self.__dict__ = dct
|
|
|
|
|
|
class _RequiredModulesRegistry(dict):
|
|
def require(self, name):
|
|
if name not in self:
|
|
bits = name.split('.')
|
|
pathname = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.stack()[1][0])))
|
|
filename = os.path.join(pathname, *bits[:-1], bits[-1] + '.py')
|
|
self[name] = _RequiredModule(runpy.run_path(filename, run_name=name))
|
|
return self[name]
|
|
|
|
|
|
registry = _RequiredModulesRegistry()
|
|
require = registry.require
|