playmolecule.plac module#
- class playmolecule.plac.Annotation(help=None, kind='positional', abbrev=None, type=None, choices=None, metavar=None, required=False, nargs=None)#
Bases:
object
- classmethod from_(obj)#
Helper to convert an object into an annotation, if needed
- class playmolecule.plac.ArgumentParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)#
Bases:
ArgumentParser
An ArgumentParser with .func and .argspec attributes, and possibly .commands and .subparsers.
- addsubcommands(commands, obj, title=None, cmdprefix='')#
Extract a list of subcommands from obj and add them to the parser
- alias(arg)#
Can be overridden to preprocess command-line arguments
- case_sensitive = True#
- consume(args)#
Call the underlying function with the args. Works also for command containers, by dispatching to the right subparser.
- missing(name)#
May raise a SystemExit
- populate_from(func)#
Extract the arguments from the attributes of the passed function and return a populated ArgumentParser instance.
- print_actions()#
Useful for debugging
- playmolecule.plac.annotations(**ann)#
Returns a decorator annotating a function with the given annotations. This is a trick to support function annotations in Python 2.X.
- playmolecule.plac.call(obj, arglist=None, eager=True, version=None)#
If obj is a function or a bound method, parse the given arglist by using the parser inferred from the annotations of obj and call obj with the parsed arguments. If obj is an object with attribute .commands, dispatch to the associated subparser.
- playmolecule.plac.flg(arg, help=None, abbrev=None)#
Decorator for annotating flags
- playmolecule.plac.getargspec(callableobj)#
Given a callable return an object with attributes .args, .varargs, .varkw, .defaults. It tries to do the “right thing” with functions, methods, classes and generic callables.
- playmolecule.plac.is_annotation(obj)#
An object is an annotation object if it has the attributes help, kind, abbrev, type, choices, metavar.
- playmolecule.plac.iterable(obj)#
Any object with an __iter__ method which is not a string or class
- playmolecule.plac.opt(arg, help=None, type=None, abbrev=None, choices=None, metavar=None, required=False, nargs=None)#
Decorator for annotating optional arguments
- playmolecule.plac.parser_from(obj, **confparams)#
obj can be a callable or an object with a .commands attribute. Returns an ArgumentParser.
- playmolecule.plac.pconf(obj)#
Extracts the configuration of the underlying ArgumentParser from obj
- playmolecule.plac.to_date(s)#
Returns year-month-day
- playmolecule.plac.to_datetime(s)#
Returns year-month-day hour-minute-second