Pass curly braces literarily in aiida-shell arguments

@sphuber This may be a question you can answer:

In a launch_shell_job() I would like to pass some arguments which contain curly braces for doing a brace expansion. For example I would like to run:

echo a{d,c,b}e

Converted to aiida-shell:

results, node = launch_shell_job(echo, arguments="a{d,c,b}e")

This of course results in this error:

ValueError: argument placeholder `{d,c,b}` not specified in `nodes`.`

Can I somehow escape these braces to be passed as is?


A workaround for now is this (idea from here):

results, node = launch_shell_job(
    "bash",
    arguments='{args}',
    nodes={
        'args': SinglefileData.from_string('echo a{d,c,b}e')
    }
)

But a more simple solution would be nice! Thanks!

Hi @bilke , very good question. For the argument formatting, I am relying on the string.Formatter class from Python. This is also what is used to format any f-string. It allows escaping curly braces simply by doubling them, e.g.:

In [4]: print(f'{{test}}')
{test}

I thought this would have worked as well in aiida-shell but there is a small bug since for arguments that don’t contain actual placeholders, I return them as is, but I should be calling .format() on those as well, in order to resolve the escaped braces. I fixed this bug locally and now it seems to be working:

In [1]: from aiida_shell import launch_shell_job

In [2]: results, node = launch_shell_job('echo', arguments="a{{d,c,b}}e")

In [3]: print(results['stdout'].get_content())
a{d,c,b}e

I will open a PR soon.

@bilke opened a PR with the fix here: `ShellCalculation`: Resolve escaped curly braces in arguments by sphuber · Pull Request #102 · sphuber/aiida-shell · GitHub
Please give it a go to see if that solves your problem, I think it should.

Awesome, the fix works as expected! Thanks again for your outstanding support!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.