Hello sphinx users list,

in my pylatest sphinx extension[1],
I define custom rst directive `test_action` and custom sphinx builder
`xmlexport` so that when I build a sphinx project with default sphinx html
builder (via `make html`), the `test_action` directives are transformed into
single html table, while with `xmlexport` builder, the directives are just
wrapped in `div` html tags without any additional processing.

To achieve this, the `test_action` directives generates custom doctree nodes
which are either directly translated into html (extending html translator) when
`xmlexport` builder is used, or with `html` builder the custom nodes are
transformed into html table via custom rst transformation class.

I achieve this by checking which builder is used and adding transform classes
accordingly:

    def pylatest_transform_handler(app):
        if isinstance(app.builder, builders.XmlExportBuilder):
            ...
        else:
            # pylatest transforms for human readable html output,
            # translates pylatest nodes into nice sections or tables
            app.add_transform(transforms.TestActionsTableTransform)

In a function which handles `builder-inited` event[2] in my sphinx extension:

    def setup(app):
        ...
        # pylatest transforms are added based on app.builder value
        app.connect('builder-inited', pylatest_transform_handler)

This hack works, but it has one problem: when `html` builder is used, doctree
cached in `_build/doctree/` is diferent compared to one cached after
`xmlexport` builder run. This means that when I run `make html` after I
executed `make xmlexport`, the build fails because sphinx uses wrong doctree.

So the question I have is: How do I make sure that sphinx doctree cache is
regenerated when different builders are used after each other, but kept when
the same builder is used again?

[1] 
https://gitlab.com/mbukatov/pylatest/blob/master/pylatest/xsphinx/extension.py
[2] http://www.sphinx-doc.org/en/stable/extdev/appapi.html#event-builder-inited

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to