qibuild.cmdparse – Parsing command line

For instance, after

$ qibuild make --release foo
  • look for a module named make.py
  • configure a parser using the configure_parser() of the make.py module
  • parse the arguments
  • call the do() method of make.py with
    • arg.release = True
    • arg.projects = [“foo”]

The main function are:

Functions defined in this module

qibuild.cmdparse.run_action(module_name, args=None, forward_args=None)

Run an action using its module path and a list of arguments

If forward_args is given, it must be an argparse.Namespace object. This namespace will be merged with args before being passed to the do() method of module_name.

Example of use

# Configure, build, and run tests on the "foo" project:

def do(args):
    # Forward the --release example to every action:
    qibuild.run_action("qibuild.actions.configure",
      ["foo"], forward_args=args)
    qibuild.run_action("qibuild.actions.make",
      ["foo"], forward_args=args)
    qibuild.run_action("qibuild.actions.test",
      ["foo"], forward_args=args)
qibuild.cmdparse.root_command_main(name, parser, modules, args=None, return_if_no_action=False)

name : name of the main program parser : an instance of ArgumentParser class modules : list of Python modules

qibuild.cmdparse.action_modules_from_package(package_name)

Returns a suitable list of modules from a package.

Example: assuming you have: actions/foo/__init__.py actions/foo/spam.py actions/foo/eggs.py

then action_modules_from_package(“actions.foo”) returns: [actions.foo.spam, actions.foo.eggs]

Example of usage:

parser = argparse.ArgumentParser()
modules = qibuild.cmdparse.action_modules_from_package("qibuild.actions")
qibuild.cmdparse.root_command_main("qibuild", parser, modules)

See also