Use pydantic field to automate argument building and parsing.#162
Use pydantic field to automate argument building and parsing.#162YooSunYoung merged 20 commits intomainfrom
Conversation
…sting configuration.
| return getattr(args, field_name) | ||
|
|
||
|
|
||
| class CommandArgument(BaseModel): |
There was a problem hiding this comment.
Not sure why this needs to be used as a base model. Can't the same be done with a free function such that models do not need to inherit? That would be much cleaner, as you would avoid forcing workflows to know about argument parsing.
There was a problem hiding this comment.
[WIP] Fixed it!
Sure.
I thought it would be eaiser this way if we want to be explitic about turning them into command line argument or not.
We can take care of that case in the free function too I guess?
There was a problem hiding this comment.
From my point of views the pydantic models defining the parameters might be useful for multiple purposes, e.g., to create widgets. It would thus be a more versatile design if it would work without inheritance.
| output_file=args.output_file, | ||
| compression=Compression[args.compression], | ||
| ) | ||
| class TOAUnit(Enum): |
There was a problem hiding this comment.
Consider StrEnum, since we now have Python 3.11
| min_toa: int = Field( | ||
| title="Minimum Time of Arrival", | ||
| description="Minimum time of arrival (TOA) in [toa_unit].", | ||
| default=0, | ||
| ) | ||
| max_toa: int = Field( | ||
| title="Maximum Time of Arrival", | ||
| description="Maximum time of arrival (TOA) in [toa_unit].", | ||
| default=int((1 / 14) * 1_000), | ||
| ) | ||
| toa_unit: TOAUnit = Field( | ||
| title="Maximum Time of Arrival", |
There was a problem hiding this comment.
A bunch of titles are off here.
There was a problem hiding this comment.
Fixed it! But which titles you mean? It was only toa_unit...
| # Supported annotation for command arguments: | ||
| # - Atomic types: int, float, str, bool, enum.StrEnum, Literal | ||
| # - Optional[AtomicType] | ||
| # - List[AtomicType], Tuple[AtomicType, ...], Set[AtomicType] |
There was a problem hiding this comment.
Maybe this belong into the docstring of add_args_from_pydantic_model?
There was a problem hiding this comment.
I added docstring to the helper functions including these lines.
Continued from #160