Skip to content

Commit c3e8b88

Browse files
committed
[core] checkTemplateVersions: Ensure nodes are not loaded several times
By performing a `initNodes()` every single time `checkTemplateVersions` was called without ever unregistering the nodes, warnings about nodes being already registered were raised when for example calling `checkAllTemplatesVersions`.
1 parent ee5e940 commit c3e8b88

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

meshroom/core/test.py

+49-40
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,77 @@
11
#!/usr/bin/env python
22
# coding:utf-8
33

4-
from meshroom.core import pipelineTemplates, Version
4+
from meshroom.core import unregisterNodeType, pipelineTemplates, Version
55
from meshroom.core.node import CompatibilityIssue, CompatibilityNode
66
from meshroom.core.graphIO import GraphIO
77

88
import meshroom
99

1010
import json
1111

12-
def checkTemplateVersions(path: str) -> bool:
12+
def checkTemplateVersions(path: str, nodesAlreadyLoaded: bool = False) -> bool:
1313
""" Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
14-
meshroom.core.initNodes()
14+
if not nodesAlreadyLoaded:
15+
meshroom.core.initNodes()
1516

1617
with open(path) as jsonFile:
1718
fileData = json.load(jsonFile)
1819

19-
graphData = fileData.get(GraphIO.Keys.Graph, fileData)
20-
if not isinstance(graphData, dict):
21-
return False
22-
23-
header = fileData.get(GraphIO.Keys.Header, {})
24-
if not header.get("template", False):
25-
return False
26-
nodesVersions = header.get(GraphIO.Keys.NodesVersions, {})
27-
28-
for _, nodeData in graphData.items():
29-
nodeType = nodeData["nodeType"]
30-
if not nodeType in meshroom.core.nodesDesc:
20+
try:
21+
graphData = fileData.get(GraphIO.Keys.Graph, fileData)
22+
if not isinstance(graphData, dict):
3123
return False
3224

33-
nodeDesc = meshroom.core.nodesDesc[nodeType]
34-
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
35-
36-
inputs = nodeData.get("inputs", {})
37-
internalInputs = nodeData.get("internalInputs", {})
38-
version = nodesVersions.get(nodeType, None)
39-
40-
compatibilityIssue = None
41-
42-
if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major:
43-
compatibilityIssue = CompatibilityIssue.VersionConflict
44-
else:
45-
for attrName, value in inputs.items():
46-
if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value):
47-
compatibilityIssue = CompatibilityIssue.DescriptionConflict
48-
break
49-
for attrName, value in internalInputs.items():
50-
if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value):
51-
compatibilityIssue = CompatibilityIssue.DescriptionConflict
52-
break
53-
54-
if compatibilityIssue is not None:
55-
print("{} in {} for node {}".format(compatibilityIssue, path, nodeType))
25+
header = fileData.get(GraphIO.Keys.Header, {})
26+
if not header.get("template", False):
5627
return False
28+
nodesVersions = header.get(GraphIO.Keys.NodesVersions, {})
29+
30+
for _, nodeData in graphData.items():
31+
nodeType = nodeData["nodeType"]
32+
if not nodeType in meshroom.core.nodesDesc:
33+
return False
34+
35+
nodeDesc = meshroom.core.nodesDesc[nodeType]
36+
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
37+
38+
inputs = nodeData.get("inputs", {})
39+
internalInputs = nodeData.get("internalInputs", {})
40+
version = nodesVersions.get(nodeType, None)
5741

58-
return True
42+
compatibilityIssue = None
43+
44+
if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major:
45+
compatibilityIssue = CompatibilityIssue.VersionConflict
46+
else:
47+
for attrName, value in inputs.items():
48+
if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value):
49+
compatibilityIssue = CompatibilityIssue.DescriptionConflict
50+
break
51+
for attrName, value in internalInputs.items():
52+
if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value):
53+
compatibilityIssue = CompatibilityIssue.DescriptionConflict
54+
break
55+
56+
if compatibilityIssue is not None:
57+
print("{} in {} for node {}".format(compatibilityIssue, path, nodeType))
58+
return False
59+
60+
return True
61+
62+
finally:
63+
if not nodesAlreadyLoaded:
64+
nodeTypes = [nodeType for _, nodeType in meshroom.core.nodesDesc.items()]
65+
for nodeType in nodeTypes:
66+
unregisterNodeType(nodeType)
5967

6068

6169
def checkAllTemplatesVersions() -> bool:
70+
meshroom.core.initNodes()
6271
meshroom.core.initPipelines()
6372

6473
validVersions = []
6574
for _, path in pipelineTemplates.items():
66-
validVersions.append(checkTemplateVersions(path))
75+
validVersions.append(checkTemplateVersions(path, nodesAlreadyLoaded=True))
6776

6877
return all(validVersions)

0 commit comments

Comments
 (0)