Thanks Jonathan, I will have a look.
In the meantime, I think I managed to get what I needed by writing a recursive function that inspects the references of a given list of nodes. The function find the references of each node, then look at their ancestors for new references, etc.
I don't think it's necessarily future proof, and I'll keep testing it further, but for now I think I got what I needed.
Please let me know if you guys feel like there is something wrong with what I'm doing.
### RETURNS REFERENCES FROM A GIVEN NODE ###
### Ignores the references inside a hda, as they are considered self contained ###
def getReferences(node):
references = []
if isNodeHDA(node):
references = list(node.references(include_children=False))
### Removes children if referenced in the hda ###
for reference in references:
if isNodeChildOf(reference,node):
references.remove(reference)
else:
references = node.references(include_children=True)
references = list(set(references))
### Removes the node if it references itself ###
if node in references:
references.remove(node)
return references
### RETURNS ALL DEPENDENCIES FOR A GIVEN NODE
def getAllDependencies(nodes, level=0, maxdepth=10):
dependencies = []
if level == maxdepth:
return dependencies
for node in nodes:
references = getReferences(node)
## for each reference, get ancestors
for reference in references:
ancestors = reference.inputAncestors(include_ref_inputs=True,only_used_inputs=False)
newDependencies = getAllDependencies(ancestors,level+1,maxdepth)
newDependencies.append(reference)
for dependency in newDependencies:
if dependency not in dependencies:
dependencies.append(dependency)
result = []
for dependency in dependencies:
if dependency not in nodes:
result.append(dependency)
return result