Provides several utilities for handling I/O
pip install pyiotoolsPLEASE NOTE:
This library is currently still under development. The API will likely undergo significant changes that may break any code you write with it. The documentation will fall out of sync with the updates regularly until development slows down. Use it at your own risk.
Overview
Provides several utilities for handling I/O:
The IOHandler class
- Api similar to
argparse.ArgumentParser(). Must be used as a context manager, and while in scope theArgument.add()method will act equivalent toArgumentParser.add_argument(). IOHandler.process()(equivalent toArgumentParser.parse_args()) returns asubtypes.Dictholding the argument values if no callback is provided to theIOHandler()constructor, otherwise it passes on the return value of the callback function, which will be passed aDictas its single positional argument.- Has various run-modes (in the provided
RunModeEnum)RunMode.SMARTwill attempt to choose the appropriate run-mode for the situation. - Under
RunMode.COMMANDLINEargparse is used under-the-hood to process thesys.argvarguments, but with additional features and custom-built help interface that is more readable (and way prettier!) - Under
RunMode.GUI, it will programatically build a GUI to collect user input, with widgets picked based on the 'argtype' argument ofArgument(). The argument defaults can be overriden at point-in-time by passing adictof argument name-value pairs directly toIOHandler.process(). Further calls toIOHandler.process()will still have the base defaults - Under
RunMode.PROGRAMMATIC, the argument values can be passed directly toIOHandler.process()as adictof argument name-value pairs IOHandler.add_subhandler()will add a new subhandler which will act as a subcommand underRunMode.COMMANDLINE, and will act as a tabbed sheet underRunMode.GUI. The handlers exist in a hierarchy, meaning that arguments passed to all parents on the way to the lowest child sheet (on the gui) or final used subcommand (in the commandline) are still handled.
The Argument class
-
The
Argument()constructor arguments tell the IOHandler how to handle nullability, default values, implicit coercion to the right type, whether the argument is optional, commandline aliases, conditions, dependencies, etc.