Skip to content

Commit cf6e719

Browse files
authored
Merge pull request #2933 from alicevision/dev/inputFileNode
[nodes] Add new `InputFile` input node
2 parents 574538e + 06a83f6 commit cf6e719

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
__version__ = "1.0"
2+
3+
import logging
4+
import os
5+
6+
from meshroom.core import desc
7+
8+
class InputFile(desc.InputNode, desc.InitNode):
9+
"""
10+
This node is an input node that receives a File.
11+
"""
12+
category = "Other"
13+
14+
inputs = [
15+
desc.File(
16+
name="inputFile",
17+
label="Input File",
18+
description="A file or folder to use as the input.",
19+
value="",
20+
)
21+
]
22+
23+
def initialize(self, node, inputs, recursiveInputs):
24+
self.resetAttributes(node, ["inputFile"])
25+
26+
if len(inputs) >= 1:
27+
if os.path.isfile(inputs[0]) or os.path.isdir(inputs[0]):
28+
self.setAttributes(node, {"inputFile": inputs[0]})
29+
30+
if len(inputs) > 1:
31+
logging.warning(f"Several inputs were provided ({inputs}).")
32+
logging.warning(f"Only the first one ({inputs[0]}) will be used.")
33+
else:
34+
raise RuntimeError(f"{inputs[0]} is not a valid file or directory.")
35+
36+
elif len(recursiveInputs) >= 1:
37+
if os.path.isfile(recursiveInputs[0]) or os.path.isdir(recursiveInputs[0]):
38+
self.setAttributes(node, {"inputFile": recursiveInputs[0]})
39+
40+
if len(recursiveInputs) > 1:
41+
logging.warning(f"Several recursive inputs were provided ({recursiveInputs}).")
42+
logging.warning(f"Only the first valid one ({recursiveInputs[0]}) will be used.")
43+
44+
else:
45+
raise RuntimeError(f"{recursiveInputs[0]} is not a valid file or directory.")
46+
47+
else:
48+
raise RuntimeError("No file or directory has been set for 'inputFile'.")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
__version__ = "1.0"
2+
3+
from meshroom.core import desc
4+
5+
6+
class PluginAInputInitNode(desc.InputNode, desc.InitNode):
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+
]
24+
25+
def initialize(self, node, inputs, recursiveInputs):
26+
if len(inputs) >= 1:
27+
self.setAttributes(node, {"input": inputs[0]})

tests/plugins/meshroom/pluginA/PluginAInputNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from meshroom.core import desc
44

55

6-
class PluginANodeA(desc.InputNode):
6+
class PluginAInputNode(desc.InputNode):
77
inputs = [
88
desc.File(
99
name="input",

tests/test_nodes.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,38 @@ def test_expVariables(self):
101101
assert n._expVars["uid"] == n._uid
102102
assert n.internalFolder
103103
assert n.internalFolder == n._expVars["nodeCacheFolder"]
104+
105+
106+
class TestInitNode:
107+
plugin = None
108+
109+
@classmethod
110+
def setup_class(cls):
111+
folder = os.path.join(os.path.dirname(__file__), "plugins", "meshroom")
112+
package = "pluginA"
113+
cls.plugin = Plugin(package, folder)
114+
nodes = loadClassesNodes(folder, package)
115+
for node in nodes:
116+
cls.plugin.addNodePlugin(node)
117+
pluginManager.addPlugin(cls.plugin)
118+
119+
@classmethod
120+
def teardown_class(cls):
121+
for node in cls.plugin.nodes.values():
122+
pluginManager.unregisterNode(node)
123+
pluginManager.removePlugin(cls.plugin)
124+
cls.plugin = None
125+
126+
def test_initNode(self):
127+
g = Graph("")
128+
129+
node = g.addNewNode("PluginAInputInitNode")
130+
131+
# Check that the init node is correctly detected
132+
initNodes = g.findInitNodes()
133+
assert len(initNodes) == 1 and node in initNodes
134+
135+
# Check that the init node's initialize method has been set
136+
inputs = ["/path/to/file", "/path/to/file/2"]
137+
node.nodeDesc.initialize(node, inputs, None)
138+
assert node.input.value == inputs[0]

0 commit comments

Comments
 (0)