From c3e8b8833f401bf1d6e2e4274cf34f675efe847d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Tue, 18 Mar 2025 14:04:06 +0000 Subject: [PATCH] [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`. --- meshroom/core/test.py | 89 ++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/meshroom/core/test.py b/meshroom/core/test.py index 74cb2f5c..85e7a021 100644 --- a/meshroom/core/test.py +++ b/meshroom/core/test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # 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.graphIO import GraphIO @@ -9,60 +9,69 @@ import meshroom 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". """ - meshroom.core.initNodes() + if not nodesAlreadyLoaded: + meshroom.core.initNodes() with open(path) as jsonFile: fileData = json.load(jsonFile) - graphData = fileData.get(GraphIO.Keys.Graph, fileData) - if not isinstance(graphData, dict): - return False - - header = fileData.get(GraphIO.Keys.Header, {}) - if not header.get("template", False): - return False - nodesVersions = header.get(GraphIO.Keys.NodesVersions, {}) - - for _, nodeData in graphData.items(): - nodeType = nodeData["nodeType"] - if not nodeType in meshroom.core.nodesDesc: + try: + graphData = fileData.get(GraphIO.Keys.Graph, fileData) + if not isinstance(graphData, dict): return False - nodeDesc = meshroom.core.nodesDesc[nodeType] - currentNodeVersion = meshroom.core.nodeVersion(nodeDesc) - - inputs = nodeData.get("inputs", {}) - internalInputs = nodeData.get("internalInputs", {}) - version = nodesVersions.get(nodeType, None) - - compatibilityIssue = None - - if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major: - compatibilityIssue = CompatibilityIssue.VersionConflict - else: - for attrName, value in inputs.items(): - if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value): - compatibilityIssue = CompatibilityIssue.DescriptionConflict - break - for attrName, value in internalInputs.items(): - if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value): - compatibilityIssue = CompatibilityIssue.DescriptionConflict - break - - if compatibilityIssue is not None: - print("{} in {} for node {}".format(compatibilityIssue, path, nodeType)) + header = fileData.get(GraphIO.Keys.Header, {}) + if not header.get("template", False): return False + nodesVersions = header.get(GraphIO.Keys.NodesVersions, {}) - return True + for _, nodeData in graphData.items(): + nodeType = nodeData["nodeType"] + if not nodeType in meshroom.core.nodesDesc: + return False + + nodeDesc = meshroom.core.nodesDesc[nodeType] + currentNodeVersion = meshroom.core.nodeVersion(nodeDesc) + + inputs = nodeData.get("inputs", {}) + internalInputs = nodeData.get("internalInputs", {}) + version = nodesVersions.get(nodeType, None) + + compatibilityIssue = None + + if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major: + compatibilityIssue = CompatibilityIssue.VersionConflict + else: + for attrName, value in inputs.items(): + if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value): + compatibilityIssue = CompatibilityIssue.DescriptionConflict + break + for attrName, value in internalInputs.items(): + if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value): + compatibilityIssue = CompatibilityIssue.DescriptionConflict + break + + if compatibilityIssue is not None: + print("{} in {} for node {}".format(compatibilityIssue, path, nodeType)) + return False + + return True + + finally: + if not nodesAlreadyLoaded: + nodeTypes = [nodeType for _, nodeType in meshroom.core.nodesDesc.items()] + for nodeType in nodeTypes: + unregisterNodeType(nodeType) def checkAllTemplatesVersions() -> bool: + meshroom.core.initNodes() meshroom.core.initPipelines() validVersions = [] for _, path in pipelineTemplates.items(): - validVersions.append(checkTemplateVersions(path)) + validVersions.append(checkTemplateVersions(path, nodesAlreadyLoaded=True)) return all(validVersions)