Thanks a lot for your quick answer, this is exactly what i needed (i 
thought i already answered you, sorry) !

Le dimanche 29 novembre 2020 à 04:20:19 UTC+1, i.tk...@gmail.com a écrit :

> > 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 sphinx-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sphinx-users/2bdfd6f3-ca2e-4d67-afe0-0b4855ae1aben%40googlegroups.com.

Reply via email to