> May i ask another question here (if you say no, i'll make another discussion)
Of course, yes :-) > I made a custom directive that generates a video and displays it. But the > video generation process is quite long, and, when i launch sphinx gettext or > pdf target, the videos takes a lot of unneeded time to generate. > So, is there a way i can know which target sphinx was launched with inside my > directive code, so i generate the video the good way ? Directive itself should not know what builder is running now because the output of the directive are cached and used to other builds (a.k.a. incremental build feature). It would be better to process it after the builder is determined. That is the resolving phase (see https://www.sphinx-doc.org/en/master/extdev/index.html#build-phases). So you need to process videos in two steps. 1) Generate an intermediate node on the directive, and 2) process a video by type of current builder on resolving phase. ``` from docutils import nodes class my_video(nodes.Element): """A node for video""" pass class VideoDirective(Directive): def run(self): # generate a video node (please fill attributes using options if you need it on latter step). node = my_video() return [node] def on_doctree_resolved(app, doctree, docname): # process my_video nodes only if HTML builds # Note: you can also use "builder.format" to determine builder types. if app.builder.name == 'html': for video in doctree.traverse(my_video): process_video(video) ``` Thanks, Takeshi KOMIYA -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/CAFmkQAOs1XVQz5779r_UCfyD29pdJZK5XZt%3DsbfN%2Bc%3Dv8kUJXA%40mail.gmail.com.
