Skip to content

Commit 4ad6b83

Browse files
authored
Merge pull request #2910 from alicevision/fix/nodeSourceCodeFolder
[core] Correctly set `_sourceCodeFolder` in `BaseNode`'s constructor This PR fixes a regression introduced by the refactoring of the command line variables in #2888, where the static nodeSourceCodeFolder is initialized but never set with the correct value once it becomes available. This is fixed by initializing _sourceCodeFolder directly in the BaseNode's constructor if the description is available (if it isn't, the node will be in Unknown Node compatibility error anyway). This both simplifies what was done prior to #2888 (where _sourceCodeFolder was correctly set later than it should have been) and ensures that _staticExpVars["nodeSourceCodeFolder"] is initialized with the correct value as well. Additionally, simple unit tests are added to ensure that static variables are always correctly set. A test InputNode is also added to one of the test plugins to cover all cases.
2 parents c0532e0 + e8ae796 commit 4ad6b83

File tree

4 files changed

+85
-14
lines changed

4 files changed

+85
-14
lines changed

meshroom/core/node.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def name(self):
359359
return f"{self.node.name}({self.index})"
360360
else:
361361
return self.node.name
362-
362+
363363
@property
364364
def logManager(self):
365365
if self._logManager is None:
@@ -520,7 +520,7 @@ def process(self, forceCompute=False, inCurrentEnv=False):
520520
executionStatus = None
521521
self.statThread = stats.StatisticsThread(self)
522522
self.statThread.start()
523-
523+
524524
try:
525525
self.node.nodeDesc.processChunk(self)
526526
# NOTE: this assumes saving the output attributes for each chunk
@@ -672,7 +672,7 @@ def __init__(self, nodeType: str, position: Position = None, parent: BaseObject
672672
self.packageName: str = ""
673673
self.packageVersion: str = ""
674674
self._internalFolder: str = ""
675-
self._sourceCodeFolder: str = ""
675+
self._sourceCodeFolder: str = self.nodeDesc.sourceCodeFolder if self.nodeDesc else ""
676676
self._internalFolderExp = "{cache}/{nodeType}/{uid}"
677677

678678
# temporary unique name for this node
@@ -742,7 +742,7 @@ def getNodeLogLevel(self):
742742
if self.hasInternalAttribute("nodeDefaultLogLevel"):
743743
return self.internalAttribute("nodeDefaultLogLevel").value.strip()
744744
return "info"
745-
745+
746746
def getColor(self):
747747
"""
748748
Returns:
@@ -1831,7 +1831,6 @@ def __init__(self, nodeType, position=None, parent=None, uid=None, **kwargs):
18311831

18321832
self.packageName = self.nodeDesc.packageName
18331833
self.packageVersion = self.nodeDesc.packageVersion
1834-
self._sourceCodeFolder = self.nodeDesc.sourceCodeFolder
18351834

18361835
for attrDesc in self.nodeDesc.inputs:
18371836
self._attributes.add(attributeFactory(attrDesc, kwargs.get(attrDesc.name, None),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__version__ = "1.0"
2+
3+
from meshroom.core import desc
4+
5+
6+
class PluginANodeA(desc.InputNode):
7+
inputs = [
8+
desc.File(
9+
name="input",
10+
label="Input",
11+
description="",
12+
value="",
13+
),
14+
]
15+
16+
outputs = [
17+
desc.File(
18+
name="output",
19+
label="Output",
20+
description="",
21+
value="",
22+
),
23+
]

tests/plugins/meshroom/pluginC/PluginCNodeA.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
class PluginCNodeA(desc.Node):
88
"""PluginCNodeA"""
9-
9+
1010
author = "testAuthor"
11-
11+
1212
inputs = [
1313
desc.File(
1414
name="input",

tests/test_nodes.py

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
from pathlib import Path
66

77
from meshroom.core import pluginManager, loadClassesNodes
8-
from meshroom.core.plugins import Plugin
9-
from meshroom.core import pluginManager
10-
from meshroom.core import pluginManager
118
from meshroom.core.graph import Graph
9+
from meshroom.core.plugins import Plugin
1210

1311
from .utils import registerNodeDesc
1412

@@ -38,17 +36,68 @@ def test_loadedPlugin(self):
3836
assert plugin == self.plugin
3937
node = plugin.nodes["PluginCNodeA"]
4038
nodeType = node.nodeDescriptor
41-
39+
4240
g = Graph("")
4341
registerNodeDesc(nodeType)
4442
node = g.addNewNode(nodeType.__name__)
45-
43+
4644
nodeDocumentation = node.getDocumentation()
4745
assert nodeDocumentation == "PluginCNodeA"
4846
nodeInfos = {item["key"]: item["value"] for item in node.getNodeInfos()}
4947
assert nodeInfos["module"] == "pluginC.PluginCNodeA"
50-
plugin_path = os.path.join(self.folder, "pluginC", "PluginCNodeA.py")
51-
assert nodeInfos["modulePath"] == Path(plugin_path).as_posix() # modulePath seems to follow linux convention
48+
pluginPath = os.path.join(self.folder, "pluginC", "PluginCNodeA.py")
49+
assert nodeInfos["modulePath"] == Path(pluginPath).as_posix() # modulePath seems to follow linux convention
5250
assert nodeInfos["author"] == "testAuthor"
5351
assert nodeInfos["license"] == "no-license"
5452
assert nodeInfos["version"] == "1.0"
53+
54+
55+
class TestNodeVariables:
56+
plugin = None
57+
58+
@classmethod
59+
def setup_class(cls):
60+
folder = os.path.join(os.path.dirname(__file__), "plugins", "meshroom")
61+
package = "pluginA"
62+
cls.plugin = Plugin(package, folder)
63+
nodes = loadClassesNodes(folder, package)
64+
for node in nodes:
65+
cls.plugin.addNodePlugin(node)
66+
pluginManager.addPlugin(cls.plugin)
67+
68+
@classmethod
69+
def teardown_class(cls):
70+
for node in cls.plugin.nodes.values():
71+
pluginManager.unregisterNode(node)
72+
pluginManager.removePlugin(cls.plugin)
73+
cls.plugin = None
74+
75+
def test_staticVariables(self):
76+
g = Graph("")
77+
78+
for nodeName in self.plugin.nodes.keys():
79+
n = g.addNewNode(nodeName)
80+
assert nodeName == n._staticExpVars["nodeType"]
81+
assert n.sourceCodeFolder
82+
assert n.sourceCodeFolder == n._staticExpVars["nodeSourceCodeFolder"]
83+
84+
self.plugin.nodes[nodeName].reload()
85+
86+
assert nodeName == n._staticExpVars["nodeType"]
87+
assert n.sourceCodeFolder
88+
assert n.sourceCodeFolder == n._staticExpVars["nodeSourceCodeFolder"]
89+
90+
def test_expVariables(self):
91+
g = Graph("")
92+
93+
for nodeName in self.plugin.nodes.keys():
94+
n = g.addNewNode(nodeName)
95+
assert n._expVars["uid"] == n._uid
96+
assert n.internalFolder
97+
assert n.internalFolder == n._expVars["nodeCacheFolder"]
98+
99+
self.plugin.nodes[nodeName].reload()
100+
101+
assert n._expVars["uid"] == n._uid
102+
assert n.internalFolder
103+
assert n.internalFolder == n._expVars["nodeCacheFolder"]

0 commit comments

Comments
 (0)