CommandOutputParameter - mathematical evaluation and assignment

I have some output parameter of type int which I’d like to provide to downstream steps, how can I perform numerical evaluation for output parameter. Currently, my evaluation result in string rather than actual integer maths.

def main(cwlFile):
    clt = cwl.CommandLineTool(
        successCodes=[0],
        arguments=["--background", "--python", "$(inputs.blenderScript.path)",
                   "--", "--input", "$(inputs.inputAlembicMesh)",
                   "--output", "$(inputs.alembicCamera)",
                   "--start", "$(inputs.start)",
                   "--frames", "$(inputs.frames)"],
        requirements=[cwl.InlineJavascriptRequirement()],
        baseCommand="blender",
        inputs=[
            cwl.CommandInputParameter("File", id="blenderScript"),
            cwl.CommandInputParameter("string", id="inputAlembicMesh"),
            cwl.CommandInputParameter("string", id="alembicCamera"),
            cwl.CommandInputParameter("int", id="start"),
            cwl.CommandInputParameter("int", id="frames"),
        ],
        outputs=[
            cwl.CommandOutputParameter("string", id="outputAlembicCamera", outputBinding={
                                       "outputEval": "$(inputs.alembicCamera)"}),
            cwl.CommandOutputParameter("int", id="renderStart", outputBinding={
                                       "outputEval": "$(inputs.start)"}),
            cwl.CommandOutputParameter("int", id="renderEnd", outputBinding={
                                       "outputEval": "$(inputs.frames) - 1"}),
            cwl.CommandOutputParameter("int", id="renderStep", outputBinding={
                                       "outputEval": "1"})
        ]
    )

    dict_representation = clt.save()
    dict_representation['cwlVersion'] = 'v1.0'
    yaml = YAML()
    with open(cwlFile, 'w') as outfile:
        yaml.dump(dict_representation, outfile)

Answering my own question, the following seems to be working so I will go with this

i.e. using the JavaScript parseInt() function

        outputs=[
            cwl.CommandOutputParameter("string", id="outputAlembicCamera", outputBinding={
                                       "outputEval": "$(inputs.alembicCamera)"}),
            cwl.CommandOutputParameter("int", id="renderStart", outputBinding={
                                       "outputEval": "$(inputs.start)"}),
            cwl.CommandOutputParameter("int", id="renderEnd", outputBinding={
                                       "outputEval": "$(parseInt(inputs.frames) - 1)"}),
            cwl.CommandOutputParameter("int", id="renderStep", outputBinding={
                                       "outputEval": "$(parseInt(\"1\"))"})
        ]
2 Likes

I think this would work too, just don’t quote the value of 1:

            cwl.CommandOutputParameter("int", id="renderStep", outputBinding={
                                       "outputEval": 1})
1 Like