Support for waf command-line options

Provides default and command-line options, as well the command that reads the options wscript function.

waflib.Options.options = <Values at 0x7f903aa62290: {}>

A global dictionary representing user-provided command-line options:

$ waf --foo=bar
waflib.Options.commands = []

List of commands to execute extracted from the command-line. This list is consumed during the execution by waflib.Scripting.run_commands().

waflib.Options.envvars = []

List of environment variable declarations placed after the Waf executable name. These are detected by searching for “=” in the remaining arguments. You probably do not want to use this.

waflib.Options.lockfile = '.lock-waf_linux_build'

Name of the lock file that marks a project as configured

class waflib.Options.opt_parser(ctx, allow_unknown=False)[source]

Command-line options parser.

_process_args(largs, rargs, values)[source]

Custom _process_args to allow unknown options according to the allow_unknown status

print_usage(file: file = stdout)[source]

Print the usage message for the current program (self.usage) to ‘file’ (default stdout). Any occurrence of the string “%prog” in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.


Builds the message to print on waf --help

Return type


class waflib.Options.OptionsContext(**kw)[source]

Collects custom options from wscript files and parses the command line. Sets the global waflib.Options.commands and waflib.Options.options values.

cmd = 'options'
fun = 'options'

Instance of waflib.Options.opt_parser


Finds the optimal amount of cpu cores to use for parallel jobs. At runtime the options can be obtained from waflib.Options.options

from waflib.Options import options
njobs = options.jobs

the amount of cpu cores

Return type


add_option(*k, **kw)[source]

Wraps optparse.add_option:

def options(ctx):
        ctx.add_option('-u', '--use', dest='use', default=False,
                action='store_true', help='a boolean option')
Return type

optparse option object

add_option_group(*k, **kw)[source]

Wraps optparse.add_option_group:

def options(ctx):
        gr = ctx.add_option_group('some options')
        gr.add_option('-u', '--use', dest='use', default=False, action='store_true')
Return type

optparse option group object


Wraps optparse.get_option_group:

def options(ctx):
        gr = ctx.get_option_group('configure options')
        gr.add_option('-o', '--out', action='store', default='',
                help='build dir for the project', dest='out')
Return type

optparse option group object

parse_cmd_args(_args=None, cwd=None, allow_unknown=False)[source]

Just parse the arguments


Parses arguments from a list which is not necessarily the command-line. Initializes the module variables options, commands and envvars If help is requested, prints it and exit the application


_args (list of strings) – arguments


See waflib.Context.Context.execute()