Skip to content
Browse files

fix issues when parsing sphinx documentation with custom environment …

  • Loading branch information...
sdpython committed Sep 7, 2015
1 parent 46d67f8 commit d054ae56b29d103909a490cfd9bafcfa9270dc1c
@@ -207,6 +207,50 @@ def depart_node(self, node):
if tb not in html:
raise Exception(html)

def test_newdirective_with_rst2html_bug(self):
OutputPrint=__name__ == "__main__")

from docutils import nodes

class runpythonthis_node(nodes.Structural, nodes.Element):

class RunPythonThisDirective (RunPythonDirective):
runpython_class = runpythonthis_node

def visit_node(self, node):

def depart_node(self, node):

content = """
.. deprecated:: 0.3
to add
this code shoud appear___
""".replace(" ", "")

tives = [("runpythonthis", RunPythonThisDirective, runpythonthis_node,
visit_node, depart_node)]

html = rst2html(content, fLOG=fLOG,
writer="custom", keep_warnings=True,

t1 = "this code shoud appear___"
assert t1 in html
ta = "Deprecated since version 0.3"
if ta not in html:
raise Exception(html)

if __name__ == "__main__":
@@ -32,3 +32,4 @@ def get_help_usage():
from .sphinx_main import generate_help_sphinx, process_notebooks
from .sphinx_runpython_extension import RunPythonDirective, runpython_node
from .utils_sphinx_config import NbImage
from .utils_pywin32 import import_pywin32
@@ -106,8 +106,11 @@ def __init__(self, filename, encoding="utf8", raise_exception=False):
raise BlogPostParseError("unable to parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
all_err, self._filename, content))
warnings.warn("Raw rst was caught but unable to fully parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
all_err, self._filename, content))
# we assume we just need the content, raising a warnings
# might make some process fail later
# warnings.warn("Raw rst was caught but unable to fully parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
# all_err, self._filename, content))

#document = pub.writer.document
objects = pub.settings.out_blogpostlist
@@ -10,6 +10,8 @@
from docutils import core
# from docutils import nodes
from docutils.parsers.rst import directives as doc_directives
from sphinx.environment import BuildEnvironment, default_settings
from sphinx.config import Config

from .utils_sphinx_doc import migrating_doxygen_doc
from ..loghelper.flog import noLOG
@@ -131,15 +133,22 @@ def depart_node(self, node):
# nodes._add_node_class_names([node.__name__])
writer.connect_directive_node(node.__name__, f1, f2)

settings_overrides = {'output_encoding': 'unicode',
'doctitle_xform': True,
'initial_header_level': 2,
'warning_stream': StringIO(),
'input_encoding': 'utf8',
'out_blogpostlist': [],
'out_runpythonlist': [],
'blog_background': False,
settings_overrides = default_settings.copy()
settings_overrides.update({'output_encoding': 'unicode',
'doctitle_xform': True,
'initial_header_level': 2,
'warning_stream': StringIO(),
'input_encoding': 'utf8',
'out_blogpostlist': [],
'out_runpythonlist': [],
'blog_background': False,

config = Config(None, None, overrides=settings_overrides, tags=None)
config.blog_background = False
env = BuildEnvironment(None, None, config=config)
env.temp_data["docname"] = "string"
settings_overrides["env"] = env

parts = core.publish_parts(source=s, source_path=None,
destination_path=None, writer=writer,
@@ -2,10 +2,11 @@
@brief Helpers to convert docstring to various format
.. versionadded:: 1.0
.. versionadded:: 1.3
import sys
# from docutils import nodes
from docutils.languages import en as docutils_en
from sphinx.writers.html import HTMLWriter, HTMLTranslator
from import SingleFileHTMLBuilder, SerializingHTMLBuilder
from sphinx.application import Sphinx
@@ -20,6 +21,23 @@
from io import StringIO

def update_docutils_languages(values=None):
update ``docutils/languages/`` with missing labels
does that for languages:
* en
@param values consider values in this dictionaries first
if values is None:
values = dict()
lab = docutils_en.labels
if 'versionmodified' not in lab:
lab['versionmodified'] = values.get('versionmodified', '')

class HTMLTranslatorWithCustomDirectives(HTMLTranslator):
@see cl HTMLWriterWithCustomDirectives
@@ -135,6 +153,7 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
from sphinx.application import BUILTIN_DOMAINS, BUILTIN_BUILDERS, events, bold, Tags, Config, CONFIG_FILENAME, ConfigError, VersionRequirementError
from sphinx import __display_version__
self.verbosity = verbosity
self.next_listener_id = 0
self._extensions = {}

0 comments on commit d054ae5

Please sign in to comment.
You can’t perform that action at this time.