Skip to content

Commit 6bbc93b

Browse files
fabiencastancbentejac
authored andcommitted
[core] node: rename cmdVars into expVars
Make a clear difference between the variables needed for expressions and the ones needed for the command line nodes.
1 parent c65611f commit 6bbc93b

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

meshroom/core/attribute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def _getEvalValue(self):
131131
env = self.node.nodePlugin.configFullEnv if self.node.nodePlugin else os.environ
132132
substituted = Template(self.value).safe_substitute(env)
133133
try:
134-
varResolved = substituted.format(**self.node._cmdVars, **self.node._staticCmdVars)
134+
varResolved = substituted.format(**self.node._expVars, **self.node._staticExpVars)
135135
return varResolved
136136
except (KeyError, IndexError):
137137
# Catch KeyErrors and IndexErros to be able to open files created prior to the
138-
# support of relative variables (when self.node._cmdVars was not used to evaluate
138+
# support of relative variables (when self.node._expVars was not used to evaluate
139139
# expressions in the attribute)
140140
return substituted
141141
return self.value

meshroom/core/desc/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def buildCommandLine(self, chunk) -> str:
306306
if chunk.node.isParallelized and chunk.node.size > 1:
307307
cmdSuffix = " " + self.commandLineRange.format(**chunk.range.toDict()) + " " + cmdSuffix
308308

309-
return cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._cmdVars, **chunk.node._staticCmdVars, **cmdLineVars) + cmdSuffix
309+
return cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._expVars, **chunk.node._staticExpVars, **cmdLineVars) + cmdSuffix
310310

311311
def processChunk(self, chunk):
312312
cmd = self.buildCommandLine(chunk)

