Topological sort of a graph, allowing better console (and other) outputs.
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.
This commit is contained in:
@ -200,6 +200,9 @@ class ValueHolder:
|
||||
def __invert__(self):
|
||||
return ~self.value
|
||||
|
||||
def __len__(self):
|
||||
return len(self.value)
|
||||
|
||||
|
||||
def get_attribute_or_create(obj, attr, default):
|
||||
try:
|
||||
@ -207,4 +210,3 @@ def get_attribute_or_create(obj, attr, default):
|
||||
except AttributeError:
|
||||
setattr(obj, attr, default)
|
||||
return getattr(obj, attr)
|
||||
|
||||
|
||||
22
bonobo/util/python.py
Normal file
22
bonobo/util/python.py
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
||||
Reference in New Issue
Block a user