Skip to content

Add lambda support for CommandLineNode.commandLine#3015

Draft
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-support-for-lambda-commandline
Draft

Add lambda support for CommandLineNode.commandLine#3015
Copilot wants to merge 2 commits intodevelopfrom
copilot/add-support-for-lambda-commandline

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

CommandLineNode.commandLine only supported string templates formatted with .format(**vars). This adds support for it to also be a callable (lambda/function) taking a node argument, evaluated at build time instead.

Description

Users can now define commandLine as a lambda receiving the node, enabling dynamic command line construction based on node state:

class MyNode(desc.CommandLineNode):
    # New: lambda receiving the node
    commandLine = lambda node: f"myapp --input {node.input.value} --output {node.output.value}"

    # Existing: string template (unchanged)
    # commandLine = "myapp --input {inputValue} --output {outputValue}"

Features list

  • CommandLineNode.commandLine accepts a callable (node) -> str in addition to a string template.

Implementation remarks

When a lambda is assigned as a class variable, Python's descriptor protocol wraps it as a bound method on instance access — passing self (the node descriptor) as the first argument, not node. inspect.getattr_static bypasses this, retrieving the raw callable so it can be invoked with just chunk.node.

# meshroom/core/desc/node.py
commandLineValue = getattr_static(self, 'commandLine')
if callable(commandLineValue):
    cmd = commandLineValue(chunk.node)
else:
    cmd = commandLineValue.format(**chunk.node._expVars, **chunk.node._staticExpVars, **cmdLineVars)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: fabiencastan <153585+fabiencastan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for lambda evaluation in commandLine Add lambda support for CommandLineNode.commandLine Feb 24, 2026
Copilot AI requested a review from fabiencastan February 24, 2026 19:17
cmdSuffix = " " + self.commandLineRange.format(**chunk.range.toDict()) + " " + cmdSuffix

return cmdPrefix + chunk.node.nodeDesc.commandLine.format(**chunk.node._expVars, **chunk.node._staticExpVars, **cmdLineVars) + cmdSuffix
commandLineValue = getattr_static(self, 'commandLine')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
commandLineValue = getattr_static(self, 'commandLine')
# In the case of a lambda, we want a single "node" argument and not the node descriptor "self".
# Therefore, we use getattr_static to retrieve the raw lambda instead of a bound method, which
# would impose "self" as the first argument if we accessed "self.commandLine".
commandLineValue = getattr_static(self, 'commandLine')

@fabiencastan fabiencastan added this to the Meshroom 2026.1.0 milestone Feb 27, 2026
@fabiencastan fabiencastan added the feature new feature (proposed as PR or issue planned by dev) label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature new feature (proposed as PR or issue planned by dev)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants