Beispiel #1
0
def check_rst_files():
    string_io = io.StringIO()
    settings_overrides = {}
    settings_overrides.update(readme_rst.SETTINGS)
    settings_overrides['report_level'] = 2
    settings_overrides['warning_stream'] = string_io
    files = [_ for _ in iglob('*.rst', recursive=True)]
    for file in files:
        data = read_rst_file(file)
        try:
            docutils.core.publish_string(data, settings_overrides=settings_overrides)
            clean_body = readme_rst.clean(''.join(data))
            if clean_body is None:
                # Raised sometimes when rendered failed to generate html
                string_io.write("Failed to generate output for rendering")
                raise ValueError("Output Failed")
        except Exception:
            pass
        errors = string_io.getvalue().strip()
        if errors:
            body = 'There are some Errors in your RST file syntax \n\n'
            for error in errors.splitlines():
                body += '- {}\n'.format(error)
            print(body)
            sys.exit(1)
    def rest_to_html(self,
                     rest_input,
                     settings=None,
                     mtime=None,
                     filename=None):
        """Render ReStructuredText."""
        writer = docutils.writers.html4css1.Writer()
        if pygments is not None:
            writer.translator_class = SyntaxHighlightingHTMLTranslator
        if self.stylesheets:
            stylesheet_dirs = writer.default_stylesheet_dirs + [DATA_PATH]
            # docutils can't embed http:// or https:// URLs
            embed_stylesheet = '//' not in self.stylesheets
            settings_overrides = {
                'stylesheet': self.stylesheets,
                'stylesheet_path': None,
                'stylesheet_dirs': stylesheet_dirs,
                'embed_stylesheet': embed_stylesheet
            }
        else:
            settings_overrides = {}
        settings_overrides['syntax_highlight'] = 'short'
        if self.pypi_strict:
            settings_overrides.update(readme_rst.SETTINGS)
        if self.halt_level is not None:
            settings_overrides['halt_level'] = self.halt_level
        if self.report_level is not None:
            settings_overrides['report_level'] = self.report_level

        if settings:  # hook for unit tests
            settings_overrides.update(settings)

        try:
            docutils.core.publish_string(rest_input,
                                         writer=writer,
                                         source_path=filename,
                                         settings_overrides=settings_overrides)
            if self.pypi_strict:
                clean_body = readme_rst.clean(''.join(writer.body))
                if clean_body is None:
                    # Unfortunately the real error was caught and discared,
                    # without even logging :/
                    raise ValueError("Output cleaning failed")
                writer.body = [clean_body]
                writer.output = writer.apply_template()
        except Exception as e:
            line = self.extract_line_info(e, filename)
            html = self.render_exception(e.__class__.__name__,
                                         str(e),
                                         rest_input,
                                         mtime=mtime,
                                         line=line)
        else:
            html = writer.output
        return self.inject_ajax(html, mtime=mtime)
Beispiel #3
0
    def rest_to_html(self,
                     rest_input,
                     settings=None,
                     mtime=None,
                     filename=None):
        """Render ReStructuredText."""
        writer = docutils.writers.html4css1.Writer()
        if pygments is not None:
            writer.translator_class = SyntaxHighlightingHTMLTranslator
        if self.stylesheets:
            stylesheet_dirs = writer.default_stylesheet_dirs + [DATA_PATH]
            # docutils can't embed http:// or https:// URLs
            embed_stylesheet = '//' not in self.stylesheets
            settings_overrides = {
                'stylesheet': self.stylesheets,
                'stylesheet_path': None,
                'stylesheet_dirs': stylesheet_dirs,
                'embed_stylesheet': embed_stylesheet
            }
        else:
            settings_overrides = {}
        settings_overrides['syntax_highlight'] = 'short'
        if self.pypi_strict:
            settings_overrides.update(readme_rst.SETTINGS)
        if self.strict:
            settings_overrides['halt_level'] = 1

        if settings:
            settings_overrides.update(settings)

        try:
            docutils.core.publish_string(rest_input,
                                         writer=writer,
                                         source_path=filename,
                                         settings_overrides=settings_overrides)
        except Exception as e:
            line = self.extract_line_info(e, filename)
            html = self.render_exception(e.__class__.__name__,
                                         str(e),
                                         rest_input,
                                         mtime=mtime,
                                         line=line)
        else:
            if self.pypi_strict:
                writer.body = [readme_rst.clean(''.join(writer.body))]
                writer.output = writer.apply_template()
            html = writer.output
        return self.inject_ajax(html, mtime=mtime)
