def gen_tasks_options_reference_data(options): """Generate the template data for the options 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) # 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. for authored_task_type in task_type.mro(): if authored_task_type.__module__ != 'abc': break doc_rst = indent_docstring_by_n(authored_task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring(authored_task_type.__doc__)) parser = options.get_parser(task_type.options_scope) oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) 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=oref_template_data_from_help_info(oschi))) 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
def gen_tasks_options_reference_data(options): """Generate the template data for the options 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) # 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. for authored_task_type in task_type.mro(): if authored_task_type.__module__ != 'abc': break doc_rst = indent_docstring_by_n(authored_task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring( authored_task_type.__doc__)) parser = options.get_parser(task_type.options_scope) oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser( parser) 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=oref_template_data_from_help_info(oschi))) 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
def do_test(args, kwargs, expected_default): # Defaults are computed in the parser and added into the kwargs, so we # must jump through this hoop in this test. parser = Parser(env={}, config=Config.load([]), scope_info=GlobalOptionsRegistrar.get_scope_info(), parent_parser=None, option_tracker=OptionTracker()) parser.register(*args, **kwargs) oshi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser).basic self.assertEquals(1, len(oshi)) ohi = oshi[0] self.assertEqual(expected_default, ohi.default)
def fill_template(options, task_type): for authored_task_type in task_type.mro(): if authored_task_type.__module__ != "abc": break doc_rst = indent_docstring_by_n(authored_task_type.__doc__ or "", 2) doc_html = rst_to_html(dedent_docstring(authored_task_type.__doc__)) parser = options.get_parser(task_type.options_scope) oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) impl = "{0}.{1}".format(authored_task_type.__module__, authored_task_type.__name__) return TemplateData( impl=impl, doc_html=doc_html, doc_rst=doc_rst, ogroup=oref_template_data_from_help_info(oschi) )
def fill_template(options, task_type): for authored_task_type in task_type.mro(): if authored_task_type.__module__ != 'abc': break doc_rst = indent_docstring_by_n(authored_task_type.__doc__ or '', 2) doc_html = rst_to_html(dedent_docstring(authored_task_type.__doc__)) parser = options.get_parser(task_type.options_scope) oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) impl = '{0}.{1}'.format(authored_task_type.__module__, authored_task_type.__name__) return TemplateData( impl=impl, doc_html=doc_html, doc_rst=doc_rst, ogroup=oref_template_data_from_help_info(oschi))
def get_from_parser(parser): oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) # We ignore advanced options, as they aren't intended to be used on the cmd line. for ohi in oschi.basic: autocomplete_options_by_scope[oschi.scope].update(ohi.unscoped_cmd_line_args) autocomplete_options_by_scope[oschi.scope].update(ohi.scoped_cmd_line_args) # Autocomplete to this option in the enclosing goal scope, but exclude options registered # on us, but not by us, e.g., recursive options (which are registered by # GlobalOptionsRegisterer). # We exclude those because they are already registered on the goal scope anyway # (via the recursion) and it would be confusing and superfluous to have autocompletion # to both --goal-recursive-opt and --goal-task-recursive-opt in goal scope. if issubclass(ohi.registering_class, TaskBase): goal_scope = oschi.scope.partition(".")[0] autocomplete_options_by_scope[goal_scope].update(ohi.scoped_cmd_line_args)
def get_from_parser(parser): oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) # We ignore advanced options, as they aren't intended to be used on the cmd line. option_help_infos = oschi.basic + oschi.recursive for ohi in option_help_infos: autocomplete_options_by_scope[oschi.scope].update(ohi.unscoped_cmd_line_args) autocomplete_options_by_scope[oschi.scope].update(ohi.scoped_cmd_line_args) # Autocomplete to this option in the enclosing goal scope, but exclude options registered # on us, but not by us, e.g., recursive options (which are registered by # GlobalOptionsRegisterer). # We exclude those because they are already registered on the goal scope anyway # (via the recursion) and it would be confusing and superfluous to have autocompletion # to both --goal-recursive-opt and --goal-task-recursive-opt in goal scope. if issubclass(ohi.registering_class, TaskBase): goal_scope = oschi.scope.partition('.')[0] autocomplete_options_by_scope[goal_scope].update(ohi.scoped_cmd_line_args)
def gen_glopts_reference_data(options): parser = options.get_parser(GLOBAL_SCOPE) oschi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser) return oref_template_data_from_help_info(oschi)