dep_tools.parsers module

This module contains various parsers for converting data.

These are primarily useful as convenience functions when using the typer module, particularly in combination with argo workflows, which only allows certain parameter types.

Example usage might be something like:

from typing import Annotated
import typer

def main(flag: Annotated[str, typer.Option(parser=bool_parser)] = "True"):
    print(flag.__class__)

if __name__ == "__main__":
    typer.run(main())

Calling this code like:

$ python file.py --flag True

or:

$ python file.py

will produce:

<class 'bool'>

That is, the input string argument has automatically been converted to a bool.

the parameter must have a name and a value.

dep_tools.parsers.datetime_parser(datetime)[source]

Parse a string representing a year or multiple years.

Parameters:

datetime (str) – A string of the format ‘<year>’ or ‘<year x>_<year y>’. If the latter, the years must be in order.

Return type:

list[str]

Returns:

If datetime is a single year, it is returned as a single item list. Otherwise a generator producing integer values in the range [<year x>, <year y> + 1] is returned.

dep_tools.parsers.bool_parser(raw)[source]

Parse a string representing a true or false condition.

Parameters:

raw (str) – Either “False” or something else.

Return type:

bool

Returns:

False if raw is “False”’ and true otherwise.