Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining requires and output_file_template for a field #619

Closed
ghisvail opened this issue Feb 9, 2023 · 5 comments · Fixed by #629
Closed

Combining requires and output_file_template for a field #619

ghisvail opened this issue Feb 9, 2023 · 5 comments · Fixed by #629
Labels
bug Something isn't working

Comments

@ghisvail
Copy link
Collaborator

ghisvail commented Feb 9, 2023

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,

  • Is this something we would want to allow?
  • If not, what's the alternative pattern to achieve the same behavior?

Cheers,
Ghis

EDIT: Fix typo in code snippet

@ghisvail ghisvail added the bug Something isn't working label Feb 9, 2023
@satra
Copy link
Contributor

satra commented Feb 9, 2023

@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
Copy link
Collaborator Author

ghisvail commented Feb 9, 2023 via email

@ghisvail
Copy link
Collaborator Author

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

Indeed 😅, 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
Copy link
Contributor

satra commented Feb 10, 2023

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
Copy link
Collaborator Author

do you have the inclination to send a PR ?

I can have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants