Ticket #6495: trac_6495_output_filter.patch
File trac_6495_output_filter.patch, 5.3 KB (added by , 9 years ago) |
---|
-
doc/common/builder.py
# HG changeset patch # User Volker Braun <vbraun.name@gmail.com> # Date 1359636478 0 # Node ID 39e2ad03ea0dc13b40c14cc9270f5a94b8f352f4 # Parent 94f8c642b47ebf1d885cb25ea99fc9f461fc7b44 Filter unnecessary messages, and line buffer the necessary ones diff --git a/doc/common/builder.py b/doc/common/builder.py
a b 94 94 # WEBSITESPHINXOPTS is either empty or " -A hide_pdf_links=1 " 95 95 options += WEBSITESPHINXOPTS 96 96 97 build_command = ' sphinx-build'97 build_command = 'python '+os.path.join(SAGE_DOC, 'common', 'custom-sphinx-build.py') 98 98 build_command += ' -b %s -d %s %s %s %s'%(type, self._doctrees_dir(), 99 99 options, self.dir, 100 100 output_dir) 101 logger. warning(build_command)101 logger.debug(build_command) 102 102 subprocess.call(build_command, shell=True) 103 103 104 logger.warning("Build finished. The built documents can be found in %s", output_dir) 104 logger.info("Build finished and can be found in %s", 105 output_dir.replace(SAGE_DOC+'/', '')) 105 106 106 107 f.is_output_format = True 107 108 return f -
doc/common/conf.py
diff --git a/doc/common/conf.py b/doc/common/conf.py
a b 116 116 refpath = 'output/html/en/reference/' 117 117 if not app.srcdir.endswith('reference'): 118 118 app.config.intersphinx_mapping[get_doc_abspath(refpath)] = get_doc_abspath(refpath+'objects.inv') 119 119 120 pythonversion = sys.version.split(' ')[0] 120 121 # Python and Sage trac ticket shortcuts. For example, :trac:`7549` . 121 122 … … 609 610 app.connect('autodoc-process-docstring', process_dollars) 610 611 app.connect('autodoc-process-docstring', process_inherited) 611 612 app.connect('autodoc-skip-member', skip_member) 612 613 613 614 # When building the standard docs, app.srcdir is set to SAGE_DOC + 614 615 # 'LANGUAGE/DOCNAME', but when doing introspection, app.srcdir is 615 616 # set to a temporary directory. We don't want to use intersphinx, … … 625 626 app.connect('builder-inited', set_intersphinx_mappings) 626 627 app.connect('builder-inited', sphinx.ext.intersphinx.load_mappings) 627 628 app.connect('builder-inited', nitpick_patch_config) 628 # Minimize GAP/libGAP RAM usage when we build the docs629 from sage.interfaces.gap import set_gap_memory_pool_size630 set_gap_memory_pool_size(0) # will be rounded up to 1M631 629 -
new file doc/common/custom-sphinx-build.py
diff --git a/doc/common/custom-sphinx-build.py b/doc/common/custom-sphinx-build.py new file mode 100644
- + 1 """ 2 This is Sage's version of the sphinx-build script 3 4 Enhancements are: 5 6 * import the Sage library to access the docstrings, otherwise doc 7 buliding doesn't work. 8 9 * redirect stdout to our own logger, and remove some unwanted chatter. 10 """ 11 12 import os 13 import sys 14 import re 15 16 17 18 useless_chatter = ( 19 re.compile('^Running Sphinx v'), 20 re.compile('^loading intersphinx inventory from '), 21 re.compile('^Compiling a sub-document'), 22 ) 23 24 25 class SageSphinxLogger(object): 26 """ 27 This implements the file object interface to serve as sys.stdout 28 replacement. 29 """ 30 ansi_color = re.compile(r'\x1b\[[0-9;]*m') 31 prefix_len = 9 32 33 def __init__(self, stream, prefix): 34 self._stream = stream 35 prefix = prefix[0:self.prefix_len] 36 prefix = ('[{0:'+str(self.prefix_len)+'}]').format(prefix) 37 self._prefix = prefix 38 39 def _filter_out(self, line): 40 line = re.sub(self.ansi_color, '', line) 41 for regex in useless_chatter: 42 if regex.match(line) is not None: 43 return True 44 return False 45 46 def _log_line(self, line): 47 if self._filter_out(line): 48 return 49 self._stream.write(self._prefix + ' ' + line + '\n') 50 self._stream.flush() 51 52 _line_buffer = '' 53 54 def _write(self, string): 55 self._line_buffer += string 56 lines = self._line_buffer.splitlines() 57 for i, line in enumerate(lines): 58 last = (i == len(lines)-1) 59 if last and not self._line_buffer.endswith('\n'): 60 self._line_buffer = line 61 return 62 self._log_line(line) 63 self._line_buffer = '' 64 65 66 # file object interface follows 67 68 closed = False 69 encoding = None 70 mode = 'w' 71 name = '<log>' 72 newlines = None 73 softspace = 0 74 75 def isatty(self): 76 return True 77 78 def close(self): 79 if self._line_buffer != '': 80 self._log_line(self._line_buffer) 81 self._line_buffer = '' 82 83 def flush(self): 84 self._stream.flush() 85 86 def write(self, str): 87 self._write(str) 88 89 def writelines(self, sequence): 90 for line in sequence: 91 self.write(line) 92 93 94 output_dir = sys.argv[-1] 95 sys.stdout = SageSphinxLogger(sys.stdout, os.path.basename(output_dir)) 96 97 98 99 # pull in the Sage library 100 import sage.all 101 102 # Minimize GAP/libGAP RAM usage when we build the docs 103 from sage.interfaces.gap import set_gap_memory_pool_size 104 set_gap_memory_pool_size(0) # will be rounded up to 1M 105 106 if __name__ == '__main__': 107 from sphinx.cmdline import main 108 sys.exit(main(sys.argv)) 109