Python absl.flags.text_wrap() Examples
The following are 3
code examples of absl.flags.text_wrap().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
absl.flags
, or try the search function
.
Example #1
Source File: flags_formatting_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_text_wrap_raises_on_excessive_indent(self): """Ensure an indent longer than line length raises.""" self.assertRaises(ValueError, flags.text_wrap, 'dummy', length=10, indent=' ' * 10)
Example #2
Source File: flags_formatting_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_text_wrap_raises_on_excessive_first_line(self): """Ensure a first line indent longer than line length raises.""" self.assertRaises( ValueError, flags.text_wrap, 'dummy', length=80, firstline_indent=' ' * 80)
Example #3
Source File: app.py From abseil-py with Apache License 2.0 | 4 votes |
def usage(shorthelp=False, writeto_stdout=False, detailed_error=None, exitcode=None): """Writes __main__'s docstring to stderr with some help text. Args: shorthelp: bool, if True, prints only flags from the main module, rather than all flags. writeto_stdout: bool, if True, writes help message to stdout, rather than to stderr. detailed_error: str, additional detail about why usage info was presented. exitcode: optional integer, if set, exits with this status code after writing help. """ if writeto_stdout: stdfile = sys.stdout else: stdfile = sys.stderr doc = sys.modules['__main__'].__doc__ if not doc: doc = '\nUSAGE: %s [flags]\n' % sys.argv[0] doc = flags.text_wrap(doc, indent=' ', firstline_indent='') else: # Replace all '%s' with sys.argv[0], and all '%%' with '%'. num_specifiers = doc.count('%') - 2 * doc.count('%%') try: doc %= (sys.argv[0],) * num_specifiers except (OverflowError, TypeError, ValueError): # Just display the docstring as-is. pass if shorthelp: flag_str = FLAGS.main_module_help() else: flag_str = FLAGS.get_help() try: stdfile.write(doc) if flag_str: stdfile.write('\nflags:\n') stdfile.write(flag_str) stdfile.write('\n') if detailed_error is not None: stdfile.write('\n%s\n' % detailed_error) except IOError as e: # We avoid printing a huge backtrace if we get EPIPE, because # "foo.par --help | less" is a frequent use case. if e.errno != errno.EPIPE: raise if exitcode is not None: sys.exit(exitcode)