We use the typedargs package extensively to automatically build shell tools around python packages that let you call individual python functions from the cli with typed bindings between strings and the python function parameters that are automatically inferred from the functions themselves.
So, you can write:
@docannotate
def do_thing(action, flag=False):
"""Do a cool thing.
Args:
action (str): The name of the action to do
flag (bool): An optional flag to control the action.
"""
You could then expose this function inside a console entry_point script and call it as:
script-name do_thing my_action -f true
and it would invoke your function, passing the string my_action as the first parameter and a bool value of True as the second optional parameter.
This generally works and is the basis for many arch tools, such as the iotile tool included as part of CoreTools.
However, it was initially intended to support Python 2 and 3 so we had to rely on a lot of custom ways to communicate the type information we needed. Now that we have dropped python 2 support, we should leverage the fact that we are python 3 only to take advantage of things we can now rely on like function annotations to simplify how we declare annotated functions.
We use the
typedargs
package extensively to automatically build shell tools around python packages that let you call individual python functions from the cli with typed bindings between strings and the python function parameters that are automatically inferred from the functions themselves.So, you can write:
You could then expose this function inside a console
entry_point
script and call it as:and it would invoke your function, passing the string
my_action
as the first parameter and abool
value ofTrue
as the second optional parameter.This generally works and is the basis for many arch tools, such as the
iotile
tool included as part of CoreTools.However, it was initially intended to support Python 2 and 3 so we had to rely on a lot of custom ways to communicate the type information we needed. Now that we have dropped python 2 support, we should leverage the fact that we are python 3 only to take advantage of things we can now rely on like function annotations to simplify how we declare annotated functions.