Python docutils.core() Examples
The following are 8
code examples of docutils.core().
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
docutils
, or try the search function
.
Example #1
Source File: doc_utils.py From pagure with GNU General Public License v2.0 | 6 votes |
def convert_doc(rst_string, view_file_url=None): """ Utility to load an RST file and turn it into fancy HTML. """ rst = modify_rst(rst_string, view_file_url) overrides = {"report_level": "quiet"} try: html = docutils.core.publish_parts( source=rst, writer_name="html", settings_overrides=overrides ) except Exception: return "<pre>%s</pre>" % jinja2.escape(rst) else: html_string = html["html_body"] html_string = modify_html(html_string) html_string = markupsafe.Markup(html_string) return html_string
Example #2
Source File: utils.py From qubes-core-admin with GNU Lesser General Public License v2.1 | 6 votes |
def format_doc(docstring): '''Return parsed documentation string, stripping RST markup. ''' if not docstring: return '' # pylint: disable=unused-variable output, pub = docutils.core.publish_programmatically( source_class=docutils.io.StringInput, source=' '.join(docstring.strip().split()), source_path=None, destination_class=docutils.io.NullOutput, destination=None, destination_path=None, reader=None, reader_name='standalone', parser=None, parser_name='restructuredtext', writer=None, writer_name='null', settings=None, settings_spec=None, settings_overrides=None, config_section=None, enable_exit_status=None) return pub.writer.document.astext()
Example #3
Source File: setup.py From parsec-cloud with GNU Affero General Public License v3.0 | 6 votes |
def run(self): import os import pathlib from babel.messages.frontend import CommandLineInterface self.announce("Compiling ui translation files", level=distutils.log.INFO) ui_dir = pathlib.Path("parsec/core/gui") tr_dir = ui_dir / "tr" rc_dir = ui_dir / "rc" / "translations" os.makedirs(rc_dir, exist_ok=True) languages = ["fr", "en"] for lang in languages: args = [ "_", "compile", "-i", str(tr_dir / f"parsec_{lang}.po"), "-o", str(rc_dir / f"parsec_{lang}.mo"), ] CommandLineInterface().run(args)
Example #4
Source File: json_reader.py From pyvideo with GNU General Public License v3.0 | 6 votes |
def _get_publisher(self, source, source_file_path): # This is a slightly modified copy of `RstReader._get_publisher` extra_params = {'initial_header_level': '4', 'syntax_highlight': 'short', 'input_encoding': 'utf-8', 'exit_status_level': 2, 'embed_stylesheet': False} user_params = self.settings.get('DOCUTILS_SETTINGS') if user_params: extra_params.update(user_params) pub = docutils.core.Publisher( source_class=docutils.io.StringInput, destination_class=docutils.io.StringOutput) pub.set_components('standalone', 'restructuredtext', 'html') pub.writer.translator_class = PelicanHTMLTranslator pub.process_programmatic_settings(None, extra_params, None) pub.set_source(source=source, source_path=source_file_path) pub.publish(enable_exit_status=True) return pub # You need to have a read method, which takes a filename and returns # some content and the associated metadata.
Example #5
Source File: setup.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def run(self): fix_pyqt_import() try: from PyQt5.pyrcc_main import processResourceFile self.announce("Generating `parsec.core.gui._resources_rc`", level=distutils.log.INFO) processResourceFile( ["parsec/core/gui/rc/resources.qrc"], "parsec/core/gui/_resources_rc.py", False ) except ImportError: print("PyQt5 not installed, skipping `parsec.core.gui._resources_rc` generation.")
Example #6
Source File: setup.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def run(self): import docutils.core destination_folder = "parsec/core/gui/rc/generated_misc" self.announce( f"Converting HISTORY.rst to {destination_folder}/history.html", level=distutils.log.INFO ) os.makedirs(destination_folder, exist_ok=True) docutils.core.publish_file( source_path="HISTORY.rst", destination_path=f"{destination_folder}/history.html", writer_name="html", )
Example #7
Source File: setup.py From parsec-cloud with GNU Affero General Public License v3.0 | 5 votes |
def run(self): import os import pathlib from collections import namedtuple fix_pyqt_import() try: from PyQt5.uic.driver import Driver except ImportError: print("PyQt5 not installed, skipping `parsec.core.gui.ui` generation.") return self.announce("Generating `parsec.core.gui.ui`", level=distutils.log.INFO) Options = namedtuple( "Options", ["output", "import_from", "debug", "preview", "execute", "indent", "resource_suffix"], ) ui_dir = pathlib.Path("parsec/core/gui/forms") ui_path = "parsec/core/gui/ui" os.makedirs(ui_path, exist_ok=True) for f in ui_dir.iterdir(): o = Options( output=os.path.join(ui_path, "{}.py".format(f.stem)), import_from="parsec.core.gui", debug=False, preview=False, execute=False, indent=4, resource_suffix="_rc", ) d = Driver(o, str(f)) d.invoke()
Example #8
Source File: setup.py From parsec-cloud with GNU Affero General Public License v3.0 | 4 votes |
def run(self): import os import pathlib from unittest.mock import patch from babel.messages.frontend import CommandLineInterface fix_pyqt_import() try: from PyQt5.pylupdate_main import main as pylupdate_main except ImportError: print("PyQt5 not installed, skipping `parsec.core.gui.ui` generation.") return self.announce("Generating ui translation files", level=distutils.log.INFO) ui_dir = pathlib.Path("parsec/core/gui") tr_dir = ui_dir / "tr" os.makedirs(tr_dir, exist_ok=True) new_args = ["pylupdate", str(ui_dir / "parsec-gui.pro")] with patch("sys.argv", new_args): pylupdate_main() files = [str(f) for f in ui_dir.iterdir() if f.is_file() and f.suffix == ".py"] files.append(str(tr_dir / "parsec_en.ts")) args = [ "_", "extract", "-s", "--no-location", "-F", ".babel.cfg", "--omit-header", "-o", str(tr_dir / "translation.pot"), *files, ] CommandLineInterface().run(args) languages = ["fr", "en"] for lang in languages: po_file = tr_dir / f"parsec_{lang}.po" if not po_file.is_file(): po_file.touch() args = [ "_", "update", "-i", str(tr_dir / "translation.pot"), "-o", str(po_file), "-l", lang, ] CommandLineInterface().run(args)