[core] Do not write outputs, internal folder and parallelization in templates

For every node, the only information that is kept when saving a
template are the non-default input attributes' values as well as the
node's position.

The unit test checking the templates' nodes is updated to stop taking
outputs into account.
This commit is contained in:
Candice Bentéjac 2022-10-21 16:54:17 +02:00
parent c9ade6c0c3
commit 10844747f0
2 changed files with 10 additions and 16 deletions

View file

@ -1206,7 +1206,7 @@ class Graph(BaseObject):
if template: if template:
data = { data = {
Graph.IO.Keys.Header: self.header, Graph.IO.Keys.Header: self.header,
Graph.IO.Keys.Graph: self.getNonDefaultAttributes() Graph.IO.Keys.Graph: self.getNonDefaultInputAttributes()
} }
else: else:
data = { data = {
@ -1220,20 +1220,22 @@ class Graph(BaseObject):
if path != self._filepath and setupProjectFile: if path != self._filepath and setupProjectFile:
self._setFilepath(path) self._setFilepath(path)
def getNonDefaultAttributes(self): def getNonDefaultInputAttributes(self):
""" """
Instead of getting all the inputs/outputs attribute keys, only get the keys of Instead of getting all the inputs attribute keys, only get the keys of
the attributes whose value is not the default one. the attributes whose value is not the default one.
The output attributes, UIDs, parallelization parameters and internal folder are
not relevant for templates, so they are explicitly removed from the returned dictionary.
Returns: Returns:
dict: self.toDict() with all the inputs/outputs attributes with default values removed dict: self.toDict() with the output attributes, UIDs, parallelization parameters, internal folder
and input attributes with default values removed
""" """
graph = self.toDict() graph = self.toDict()
for nodeName in graph.keys(): for nodeName in graph.keys():
node = self.node(nodeName) node = self.node(nodeName)
inputKeys = list(graph[nodeName]["inputs"].keys()) inputKeys = list(graph[nodeName]["inputs"].keys())
outputKeys = list(graph[nodeName]["outputs"].keys())
for attrName in inputKeys: for attrName in inputKeys:
attribute = node.attribute(attrName) attribute = node.attribute(attrName)
@ -1241,13 +1243,10 @@ class Graph(BaseObject):
if attribute.isDefault and not attribute.isLink: if attribute.isDefault and not attribute.isLink:
del graph[nodeName]["inputs"][attrName] del graph[nodeName]["inputs"][attrName]
for attrName in outputKeys: del graph[nodeName]["outputs"]
attribute = node.attribute(attrName)
# check that attribute is not a link for choice attributes
if attribute.isDefault and not attribute.isLink:
del graph[nodeName]["outputs"][attrName]
del graph[nodeName]["uids"] del graph[nodeName]["uids"]
del graph[nodeName]["internalFolder"]
del graph[nodeName]["parallelization"]
return graph return graph

View file

@ -38,7 +38,6 @@ def test_templateVersions():
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc) currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
inputs = nodeData.get("inputs", {}) inputs = nodeData.get("inputs", {})
outputs = nodeData.get("outputs", {})
version = nodesVersions.get(nodeType, None) version = nodesVersions.get(nodeType, None)
compatibilityIssue = None compatibilityIssue = None
@ -50,9 +49,5 @@ def test_templateVersions():
if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value): if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value):
compatibilityIssue = CompatibilityIssue.DescriptionConflict compatibilityIssue = CompatibilityIssue.DescriptionConflict
break break
for attrName, value in outputs.items():
if not CompatibilityNode.attributeDescFromName(nodeDesc.outputs, attrName, value):
compatibilityIssue = CompatibilityIssue.DescriptionConflict
break
assert compatibilityIssue is None assert compatibilityIssue is None