Example #1
0
def root_task_parser():
    """
    Returns a new *ArgumentParser* instance that only contains paremeter actions of the root task.
    The returned instance is cached.
    """
    global _root_task_parser

    if _root_task_parser:
        return _root_task_parser

    luigi_parser = luigi.cmdline_parser.CmdlineParser.get_instance()
    if not luigi_parser:
        return None

    root_task = luigi_parser.known_args.root_task

    # get all root task parameter destinations
    root_dests = []
    for task_name, _, param_name, _ in luigi.task_register.Register.get_all_params():
        if task_name == root_task:
            root_dests.append(param_name)

    # create a new parser and add all root actions
    _root_task_parser = ArgumentParser(add_help=False)
    for action in list(full_parser()._actions):
        if not action.option_strings or action.dest in root_dests:
            _root_task_parser._add_action(action)

    logger.debug("build luigi argument parser for root task {}".format(root_task))

    return _root_task_parser
Example #2
0
def _print_basic_help(option_parser, usage, include_deprecated=False):
    """Print all help for the parser. Unlike similar functions, this needs a
    parser so that it can include custom options added by a
    :py:class:`~mrjob.job.MRJob`.
    """
    help_parser = ArgumentParser(usage=usage, add_help=False)

    for action in option_parser._actions:
        if action.dest in _RUNNER_OPTS:
            continue

        if action.dest in _STEP_OPTS:
            continue

        if (action.dest in _DEPRECATED_NON_RUNNER_OPTS and
                not include_deprecated):
            continue

        if not action.option_strings:
            continue

        help_parser._add_action(action)

    help_parser.print_help()

    print()
    print('To see help for a specific runner, use --help -r <runner name>')
    print()
    print('To see help for options that control what part of a job runs,'
          ' use --help --steps')
    print()
    if not include_deprecated:
        print('To include help for deprecated options, add --deprecated')
        print()
Example #3
0
def _print_basic_help(option_parser, usage, include_deprecated=False):
    """Print all help for the parser. Unlike similar functions, this needs a
    parser so that it can include custom options added by a
    :py:class:`~mrjob.job.MRJob`.
    """
    help_parser = ArgumentParser(usage=usage, add_help=False)

    for action in option_parser._actions:
        if action.dest in _RUNNER_OPTS:
            continue

        if action.dest in _STEP_OPTS:
            continue

        if (action.dest in _DEPRECATED_NON_RUNNER_OPTS
                and not include_deprecated):
            continue

        if not action.option_strings:
            continue

        help_parser._add_action(action)

    help_parser.print_help()

    print()
    print('To see help for a specific runner, use --help -r <runner name>')
    print()
    print('To see help for options that control what part of a job runs,'
          ' use --help --steps')
    print()
    if not include_deprecated:
        print('To include help for deprecated options, add --deprecated')
        print()
Example #4
0
def _print_basic_help(option_parser, usage, include_deprecated=False):
    """Print all help for the parser. Unlike similar functions, this needs a
    parser so that it can include custom options added by a
    :py:class:`~mrjob.job.MRJob`.
    """
    help_parser = ArgumentParser(usage=usage, add_help=False)

    _add_basic_args(help_parser)
    _add_job_args(help_parser, include_deprecated=include_deprecated)

    basic_dests = {action.dest for action in help_parser._actions}

    # add other custom args added by the user
    for action in option_parser._actions:
        # option_parser already includes deprecated option dests

        # this excludes deprecated switch aliases (e.g. --no-output)
        if action.dest in basic_dests:
            continue

        # this excludes the --deprecated switch (which is explained below)
        if action.dest in _DEPRECATED_NON_RUNNER_OPTS:
            continue

        # this excludes options that are shown with --help -r <runner>
        if action.dest in _RUNNER_OPTS:
            continue

        # this excludes options that are show with --help --steps
        if action.dest in _STEP_OPTS:
            continue

        # this excludes the ARGS option, which is already covered by usage
        if not action.option_strings:
            continue

        # found a custom option. thanks, library user!
        help_parser._add_action(action)

    help_parser.print_help()

    print()
    print('To see help for a specific runner, use --help -r <runner name>')
    print()
    print('To see help for options that control what part of a job runs,'
          ' use --help --steps')
    print()
    if not include_deprecated:
        print('To include help for deprecated options, add --deprecated')
        print()