def run(self): split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: LOG.info('loading config file %s', config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( args=['--config-file', config_file], project='oslo.config.sphinxext', ) namespaces = conf.namespace[:] else: namespaces = [c.strip() for c in self.content if c.strip()] result = ViewList() source_name = '<' + __name__ + '>' for line in _format_option_help(namespaces, split_namespaces): result.append(line, source_name) node = nodes.section() node.document = self.state.document # With the resolution for bug #1755783, we now parse the 'Opt.help' # attribute as rST. Unfortunately, there are a lot of broken option # descriptions out there and we don't want to break peoples' builds # suddenly. As a result, we disable 'warning-is-error' temporarily. # Users will still see the warnings but the build will continue. with logging.skip_warningiserror(): nested_parse_with_titles(self.state, result, node) return node.children
def run(self): split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: LOG.info('loading config file %s', config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( args=['--config-file', config_file], project='oslo.config.sphinxext', ) namespaces = conf.namespace[:] else: namespaces = [ c.strip() for c in self.content if c.strip() ] result = ViewList() source_name = self.state.document.current_source with tempfile.NamedTemporaryFile(suffix='.rst', delete=False) as tmp: # NOTE(stephenfin): We dump the output to a tempfile to assist # people in debugging their broken config options. It would be good # to conditionalize this but that would require access to error # state from the directive, which we don't have, and would # necessitate holding the whole file, which could be rather large, # in memory while we wait on the decision. LOG.info('dumping output to %r', tmp.name) offset = 0 for count, line in enumerate(_format_option_help( namespaces, split_namespaces)): # FIXME(stephenfin): Some lines emitted are actually multiple # lines. This throws off our counter, which is rather annoying. # We handle this here but we should really handle it higher up. parts = line.split('\n') if len(parts) > 1: offset += len(parts) - 1 for part in parts: result.append(line, source_name, count + offset) tmp.write(line.encode('utf-8')) node = nodes.section() node.document = self.state.document # With the resolution for bug #1755783, we now parse the 'Opt.help' # attribute as rST. Unfortunately, there are a lot of broken option # descriptions out there and we don't want to break peoples' builds # suddenly. As a result, we disable 'warning-is-error' temporarily. # Users will still see the warnings but the build will continue. with logging.skip_warningiserror(): nested_parse_with_titles(self.state, result, node) return node.children
def run(self): env = self.state.document.settings.env app = env.app config_file = self.options.get('config-file') # if the config_file option was not defined, attempt to reuse the # 'oslo_policy.sphinxpolicygen' extension's setting if not config_file and hasattr(env.config, 'policy_generator_config_file'): config_file = env.config.policy_generator_config_file # If we are given a file that isn't an absolute path, look for it # in the source directory if it doesn't exist. candidates = [ config_file, os.path.join(app.srcdir, config_file,), ] for c in candidates: if os.path.isfile(c): config_path = c break else: raise ValueError( 'could not find config file in: %s' % str(candidates) ) self.info('loading config file %s' % config_path) conf = cfg.ConfigOpts() opts = generator.GENERATOR_OPTS + generator.RULE_OPTS conf.register_cli_opts(opts) conf.register_opts(opts) conf( args=['--config-file', config_path], ) namespaces = conf.namespace[:] result = statemachine.ViewList() source_name = '<' + __name__ + '>' for line in _format_policy(namespaces): result.append(line, source_name) node = nodes.section() node.document = self.state.document # With the resolution for bug #1788183, we now parse the # 'DocumentedRuleDefault.description' attribute as rST. Unfortunately, # there are a lot of broken option descriptions out there and we don't # want to break peoples' builds suddenly. As a result, we disable # 'warning-is-error' temporarily. Users will still see the warnings but # the build will continue. with logging.skip_warningiserror(): nested_parse_with_titles(self.state, result, node) return node.children
def setUpClass(cls): cls.temp_dir = mkdtemp() config = dict(ClientSao.config_options) for key in config: env_name = 'TEST_SPHINXCONTRIB_{}_{}'.format( ClientSao.config_prefix.upper(), key.upper()) if env_name in environ: config[key] = environ[env_name] cls.sao = ClientSao(**config) with skip_warningiserror(): cls.sao.start()
def test_skip_warningiserror(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) app.warningiserror = True with logging.skip_warningiserror(): logger.warning('message') # if False, warning raises SphinxWarning exception with pytest.raises(SphinxWarning): with logging.skip_warningiserror(False): logger.warning('message') # It also works during pending_warnings. with logging.pending_warnings(): with logging.skip_warningiserror(): logger.warning('message') with pytest.raises(SphinxWarning): with logging.pending_warnings(): with logging.skip_warningiserror(False): logger.warning('message')
def import_module(modname, warningiserror=False): """ Call __import__(modname), convert exceptions to ImportError """ try: with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=ImportWarning) with logging.skip_warningiserror(not warningiserror): return __import__(modname) except BaseException: # Importing modules may cause any side effects, including # SystemExit, so we need to catch all errors. raise ImportError(traceback.format_exc())
def test_skip_warningiserror(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) app.warningiserror = True with logging.skip_warningiserror(): logger.warning('message') # if False, warning raises SphinxWarning exception with pytest.raises(SphinxWarning): with logging.skip_warningiserror(False): logger.warning('message') # It also works during pending_warnings. with logging.pending_warnings(): with logging.skip_warningiserror(): logger.warning('message') with pytest.raises(SphinxWarning): with logging.pending_warnings(): with logging.skip_warningiserror(False): logger.warning('message')
def import_module(modname, warningiserror=False): """ Call __import__(modname), convert exceptions to ImportError """ try: with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=ImportWarning) with logging.skip_warningiserror(not warningiserror): __import__(modname) return sys.modules[modname] except BaseException: # Importing modules may cause any side effects, including # SystemExit, so we need to catch all errors. raise ImportError(traceback.format_exc())
def run(self): split_namespaces = 'split-namespaces' in self.options config_file = self.options.get('config-file') if config_file: LOG.info('loading config file %s', config_file) conf = cfg.ConfigOpts() conf.register_opts(generator._generator_opts) conf( args=['--config-file', config_file], project='oslo.config.sphinxext', ) namespaces = conf.namespace[:] else: namespaces = [ c.strip() for c in self.content if c.strip() ] result = ViewList() source_name = self.state.document.current_source for count, line in enumerate(_format_option_help( namespaces, split_namespaces)): result.append(line, source_name, count) LOG.debug('%5d%s%s', count, ' ' if line else '', line) node = nodes.section() node.document = self.state.document # With the resolution for bug #1755783, we now parse the 'Opt.help' # attribute as rST. Unfortunately, there are a lot of broken option # descriptions out there and we don't want to break peoples' builds # suddenly. As a result, we disable 'warning-is-error' temporarily. # Users will still see the warnings but the build will continue. with logging.skip_warningiserror(): nested_parse_with_titles(self.state, result, node) return node.children
def _register_title(self, title): with skip_warningiserror(): return ConfluenceState.register_title('mock', title, self.config)
def tearDownClass(cls): with skip_warningiserror(): cls.sao.stop() rmtree(cls.temp_dir, ignore_errors=True)