# Licensed under a 3-clause BSD style license - see LICENSE.rstimportabcimportargparseimportsysfromasvimportconfig,utilfrom.importcommon_args# This list is ordered in order of average workflow
[docs]defsetup_arguments(cls,subparsers):""" Method to add the parser and arguments of the command. In most cases, `subparser.add_parser(cmd_name)` should be called to add the command (where `cmd_name` is for example `run` or `continuous`). And then call `add_argument` to the returned parser, to add the command arguments. """
[docs]defrun_from_conf_args(cls,conf,args):""" Call the run method (i.e. `cls.run`) with the right arguments from `conf` and `args`. In most cases this is just something like `clf.run(conf=conf, my_arg_1=args.my_arg_1, my_arg_2=args.my_arg_2, ...)`. """
[docs]defmake_argparser():""" The top-level entry point for the asv script. Most of the real work is handled by the subcommands in the commands subpackage. """defhelp(args):parser.print_help()sys.exit(0)parser=argparse.ArgumentParser("asv",description="Airspeed Velocity: Simple benchmarking tool for Python")common_args.add_global_arguments(parser,suppress_defaults=False)subparsers=parser.add_subparsers(title='subcommands',description='valid subcommands')help_parser=subparsers.add_parser("help",help="Display usage information")help_parser.set_defaults(func=help)commands={x.__name__:xforxinutil.iter_subclasses(Command)}forcommandincommand_order:subparser=commands[str(command)].setup_arguments(subparsers)common_args.add_global_arguments(subparser)delcommands[command]forname,commandinsorted(commands.items()):subparser=command.setup_arguments(subparsers)common_args.add_global_arguments(subparser)returnparser,subparsers