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 setUp(self): commands.decl_command(self.config.fn_spec, 'foo', flags=['BAR', 'BAZ'], kwargs={ "HEADERS": '*', "SOURCES": '*', "DEPENDS": '*' })
def test_always_wrap(self): commands.decl_command(self.config.fn_spec, 'always_wrap', always_wrap=True, flags=['BAR', 'BAZ'], kwargs={ "HEADERS": '*', "SOURCES": '*', "DEPENDS": '*' }) self.do_format_test( u"""\ # This short command should be split to multiple lines always_wrap(HEADERS a.h b.h c.h SOURCES a.c b.c c.c) """, u"""\ # This short command should be split to multiple lines always_wrap(HEADERS a.h b.h c.h SOURCES a.c b.c c.c) """)
def get_config(infile_path, configfile_path): """ If configfile_path is not none, then load the configuration. Otherwise search for a config file in the ancestry of the filesystem of infile_path and find a config file to load. """ if configfile_path is None: configfile_path = find_config_file(infile_path) config = formatter.Configuration() if configfile_path: with open(configfile_path, 'r') as config_file: if configfile_path.endswith('.json'): config_dict = json.load(config_file) else: config_dict = yaml.load(config_file) config.merge(config_dict) for command_name, spec in config_dict.get('additional_commands', {}).iteritems(): commands.decl_command(config.fn_spec, command_name, **spec) return config
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, 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.dangle_parens = dangle_parens self.bullet_char = str(bullet_char)[0] if bullet_char is None: self.bullet_char = u'*' self.enum_char = str(enum_char)[0] if enum_char is None: self.enum_char = u'.' self.line_ending = get_default(line_ending, u"unix") self.command_case = get_default(command_case, u"lower") assert self.command_case in (u"lower", u"upper", u"unchanged") 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(): commands.decl_command(self.fn_spec, command_name, **spec) assert self.line_ending in (u"windows", u"unix", u"auto"), \ r"Line ending must be either 'windows', 'unix', or 'auto'" self.endl = { u'windows': u'\r\n', u'unix': u'\n', u'auto': u'\n' }[self.line_ending]