sphuber / aiida-shell

AiiDA plugin that makes running shell commands easy.
MIT License
14 stars 7 forks source link

`ShellJob`: Change the signature of custom parser functions #97

Closed sphuber closed 2 months ago

sphuber commented 2 months ago

Fixes #96

The current required signature for parser functions is:

def parser(self: Parser, dirpath: pathlib.Path) -> dict[str, Data]:

In most use cases, the Parser instance is not really necessary and it is really the dirpath that is the most important. On top of that, it being called self does not really make it very clear what it is. The reason for it being called self was historical since in an early implementation the custom parser function was actually dynamically added as a member method of the parser instance. However, currently it is simply called as a standalone function.

Since the most common use cases would just require the dirpath, it is made possible to define a parser as follows:

def parser(dirpath: pathlib.Path) -> dict[str, Data]:

In cases where the Parser instance is desirable, the code also accepts functions that define that as the second argument:

def parser(dirpath: pathlib.Path, parser: Parser) -> dict[str, Data]:

The argument is also renamed from self to parser to make it more evident as to what it refers to.

sphuber commented 2 months ago

@geigerj2 what about this? https://aiida-shell--97.org.readthedocs.build/en/97/howto.html#custom-output-parsing