mmcdermott / multisource_args

A simple utility for maintaining arguments that can be used across multiple interfaces (predominately CLI and Jupyter Notebooks)
MIT License
0 stars 0 forks source link

Duplication in spec #1

Open mmcdermott opened 4 years ago

mmcdermott commented 4 years ago

Currently, the user has to pass the arg spec twice, once in the dataclass definition, and another time in the argparse spec. This should be avoided - the spec should be defined only once, then argparse spec should be built automatically. This would also open up extensibility to other argparse system (e.g., abseil, click, --docopt). Additionally, this means that args set via class instantiation directly (e.g., in a Jupyter Notebook) lack validation. Validation should be decentralized from the argparse utility and instead done via the main class (or both).

mmcdermott commented 4 years ago

This can be solved using dataclasses.make_dataclass (ctrl+f make_dataclass)

This takes a class name, list of fields, and some other arguments, and returns a dataclass object.

Relatedly, the post init processing options allow for bubbling validation up to the top level base class.

mmcdermott commented 3 years ago

There is now a default argparse inference function based just on the dataclass spec. The interface is clunky, though, in particular for help messages and the output dir arg name. Some further unification (e.g., a config file that defines the spec, and is then read into a class programmatically) would be best, as it would decouple this from the dataclass metadata information (even if that was how everything was ultimately stored).