Beispiel #4
0
    def rest_to_html(self, rest_input, settings=None, mtime=None, filename=None):
        """Render ReStructuredText."""
        writer = docutils.writers.html4css1.Writer()
        if pygments is not None:
            writer.translator_class = SyntaxHighlightingHTMLTranslator
        if self.stylesheets:
            stylesheet_dirs = writer.default_stylesheet_dirs + [DATA_PATH]
            # docutils can't embed http:// or https:// URLs
            embed_stylesheet = '//' not in self.stylesheets
            settings_overrides = {'stylesheet': self.stylesheets,
                                  'stylesheet_path': None,
                                  'stylesheet_dirs': stylesheet_dirs,
                                  'embed_stylesheet': embed_stylesheet}
        else:
            settings_overrides = {}
        settings_overrides['syntax_highlight'] = 'short'
        if self.pypi_strict:
            settings_overrides.update(readme_rst.SETTINGS)
        if self.halt_level is not None:
            settings_overrides['halt_level'] = self.halt_level
        if self.report_level is not None:
            settings_overrides['report_level'] = self.report_level

        if settings:  # hook for unit tests
            settings_overrides.update(settings)

        try:
            docutils.core.publish_string(rest_input, writer=writer,
                                         source_path=filename,
                                         settings_overrides=settings_overrides)
            if self.pypi_strict:
                clean_body = readme_rst.clean(''.join(writer.body))
                if clean_body is None:
                    # Unfortunately the real error was caught and discared,
                    # without even logging :/
                    raise ValueError("Output cleaning failed")
                writer.body = [clean_body]
                writer.output = writer.apply_template()
        except Exception as e:
            line = self.extract_line_info(e, filename)
            html = self.render_exception(e.__class__.__name__, str(e), rest_input, mtime=mtime, line=line)
        else:
            html = writer.output
        return self.inject_ajax(html, mtime=mtime)
Beispiel #5
0
    def rest_to_html(self, rest_input, settings=None, mtime=None, filename=None):
        """Render ReStructuredText."""
        writer = docutils.writers.html4css1.Writer()
        if pygments is not None:
            writer.translator_class = SyntaxHighlightingHTMLTranslator
        if self.stylesheets:
            stylesheet_dirs = writer.default_stylesheet_dirs + [DATA_PATH]
            # docutils can't embed http:// or https:// URLs
            embed_stylesheet = '//' not in self.stylesheets
            settings_overrides = {'stylesheet': self.stylesheets,
                                  'stylesheet_path': None,
                                  'stylesheet_dirs': stylesheet_dirs,
                                  'embed_stylesheet': embed_stylesheet}
        else:
            settings_overrides = {}
        settings_overrides['syntax_highlight'] = 'short'
        if self.pypi_strict:
            settings_overrides.update(readme_rst.SETTINGS)
        if self.strict:
            settings_overrides['halt_level'] = 1

        if settings:
            settings_overrides.update(settings)

        try:
            docutils.core.publish_string(rest_input, writer=writer,
                                         source_path=filename,
                                         settings_overrides=settings_overrides)
        except Exception as e:
            line = self.extract_line_info(e, filename)
            html = self.render_exception(e.__class__.__name__, str(e), rest_input, mtime=mtime, line=line)
        else:
            if self.pypi_strict:
                writer.body = [readme_rst.clean(''.join(writer.body))]
                writer.output = writer.apply_template()
            html = writer.output
        return self.inject_ajax(html, mtime=mtime)