我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用docutils.utils.SystemMessage()。
def run(self): if not color_terminal(): nocolor() if not self.verbose: status_stream = StringIO() else: status_stream = sys.stdout confoverrides = {} if self.project: confoverrides['project'] = self.project if self.version: confoverrides['version'] = self.version if self.release: confoverrides['release'] = self.release if self.today: confoverrides['today'] = self.today if self.copyright: confoverrides['copyright'] = self.copyright app = Sphinx(self.source_dir, self.config_dir, self.builder_target_dir, self.doctree_dir, self.builder, confoverrides, status_stream, freshenv=self.fresh_env) try: app.build(force_all=self.all_files) if app.statuscode: raise DistutilsExecError( 'caused by %s builder.' % app.builder.name) except Exception as err: from docutils.utils import SystemMessage if isinstance(err, SystemMessage): print(darkred('reST markup error:'), file=sys.stderr) print(err.args[0].encode('ascii', 'backslashreplace'), file=sys.stderr) else: raise if self.link_index: src = app.config.master_doc + app.builder.out_suffix dst = app.builder.get_outfilename('index') os.symlink(src, dst)
def _sphinx_run(self): if not self.verbose: status_stream = cStringIO.StringIO() else: status_stream = sys.stdout confoverrides = {} if self.version: confoverrides['version'] = self.version if self.release: confoverrides['release'] = self.release if self.today: confoverrides['today'] = self.today sphinx_config = config.Config(self.config_dir, 'conf.py', {}, []) sphinx_config.init_values() if self.builder == 'man' and len(sphinx_config.man_pages) == 0: return app = application.Sphinx( self.source_dir, self.config_dir, self.builder_target_dir, self.doctree_dir, self.builder, confoverrides, status_stream, freshenv=self.fresh_env, warningiserror=True) try: app.build(force_all=self.all_files) except Exception as err: from docutils import utils if isinstance(err, utils.SystemMessage): sys.stder.write('reST markup error:\n') sys.stderr.write(err.args[0].encode('ascii', 'backslashreplace')) sys.stderr.write('\n') else: raise if self.link_index: src = app.config.master_doc + app.builder.out_suffix dst = app.builder.get_outfilename('index') os.symlink(src, dst)
def _sphinx_run(self): if not self.verbose: status_stream = cStringIO.StringIO() else: status_stream = sys.stdout confoverrides = {} if self.version: confoverrides['version'] = self.version if self.release: confoverrides['release'] = self.release if self.today: confoverrides['today'] = self.today sphinx_config = config.Config(self.config_dir, 'conf.py', {}, []) sphinx_ver = pkg_resources.get_distribution("sphinx").version if pkg_resources.parse_version(sphinx_ver) >= \ pkg_resources.parse_version('1.3.1'): sphinx_config.init_values(warnings.warn) else: sphinx_config.init_values() if self.builder == 'man' and len(sphinx_config.man_pages) == 0: return app = application.Sphinx( self.source_dir, self.config_dir, self.builder_target_dir, self.doctree_dir, self.builder, confoverrides, status_stream, freshenv=self.fresh_env, warningiserror=False) try: app.build(force_all=self.all_files) except Exception as err: from docutils import utils if isinstance(err, utils.SystemMessage): sys.stder.write('reST markup error:\n') sys.stderr.write(err.args[0].encode('ascii', 'backslashreplace')) sys.stderr.write('\n') else: raise if self.link_index: src = app.config.master_doc + app.builder.out_suffix dst = app.builder.get_outfilename('index') os.symlink(src, dst)
def _sphinx_run(self): if not self.verbose: status_stream = cStringIO.StringIO() else: status_stream = sys.stdout confoverrides = {} if self.project: confoverrides['project'] = self.project if self.version: confoverrides['version'] = self.version if self.release: confoverrides['release'] = self.release if self.today: confoverrides['today'] = self.today if self.sphinx_initialized: confoverrides['suppress_warnings'] = [ 'app.add_directive', 'app.add_role', 'app.add_generic_role', 'app.add_node', 'image.nonlocal_uri', ] app = application.Sphinx( self.source_dir, self.config_dir, self.builder_target_dir, self.doctree_dir, self.builder, confoverrides, status_stream, freshenv=self.fresh_env, warningiserror=self.warning_is_error) self.sphinx_initialized = True try: app.build(force_all=self.all_files) except Exception as err: from docutils import utils if isinstance(err, utils.SystemMessage): sys.stder.write('reST markup error:\n') sys.stderr.write(err.args[0].encode('ascii', 'backslashreplace')) sys.stderr.write('\n') else: raise if self.link_index: src = app.config.master_doc + app.builder.out_suffix dst = app.builder.get_outfilename('index') os.symlink(src, dst)