nipype / pydra

Pydra Dataflow Engine
https://nipype.github.io/pydra/
Other
119 stars 57 forks source link

Combining `requires` and `output_file_template` for a field #619

Closed ghisvail closed 1 year ago

ghisvail commented 1 year ago

I am trying to combine the effects of requires and output_file_template but failed so far.

Here is my latest attempt:

@attrs.define(kw_only=True)
class MyShellSpec(pydra.specs.ShellSpec):
    mandatory_arg: str = attrs.field(
        metadata={"help_string": "mandatory arg", "mandatory": True}
    )

    enable_bar: bool  = attrs.field(
        metadata={"help_string": "optional support for bar", "argstr": "-a"}
    )

    output_arg: str = attrs.field(
        metadata={
            "help_string": "output arg",
            "argstr": "-o",
            "output_file_template": "{mandatory_arg}_foo",
        }
    )

    maybe_output_arg: str = attrs.field(
        metadata={
            "help_string": "output arg if optional arg provided",
            "argstr": "-m",
            "output_file_template": "{mandatory_arg}_bar",
            "requires": {"enable_bar"},
        }
    )  

where I would want maybe_output_arg to get a templated default value only if an optional argument is provided. The reasoning behind it is that the underlying executable generates additional files based on whether some optional parameters have been provided.

Assuming this is not feasible,

Cheers, Ghis

EDIT: Fix typo in code snippet

satra commented 1 year ago

@ghisvail - i don't see optional_arg anywhere. perhaps there should at least be something that checks that variables in requires are present in the spec.

ghisvail commented 1 year ago

My bad, optional -> enable_bar

Le jeu. 9 févr. 2023, 20:48, Satrajit Ghosh @.***> a écrit :

@ghisvail https://github.com/ghisvail - i don't see optional_arg anywhere. perhaps there should at least be something that checks that variables in requires are present in the spec.

— Reply to this email directly, view it on GitHub https://github.com/nipype/pydra/issues/619#issuecomment-1424723822, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO7U32TDBYWC6OZM32WAULWWVCYLANCNFSM6AAAAAAUW37VVE . You are receiving this because you were mentioned.Message ID: @.***>

ghisvail commented 1 year ago

perhaps there should at least be something that checks that variables in requires are present in the spec.

Indeed :sweat_smile:, this mistake was not intended but you're right requires should only reference a field present in the spec.

I fixed the code snippet.

satra commented 1 year ago

i would say this is likely a order of operations resolution problem in the spec processor. do you have the inclination to send a PR ?

ghisvail commented 1 year ago

do you have the inclination to send a PR ?

I can have a look