示例#1
0
def gen_tasks_goals_reference_data():
    """Generate the template data for the goals reference rst doc."""
    goal_dict = {}
    goal_names = []
    for goal in Goal.all():
        tasks = []
        for task_name in goal.ordered_task_names():
            task_type = goal.task_type_by_name(task_name)
            doc_rst = indent_docstring_by_n(task_type.__doc__ or '', 2)
            doc_html = rst_to_html(dedent_docstring(task_type.__doc__))
            option_parser = Parser(env={},
                                   config={},
                                   scope='',
                                   parent_parser=None)
            task_type.register_options(option_parser.register)
            argparser = option_parser._help_argparser
            scope = Goal.scope(goal.name, task_name)
            # task_type may actually be a synthetic subclass of the authored class from the source code.
            # We want to display the authored class's name in the docs (but note that we must use the
            # subclass for registering options above)
            for authored_task_type in task_type.mro():
                if authored_task_type.__module__ != 'abc':
                    break
            impl = '{0}.{1}'.format(authored_task_type.__module__,
                                    authored_task_type.__name__)
            tasks.append(
                TemplateData(impl=impl,
                             doc_html=doc_html,
                             doc_rst=doc_rst,
                             ogroup=gref_template_data_from_options(
                                 scope, argparser)))
        goal_dict[goal.name] = TemplateData(goal=goal, tasks=tasks)
        goal_names.append(goal.name)

    goals = [
        goal_dict[name] for name in sorted(goal_names, key=lambda x: x.lower())
    ]
    return goals
示例#2
0
def parser() -> Parser:
    return Parser(
        env={},
        config=Config.load([]),
        scope_info=GlobalOptions.get_scope_info(),
    )