Sphinx breaks transforms that depend on document.transformer.components
, like the standard Filter
transform
#9632
Labels
Milestone
Describe the bug
Sphinx does not give transforms (nor post-transforms) a way to determine which writer will be used. This is because it reads the document with a
DummyWriter
to generate a doctree, and then it callspost_transforms
with an empty list ofself.document.transformer.components
.This breaks transforms that depend on
components
, including the standarddocutils.transforms.components.Filter
.How to Reproduce
The standard
Filter
transform does this:This breaks with Sphinx: if added as a regular transform by
note_pending
,components[component_type]
will be Sphinx'DummyWriter
ifcomponent_type
is"writer"
, and the call tosupports
will return the wrong results. If added as a post-transform it throws an exception becausecomponents
is empty.Here is another example simplified from a separate project; it works with plain Docutils, but not with Sphinx:
If added as a regular transform,
components['writer']
will be Sphinx'DummyWriter
andsupported
will be only{'html'}
. If added as a post_transform the code will throw an exception becausecomponents
won't have a'writer'
key.Expected behavior
Ideally, the
Filter
transform (and other similar transforms) should just work, which might require running transforms after the caching stage, with the correct set ofcomponents
(I imagineDummyWriter
is for caching purposes?).If that's not possible, then maybe it's possible for
post_transforms
? At the momentpost_transforms
do not see any components at all.If that's not possible, then it would be nice to have some (Sphinx-specific, unfortunately) way to determine the list of formats supported by the writer from a post-transform.
Python version
Python 3.8.10
Sphinx version
sphinx-build 3.5.4
The text was updated successfully, but these errors were encountered: