def build_rows(options): result = [] for option in options: names = option["name"] default = option["default"] if default is not None: if isinstance(default, str) and default and default[0] == default[-1] and default[0] == '"': default = default[1:-1] if default == SUPPRESS: default = None choices = option.get("choices") key = names[0].strip("-") if key in CliTable.plugins: choices = list(ComponentBuilder.entry_points_for(CliTable.plugins[key]).keys()) help_text = option["help"] row = TableRow(names, default, choices, help_text) result.append(row) return result
from collections import namedtuple from contextlib import contextmanager from docutils import nodes as n from docutils.parsers.rst.directives import unchanged_required from sphinx.util.docutils import SphinxDirective from sphinxarg.parser import parse_parser from virtualenv.run.plugin.base import ComponentBuilder TableRow = namedtuple("TableRow", ["names", "default", "choices", "help"]) TextAsDefault = namedtuple("TextAsDefault", ["text"]) CUSTOM = { "discovery": ComponentBuilder.entry_points_for("virtualenv.discovery"), "creator": ComponentBuilder.entry_points_for("virtualenv.create"), "seeder": ComponentBuilder.entry_points_for("virtualenv.seed"), "activators": ComponentBuilder.entry_points_for("virtualenv.activate"), } class CliTable(SphinxDirective): name = "table_cli" option_spec = dict(module=unchanged_required, func=unchanged_required) def run(self): module_name, attr_name = self.options["module"], self.options["func"] parser_creator = getattr(__import__(module_name, fromlist=[attr_name]), attr_name) core_result = parse_parser(parser_creator()) core_result["action_groups"] = [i for i in core_result["action_groups"] if i["title"] not in CUSTOM]