def __init__(self, line_width=80, tab_size=2, max_subargs_per_line=3, separate_ctrl_name_with_space=False, separate_fn_name_with_space=False, bullet_char='*', enum_char=".", additional_commands=None, **_): self.line_width = line_width self.tab_size = tab_size # TODO(josh): make this conditioned on certain commands / kwargs # because things like execute_process(COMMAND...) are less readable # formatted as a single list. In fact... special case COMMAND to break on # flags the way we do kwargs. self.max_subargs_per_line = max_subargs_per_line self.separate_ctrl_name_with_space = separate_ctrl_name_with_space self.separate_fn_name_with_space = separate_fn_name_with_space self.bullet_char = str(bullet_char)[0] self.enum_char = str(enum_char)[0] self.additional_commands = additional_commands self.fn_spec = commands.get_fn_spec() if additional_commands is not None: for command_name, spec in additional_commands.items(): commands.decl_command(self.fn_spec, command_name, **spec)
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("outfile", nargs="?", default="-") args = parser.parse_args() missing_commands = [] proc = subprocess.Popen(["cmake", "--help-command-list"], stdout=subprocess.PIPE) parse_db = parse_funs.get_parse_db() parse_db.update(parse_funs.get_legacy_parse(commands.get_fn_spec()).kwargs) with proc.stdout as infile: for line in infile: command = line.strip().decode("utf-8") if command not in parse_db and not command.startswith("end"): missing_commands.append(command) proc.wait() outfile_path = args.outfile if outfile_path == "-": outfile_path = os.dup(sys.stdout.fileno()) with io.open(outfile_path, "w", encoding="utf-8") as outfile: for command in missing_commands: outfile.write(TEMPLATE.format(command)) outfile.write("\n\ndef populate_db(parse_db):\n") for command in missing_commands: outfile.write(' parse_db["{0}"] = parse_{0}\n'.format(command))
def parse(tokens, cmdspec=None): """ digest tokens, then layout the digested blocks. """ if cmdspec is None: cmdspec = commands.get_fn_spec() return consume_body(tokens, cmdspec)
def parse(tokens, cmdspec=None): """ digest tokens, then layout the digested blocks. """ if cmdspec is None: cmdspec = commands.get_fn_spec() return consume_body(tokens, cmdspec)
def __init__(self, line_width=80, tab_size=2, max_subargs_per_line=3): self.line_width = line_width self.tab_size = tab_size # TODO(josh): make this conditioned on certain commands / kwargs # because things like execute_process(COMMAND...) are less readable # formatted as a single list. In fact... special case COMMAND to break on # flags the way we do kwargs. self.max_subargs_per_line = max_subargs_per_line self.fn_spec = commands.get_fn_spec()
def test_all_commands_in_db(self): missing_commands = [] proc = subprocess.Popen(["cmake", "--help-command-list"], stdout=subprocess.PIPE) parse_db = parse_funs.get_parse_db() parse_db.update( parse_funs.get_legacy_parse(commands.get_fn_spec()).kwargs) ignore = IGNORE_LIST with proc.stdout as infile: for line in infile: command = line.strip().decode("utf-8") if command not in parse_db and command not in ignore: missing_commands.append(command) proc.wait() message = "Missing commands:\n " + "\n ".join( sorted(missing_commands)) self.assertFalse(bool(missing_commands), msg=message)
def __init__(self, line_width=80, tab_size=2, max_subgroups_hwrap=2, max_pargs_hwrap=6, separate_ctrl_name_with_space=False, separate_fn_name_with_space=False, dangle_parens=False, dangle_align=None, min_prefix_chars=4, max_prefix_chars=10, max_lines_hwrap=2, bullet_char=None, enum_char=None, line_ending=None, command_case=None, keyword_case=None, additional_commands=None, always_wrap=None, enable_sort=True, autosort=False, enable_markup=True, first_comment_is_literal=False, literal_comment_pattern=None, fence_pattern=None, ruler_pattern=None, emit_byteorder_mark=False, hashruler_min_length=10, canonicalize_hashrulers=True, input_encoding=None, output_encoding=None, per_command=None, layout_passes=None, **_): # pylint: disable=W0613 # pylint: disable=too-many-locals self.line_width = line_width self.tab_size = tab_size self.max_subgroups_hwrap = max_subgroups_hwrap self.max_pargs_hwrap = max_pargs_hwrap self.separate_ctrl_name_with_space = separate_ctrl_name_with_space self.separate_fn_name_with_space = separate_fn_name_with_space self.dangle_parens = dangle_parens self.dangle_align = get_default(dangle_align, "prefix") self.min_prefix_chars = min_prefix_chars self.max_prefix_chars = max_prefix_chars self.max_lines_hwrap = max_lines_hwrap self.bullet_char = str(bullet_char)[0] if bullet_char is None: self.bullet_char = '*' self.enum_char = str(enum_char)[0] if enum_char is None: self.enum_char = '.' self.line_ending = get_default(line_ending, "unix") self.command_case = get_default(command_case, "canonical") assert self.command_case in ("lower", "upper", "canonical", "unchanged") self.keyword_case = get_default(keyword_case, "unchanged") assert self.keyword_case in ("lower", "upper", "unchanged") self.additional_commands = get_default(additional_commands, { 'foo': { 'flags': ['BAR', 'BAZ'], 'kwargs': { 'HEADERS': '*', 'SOURCES': '*', 'DEPENDS': '*' } } }) self.always_wrap = get_default(always_wrap, []) self.enable_sort = enable_sort self.autosort = autosort self.enable_markup = enable_markup self.first_comment_is_literal = first_comment_is_literal self.literal_comment_pattern = literal_comment_pattern self.fence_pattern = get_default(fence_pattern, markup.FENCE_PATTERN) self.ruler_pattern = get_default(ruler_pattern, markup.RULER_PATTERN) self.emit_byteorder_mark = emit_byteorder_mark self.hashruler_min_length = hashruler_min_length self.canonicalize_hashrulers = canonicalize_hashrulers self.layout_passes = get_default(layout_passes, {}) self.input_encoding = get_default(input_encoding, "utf-8") self.output_encoding = get_default(output_encoding, "utf-8") self.fn_spec = commands.get_fn_spec() if additional_commands is not None: for command_name, spec in additional_commands.items(): self.fn_spec.add(command_name, **spec) self.per_command = commands.get_default_config() for command, cdict in get_default(per_command, {}).items(): if not isinstance(cdict, dict): logging.warning("Invalid override of type %s for %s", type(cdict), command) continue command = command.lower() if command not in self.per_command: self.per_command[command] = {} self.per_command[command].update(cdict) assert self.line_ending in ("windows", "unix", "auto"), \ r"Line ending must be either 'windows', 'unix', or 'auto'" self.endl = {'windows': '\r\n', 'unix': '\n', 'auto': '\n'}[self.line_ending] # TODO(josh): this does not belong here! We need some global state for # formatting and the only thing we have accessible through the whole format # stack is this config object... so I'm abusing it by adding this field here self.first_token = None
def __init__(self, line_width=80, tab_size=2, max_subargs_per_line=3, separate_ctrl_name_with_space=False, separate_fn_name_with_space=False, dangle_parens=False, bullet_char=None, enum_char=None, line_ending=None, command_case=None, keyword_case=None, additional_commands=None, always_wrap=None, **_): self.line_width = line_width self.tab_size = tab_size # TODO(josh): make this conditioned on certain commands / kwargs # because things like execute_process(COMMAND...) are less readable # formatted as a single list. In fact... special case COMMAND to break on # flags the way we do kwargs. self.max_subargs_per_line = max_subargs_per_line self.separate_ctrl_name_with_space = separate_ctrl_name_with_space self.separate_fn_name_with_space = separate_fn_name_with_space self.dangle_parens = dangle_parens self.bullet_char = str(bullet_char)[0] if bullet_char is None: self.bullet_char = '*' self.enum_char = str(enum_char)[0] if enum_char is None: self.enum_char = '.' self.line_ending = get_default(line_ending, "unix") self.command_case = get_default(command_case, "lower") assert self.command_case in ("lower", "upper", "unchanged") self.keyword_case = get_default(keyword_case, "unchanged") assert self.keyword_case in ("lower", "upper", "unchanged") self.always_wrap = get_default(always_wrap, []) self.additional_commands = get_default( additional_commands, { 'foo': { 'flags': ['BAR', 'BAZ'], 'kwargs': { 'HEADERS': '*', 'SOURCES': '*', 'DEPENDS': '*' } } }) self.fn_spec = commands.get_fn_spec() if additional_commands is not None: for command_name, spec in additional_commands.items(): self.fn_spec.add(command_name, **spec) assert self.line_ending in ("windows", "unix", "auto"), \ r"Line ending must be either 'windows', 'unix', or 'auto'" self.endl = { 'windows': '\r\n', 'unix': '\n', 'auto': '\n' }[self.line_ending]
def __init__(self, line_width=80, tab_size=2, max_subargs_per_line=3, separate_ctrl_name_with_space=False, separate_fn_name_with_space=False, dangle_parens=False, bullet_char=None, enum_char=None, line_ending=None, command_case=None, keyword_case=None, additional_commands=None, always_wrap=None, algorithm_order=None, enable_markup=True, first_comment_is_literal=False, literal_comment_pattern=None, fence_pattern=None, ruler_pattern=None, emit_byteorder_mark=False, per_command=None, **_): self.line_width = line_width self.tab_size = tab_size # TODO(josh): make this conditioned on certain commands / kwargs # because things like execute_process(COMMAND...) are less readable # formatted as a single list. In fact... special case COMMAND to break on # flags the way we do kwargs. self.max_subargs_per_line = max_subargs_per_line self.separate_ctrl_name_with_space = separate_ctrl_name_with_space self.separate_fn_name_with_space = separate_fn_name_with_space self.dangle_parens = dangle_parens self.bullet_char = str(bullet_char)[0] if bullet_char is None: self.bullet_char = '*' self.enum_char = str(enum_char)[0] if enum_char is None: self.enum_char = '.' self.line_ending = get_default(line_ending, "unix") self.command_case = get_default(command_case, "lower") assert self.command_case in ("lower", "upper", "unchanged") self.keyword_case = get_default(keyword_case, "unchanged") assert self.keyword_case in ("lower", "upper", "unchanged") self.additional_commands = get_default(additional_commands, { 'foo': { 'flags': ['BAR', 'BAZ'], 'kwargs': { 'HEADERS': '*', 'SOURCES': '*', 'DEPENDS': '*' } } }) self.always_wrap = get_default(always_wrap, []) self.algorithm_order = get_default(algorithm_order, [0, 1, 2, 3]) self.enable_markup = enable_markup self.first_comment_is_literal = first_comment_is_literal self.literal_comment_pattern = literal_comment_pattern self.fence_pattern = get_default(fence_pattern, markup.FENCE_PATTERN) self.ruler_pattern = get_default(ruler_pattern, markup.RULER_PATTERN) self.emit_byteorder_mark = emit_byteorder_mark self.fn_spec = commands.get_fn_spec() if additional_commands is not None: for command_name, spec in additional_commands.items(): self.fn_spec.add(command_name, **spec) self.per_command = {} for key, value in get_default(per_command, {}).items(): if not isinstance(value, dict): logging.warning("Invalid override of type %s for %s", type(value), key) continue self.per_command[key.lower()] = value assert self.line_ending in ("windows", "unix", "auto"), \ r"Line ending must be either 'windows', 'unix', or 'auto'" self.endl = {'windows': '\r\n', 'unix': '\n', 'auto': '\n'}[self.line_ending] # TODO(josh): this does not belong here! We need some global state for # formatting and the only thing we have accessible through the whole format # stack is this config object... so I'm abusing it by adding this field here self.first_token = None
def __init__(self, line_width=80, tab_size=2, max_subargs_per_line=3, separate_ctrl_name_with_space=False, separate_fn_name_with_space=False, dangle_parens=False, bullet_char=None, enum_char=None, line_ending=None, command_case=None, keyword_case=None, additional_commands=None, always_wrap=None, algorithm_order=None, enable_markup=True, first_comment_is_literal=False, literal_comment_pattern=None, fence_pattern=None, ruler_pattern=None, emit_byteorder_mark=False, per_command=None, **_): self.line_width = line_width self.tab_size = tab_size # TODO(josh): make this conditioned on certain commands / kwargs # because things like execute_process(COMMAND...) are less readable # formatted as a single list. In fact... special case COMMAND to break on # flags the way we do kwargs. self.max_subargs_per_line = max_subargs_per_line self.separate_ctrl_name_with_space = separate_ctrl_name_with_space self.separate_fn_name_with_space = separate_fn_name_with_space self.dangle_parens = dangle_parens self.bullet_char = str(bullet_char)[0] if bullet_char is None: self.bullet_char = '*' self.enum_char = str(enum_char)[0] if enum_char is None: self.enum_char = '.' self.line_ending = get_default(line_ending, "unix") self.command_case = get_default(command_case, "lower") assert self.command_case in ("lower", "upper", "unchanged") self.keyword_case = get_default(keyword_case, "unchanged") assert self.keyword_case in ("lower", "upper", "unchanged") self.additional_commands = get_default( additional_commands, { 'foo': { 'flags': ['BAR', 'BAZ'], 'kwargs': { 'HEADERS': '*', 'SOURCES': '*', 'DEPENDS': '*' } } }) self.always_wrap = get_default(always_wrap, []) self.algorithm_order = get_default(algorithm_order, [0, 1, 2, 3]) self.enable_markup = enable_markup self.first_comment_is_literal = first_comment_is_literal self.literal_comment_pattern = literal_comment_pattern self.fence_pattern = get_default(fence_pattern, markup.FENCE_PATTERN) self.ruler_pattern = get_default(ruler_pattern, markup.RULER_PATTERN) self.emit_byteorder_mark = emit_byteorder_mark self.fn_spec = commands.get_fn_spec() if additional_commands is not None: for command_name, spec in additional_commands.items(): self.fn_spec.add(command_name, **spec) self.per_command = {} for key, value in get_default(per_command, {}).items(): if not isinstance(value, dict): logging.warning("Invalid override of type %s for %s", type(value), key) continue self.per_command[key.lower()] = value assert self.line_ending in ("windows", "unix", "auto"), \ r"Line ending must be either 'windows', 'unix', or 'auto'" self.endl = { 'windows': '\r\n', 'unix': '\n', 'auto': '\n' }[self.line_ending] # TODO(josh): this does not belong here! We need some global state for # formatting and the only thing we have accessible through the whole format # stack is this config object... so I'm abusing it by adding this field here self.first_token = None
def __init__(self, **kwargs): # pylint: disable=W0613 self.fn_spec = commands.get_fn_spec() super(ParseConfig, self).__init__(**kwargs)