[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`.
This commit is contained in:
Candice Bentéjac 2025-03-18 14:04:06 +00:00
parent ee5e9401ce
commit c3e8b8833f

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding:utf-8 # coding:utf-8
from meshroom.core import pipelineTemplates, Version from meshroom.core import unregisterNodeType, pipelineTemplates, Version
from meshroom.core.node import CompatibilityIssue, CompatibilityNode from meshroom.core.node import CompatibilityIssue, CompatibilityNode
from meshroom.core.graphIO import GraphIO from meshroom.core.graphIO import GraphIO
@ -9,13 +9,15 @@ import meshroom
import json import json
def checkTemplateVersions(path: str) -> bool: def checkTemplateVersions(path: str, nodesAlreadyLoaded: bool = False) -> bool:
""" Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """ """ Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
if not nodesAlreadyLoaded:
meshroom.core.initNodes() meshroom.core.initNodes()
with open(path) as jsonFile: with open(path) as jsonFile:
fileData = json.load(jsonFile) fileData = json.load(jsonFile)
try:
graphData = fileData.get(GraphIO.Keys.Graph, fileData) graphData = fileData.get(GraphIO.Keys.Graph, fileData)
if not isinstance(graphData, dict): if not isinstance(graphData, dict):
return False return False
@ -57,12 +59,19 @@ def checkTemplateVersions(path: str) -> bool:
return True return True
finally:
if not nodesAlreadyLoaded:
nodeTypes = [nodeType for _, nodeType in meshroom.core.nodesDesc.items()]
for nodeType in nodeTypes:
unregisterNodeType(nodeType)
def checkAllTemplatesVersions() -> bool: def checkAllTemplatesVersions() -> bool:
meshroom.core.initNodes()
meshroom.core.initPipelines() meshroom.core.initPipelines()
validVersions = [] validVersions = []
for _, path in pipelineTemplates.items(): for _, path in pipelineTemplates.items():
validVersions.append(checkTemplateVersions(path)) validVersions.append(checkTemplateVersions(path, nodesAlreadyLoaded=True))
return all(validVersions) return all(validVersions)