meshroom/core/node.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def __init__(self, nodeType: str, position: Position = None, parent: BaseObject
681681
self.dirty: bool = True # whether this node's outputs must be re-evaluated on next Graph update
682682
self._chunks = ListModel(parent=self)
683683
self._uid: str = uid
684-
self._cmdVars: dict = {}
684+
self._expVars: dict = {}
685685
self._size: int = 0
686686
self._logManager: Optional[LogManager] = None
687687
self._position: Position = position or Position()
@@ -695,7 +695,7 @@ def __init__(self, nodeType: str, position: Position = None, parent: BaseObject
695695

696696
self.globalStatusChanged.connect(self.updateDuplicatesStatusAndLocked)
697697

698-
self._staticCmdVars = {
698+
self._staticExpVars = {
699699
"nodeType": self.nodeType,
700700
"nodeSourceCodeFolder": self.sourceCodeFolder
701701
}
@@ -965,24 +965,24 @@ def _computeInternalFolder(self, cacheDir):
965965
nodeType=self.nodeType,
966966
uid=self._uid)
967967

968-
def _buildCmdVars(self):
968+
def _buildExpVars(self):
969969
"""
970970
Generate command variables using input attributes and resolved output attributes
971971
names and values.
972972
"""
973-
def _buildAttributeCmdVars(cmdVars, name, attr):
973+
def _buildAttributeExpVars(expVars, name, attr):
974974
if attr.enabled:
975975
# xxValue is exposed without quotes to allow to compose expressions
976-
cmdVars[name + "Value"] = attr.getValueStr(withQuotes=False)
976+
expVars[name + "Value"] = attr.getValueStr(withQuotes=False)
977977

978978
if isinstance(attr, GroupAttribute):
979979
assert isinstance(attr.value, DictModel)
980980
# If the GroupAttribute is not set in a single command line argument,
981981
# the sub-attributes may need to be exposed individually
982982
for v in attr._value:
983-
_buildAttributeCmdVars(cmdVars, v.name, v)
983+
_buildAttributeExpVars(expVars, v.name, v)
984984

985-
self._cmdVars = {
985+
self._expVars = {
986986
"uid": self._uid,
987987
"nodeCacheFolder": self._internalFolder,
988988
}
@@ -991,16 +991,16 @@ def _buildAttributeCmdVars(cmdVars, name, attr):
991991
for name, attr in self._attributes.objects.items():
992992
if attr.isOutput:
993993
continue # skip outputs
994-
_buildAttributeCmdVars(self._cmdVars, name, attr)
994+
_buildAttributeExpVars(self._expVars, name, attr)
995995

996996
# For updating output attributes invalidation values
997-
cmdVarsNoCache = self._cmdVars.copy()
998-
cmdVarsNoCache["cache"] = ""
997+
expVarsNoCache = self._expVars.copy()
998+
expVarsNoCache["cache"] = ""
999999

10001000
# Use "self._internalFolder" instead of "self.internalFolder" because we do not want it to
10011001
# be resolved with the {cache} information ("self.internalFolder" resolves
10021002
# "self._internalFolder")
1003-
cmdVarsNoCache["nodeCacheFolder"] = self._internalFolderExp.format(**cmdVarsNoCache, **self._staticCmdVars)
1003+
expVarsNoCache["nodeCacheFolder"] = self._internalFolderExp.format(**expVarsNoCache, **self._staticExpVars)
10041004

10051005
# Evaluate output params
10061006
for name, attr in self._attributes.objects.items():
@@ -1022,8 +1022,8 @@ def _buildAttributeCmdVars(cmdVars, name, attr):
10221022
format(nodeName=self.name, attrName=attr.name))
10231023
if defaultValue is not None:
10241024
try:
1025-
attr.value = defaultValue.format(**self._cmdVars)
1026-
attr._invalidationValue = defaultValue.format(**cmdVarsNoCache)
1025+
attr.value = defaultValue.format(**self._expVars)
1026+
attr._invalidationValue = defaultValue.format(**expVarsNoCache)
10271027
except KeyError as e:
10281028
logging.warning('Invalid expression with missing key on "{nodeName}.{attrName}" with '
10291029
'value "{defaultValue}".\nError: {err}'.
@@ -1036,7 +1036,7 @@ def _buildAttributeCmdVars(cmdVars, name, attr):
10361036
err=str(e)))
10371037

10381038
# xxValue is exposed without quotes to allow to compose expressions
1039-
self._cmdVars[name + 'Value'] = attr.getValueStr(withQuotes=False)
1039+
self._expVars[name + 'Value'] = attr.getValueStr(withQuotes=False)
10401040

10411041

10421042
def createCmdLineVars(self):
@@ -1332,7 +1332,7 @@ def updateInternals(self, cacheDir=None):
13321332
# Update command variables / output attributes
13331333
self._computeUid()
13341334
self._computeInternalFolder(cacheDir)
1335-
self._buildCmdVars()
1335+
self._buildExpVars()
13361336
if self.nodeDesc:
13371337
self.nodeDesc.postUpdate(self)
13381338
# Notify internal folder change if needed

tests/test_nodeCommandLineFormatting.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,52 +138,52 @@ def test_formatting_listOfFiles(self):
138138

139139
# Values are not retrieved as strings in the command line, so quotes around them are
140140
# not expected
141-
assert node._cmdVars["imagesValue"] == \
141+
assert node._expVars["imagesValue"] == \
142142
'single value with space {} {}'.format(inputImages[0],
143143
inputImages[1])
144144

145145
def test_formatting_strings(self):
146146
graph = Graph("")
147147
node = graph.addNewNode("NodeWithAttributesNeedingFormatting")
148-
node._buildCmdVars()
148+
node._buildExpVars()
149149

150150
# Assert an empty File attribute generates empty quotes when requesting its value as
151151
# a string
152152
assert node.input.getValueStr() == '""'
153-
assert node._cmdVars["inputValue"] == ""
153+
assert node._expVars["inputValue"] == ""
154154

155155
# Assert a Choice attribute with a non-empty default value is surrounded with quotes
156156
# when requested as a string
157157
assert node.method.getValueStr() == '"MethodC"'
158-
assert node._cmdVars["methodValue"] == "MethodC"
158+
assert node._expVars["methodValue"] == "MethodC"
159159

160160
# Assert that the empty list is really empty (no quotes)
161161
assert node.images.getValueStr() == ""
162-
assert node._cmdVars["imagesValue"] == "", "Empty list should become fully empty"
162+
assert node._expVars["imagesValue"] == "", "Empty list should become fully empty"
163163

164164
# Assert that the list with one empty value generates empty quotes
165165
node.images.extend("")
166166
assert node.images.getValueStr() == '""', \
167167
"A list with one empty string should generate empty quotes"
168-
assert node._cmdVars["imagesValue"] == "", \
168+
assert node._expVars["imagesValue"] == "", \
169169
"The value is always only the value, so empty here"
170170

171171
# Assert that a list with 2 empty strings generates quotes
172172
node.images.extend("")
173173
assert node.images.getValueStr() == '"" ""', \
174174
"A list with 2 empty strings should generate quotes"
175-
assert node._cmdVars["imagesValue"] == ' ', \
175+
assert node._expVars["imagesValue"] == ' ', \
176176
"The value is always only the value, so 2 empty strings with the " \
177177
"space separator in the middle"
178178

179179
def test_formatting_groups(self):
180180
graph = Graph("")
181181
node = graph.addNewNode("NodeWithAttributesNeedingFormatting")
182-
node._buildCmdVars()
182+
node._buildExpVars()
183183

184184
assert node.firstGroup.getValueStr() == '"False:3"'
185-
assert node._cmdVars["firstGroupValue"] == 'False:3', \
185+
assert node._expVars["firstGroupValue"] == 'False:3', \
186186
"There should be no quotes here as the value is not formatted as a string"
187187

188188
assert node.secondGroup.getValueStr() == '"False,second_value,3.0"'
189-
assert node._cmdVars["secondGroupValue"] == 'False,second_value,3.0'
189+
assert node._expVars["secondGroupValue"] == 'False,second_value,3.0'

0 commit comments

Comments
 (0)