def usage(): """Update the usage.rst from the application's --help output""" # noinspection PyBroadException try: console_scripts = _console_scripts() # noinspection PyArgumentEqualDefault with LocalShell(verbose=False) as local: with open(Project.usage_file, "w") as usage_file: usage_file.write("\n\n") usage_file.write("Usage\n") usage_file.write("=====\n\n") if Project.usage_autoprogram: parser = "{pkg}.{pkg}_settings:{name}Settings().parse()[0]\n".format( pkg=Project.package, name=Project.name ) usage_file.write(".. autoprogram:: {parser}".format(parser=parser)) usage_file.write(" :prog: {name}\n\n".format(name=Project.package)) usage_file.write("::\n\n") for script in console_scripts: text = local.run("python -m %s --help" % script) if text: usage_file.write(" ➤ {app} --help\n".format(app=script)) usage_file.write(indent(text, indent_spaces=4)) usage_file.write("\n\n") except: pass
def test_indent(): """ From indent.__doc__:: Indent each line in the given string using indent_str if given or the number of spaces in indent_spaces. If neither indent_str nor indent_spaces have non-default values, then the original string is returned unchanged. If both are given then then indent is: ' ' * indent_spaces + indent_str """ base_str = dedent("""\ This is a test. It has multiple lines. With no initial indentations. """) one_space = 1 * ' ' two_spaces = 2 * ' ' three_spaces = 3 * ' ' one_plus = 1 * '+' two_plus = 2 * '+' three_plus = 3 * '+' # no indent assert not __lines_with_indent(base_str, one_space) # indent_str == ' ' # all lines have one space indent assert not __lines_without_indent(indent(base_str, indent_str=one_space), one_space) # no lines have more than one space indent assert not __lines_with_indent(indent(base_str, indent_str=one_space), two_spaces) # indent_str == ' ' # all lines have two spaces indent assert not __lines_without_indent(indent(base_str, indent_str=two_spaces), two_spaces) # no lines have more than two spaces indent assert not __lines_with_indent(indent(base_str, indent_str=two_spaces), three_spaces) # indent_spaces == 1 # one space assert not __lines_without_indent(indent(base_str, indent_spaces=1), one_space) # not more than one space assert not __lines_with_indent(indent(base_str, indent_spaces=1), two_spaces) # indent_spaces == 2 # two spaces assert not __lines_without_indent(indent(base_str, indent_spaces=2), two_spaces) # not more than two spaces assert not __lines_with_indent(indent(base_str, indent_spaces=2), three_spaces) # indent_str == '+' # all lines have one plus indent assert not __lines_without_indent(indent(base_str, indent_str=one_plus), one_plus) # no lines have more than one plus indent assert not __lines_with_indent(indent(base_str, indent_str=one_plus), two_plus) # indent_str == '++' # all lines have two pluses indent assert not __lines_without_indent(indent(base_str, indent_str=two_plus), two_plus) # no lines have more than two pluses indent assert not __lines_with_indent(indent(base_str, indent_str=two_plus), three_plus)