All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Heiser <markus.heiser@darmarit.de>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	linux-doc@vger.kernel.org,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Mauro Carvalho Chehab <mchehab@s-opensource.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Subject: Re: [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images
Date: Thu, 2 Mar 2017 09:23:43 +0100	[thread overview]
Message-ID: <F595B7DD-4BA5-4935-8B4D-37D05EBB8EED@darmarit.de> (raw)
In-Reply-To: <20170302071259.puoqarzmh7spcden@phenom.ffwll.local>


Am 02.03.2017 um 08:12 schrieb Daniel Vetter <daniel@ffwll.ch>:

> On Wed, Mar 01, 2017 at 12:56:36PM -0300, Gabriel Krisman Bertazi wrote:
>> Daniel Vetter <daniel.vetter@ffwll.ch> writes:
>> 
>> Hi Daniel,
>> 
>>> +    if dst_fname:
>>> +        name = dst_fname[len(out_dir) + 1:]
>>> +        # the builder needs not to copy one more time, so pop it if exists.
>>> +        translator.builder.images.pop(img_node['uri'], None)
>>> +        img_node['uri'] = dst_fname
>>> +        img_node['candidates'] = {'*': dst_fname}
>>> +
>>> +        mkdir(path.dirname(dst_fname))
>>> +
>>> +        if in_ext == '.dot':
>>> +            verbose('convert DOT to: {out}/' + name)
>>> +            dot2format(src_fname, dst_fname)
>>> +
>>> +        elif in_ext == '.svg':
>>> +            verbose('convert SVG to: {out}/' + name)
>>> +            svg2pdf(src_fname, dst_fname)
>> 
>> Small nit, but, shouldn't you add dst_fname to img_node only if
>> dot2format or svg2pdf was successful?
> 
> I kinda assumed they're always successful, since the media documentation
> build already requires them.

SHORT:

At this time (Phase 1: Reading), the internal doctree is build and
with these two lines:

>>> +        img_node['uri'] = dst_fname
>>> +        img_node['candidates'] = {'*': dst_fname}


the image is added as wildcard "*" to the doctree. 

Later (Phase 4: Writing), when the output is generated from
doctree, the (pdf-/html-) builder will search for the best
existing "*" candidate, e.g. "*.svg" for html and "*.pdf"
for LaTeX.

MORE VERBOSE:

To see/understand the whole play we have to know that Sphinx/docutils
has Build Phases: 

* http://www.sphinx-doc.org/en/stable/extdev/tutorial.html#build-phases

"""
Phase 1: Reading
In Phase 1, all source files (and on subsequent builds, those that are new or changed) are read and parsed. This is the phase where directives and roles are encountered by docutils, and the corresponding code is executed. The output of this phase is a doctree for each source file"""
...

Phase 4: Writing
This phase converts the resolved doctrees to the desired output format, such as HTML or LaTeX. This happens via a so-called docutils writer that visits the individual nodes of each doctree and produces some output in the process.
"""

The visitor for handling kernel_image, kernel_render and kernel_figure
directives are analog, so lets look at the simple one::

+def visit_kernel_image(self, node):    # pylint: disable=W0613
+    """Visitor of the ``kernel_image`` Node.
+
+    Handles the ``image`` child-node with the ``convert_image(...)``.
+    """
+    img_node = node[0]
+    convert_image(img_node, self)

this is the visitor, for building the internal doctree. The visitor
calls convert_image() with img_node as first argument.

The convert_image() first evals a new dst_fname for image
types which are covered by:

+    dst_fname     = None
...
+    if in_ext == '.dot':
+        dst_fname = path.join(out_dir, fname + '.pdf')
....
+
+    elif in_ext == '.svg':
+        if translator.builder.format == 'latex':
+            dst_fname = path.join(out_dir, fname + '.pdf')

Consider that dst_fname is always in the out_dir. So, if this image type
is covered by convert_image(), we have to remove the old image from
builder's image-stack (the stack is outside of the node-tree).

+    if dst_fname:
+        name = dst_fname[len(out_dir) + 1:]
+        # the builder needs not to copy one more time, so pop it if exists.
+        translator.builder.images.pop(img_node['uri'], None)
+        img_node['uri'] = dst_fname
+        img_node['candidates'] = {'*': dst_fname}


So you might already guess, this image handling method is bonded
only to Phase 1 and we do not need to touch any builder (Phase 4).
The central point is the last line:

+        img_node['candidates'] = {'*': dst_fname}

The other important thing is, that generated files (dst_fname) are 
always in the out_dir. This is needed, since kernel-build should not
pollute the src_folder. 


@Daniel: Thanks a lot for your:

v2: s/DOC/DOT/ in a few places (by Daniel).
v3: Simplify stuff a bit (by Daniel):

I haven't had time to test and I can't promise that I will
find the time for. So, for the first, take my Acked-by.

--Markus--
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-03-02  8:31 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 17:13 [PATCH 0/6] more kernel-doc patches Daniel Vetter
2017-02-28 17:13 ` [PATCH 1/6] doc: Explain light-handed markup preference a bit better Daniel Vetter
2017-02-28 17:13 ` [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images Daniel Vetter
2017-03-01 15:56   ` Gabriel Krisman Bertazi
2017-03-02  7:12     ` Daniel Vetter
2017-03-02  8:23       ` Markus Heiser [this message]
2017-03-02 12:26   ` Laurent Pinchart
2017-03-02 13:54     ` Daniel Vetter
2017-03-02 14:14       ` Laurent Pinchart
2017-03-02 14:58         ` Markus Heiser
2017-03-02 15:11           ` Daniel Vetter
2017-03-02 15:17             ` Laurent Pinchart
2017-03-02 15:21             ` Markus Heiser
2017-03-02 15:45               ` Mauro Carvalho Chehab
2017-03-02 15:49                 ` Mauro Carvalho Chehab
2017-03-02 16:13                   ` Markus Heiser
2017-03-02 16:29                     ` Mauro Carvalho Chehab
2017-03-02 18:16                       ` Markus Heiser
2017-03-02 18:20                         ` Jonathan Corbet
2017-03-02 18:47                           ` Markus Heiser
2017-03-02 19:09                         ` Mauro Carvalho Chehab
2017-03-02 20:16                           ` Markus Heiser
2017-03-02 20:28                             ` Mauro Carvalho Chehab
2017-03-04 14:56                           ` docutils borkage (was: [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images) Jonathan Corbet
2017-03-05  2:23                             ` Mauro Carvalho Chehab
2017-03-02 15:22             ` [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images Jonathan Corbet
2017-03-02 15:53               ` Daniel Vetter
2017-03-02 16:01                 ` Mauro Carvalho Chehab
2017-03-02 19:49                   ` Daniel Vetter
2017-03-06 10:12   ` Daniel Vetter
2017-03-06 13:13     ` Markus Heiser
2017-03-06 15:03       ` Daniel Vetter
2017-02-28 17:13 ` [PATCH 3/6] drm/doc: Add KMS overview graphs Daniel Vetter
2017-03-01 16:33   ` Gabriel Krisman Bertazi
2017-03-02 14:34   ` Laurent Pinchart
2017-03-02 15:06     ` Daniel Vetter
2017-02-28 17:13 ` [PATCH 4/6] drm/doc: Consistent kerneldoc include order Daniel Vetter
2017-02-28 23:39   ` Eric Anholt
2017-02-28 17:13 ` [PATCH 5/6] drm/doc: diagram for mode objects and properties Daniel Vetter
2017-02-28 23:40   ` Eric Anholt
2017-03-01  8:27   ` [PATCH] " Daniel Vetter
2017-03-01 16:45     ` Gabriel Krisman Bertazi
2017-03-02 14:42     ` Laurent Pinchart
2017-02-28 17:13 ` [PATCH 6/6] drm/doc: atomic overview, with graph Daniel Vetter
2017-02-28 23:48   ` Eric Anholt
2017-03-01  9:57     ` Daniel Vetter
2017-03-01 17:42       ` Gabriel Krisman Bertazi
2017-03-02  7:16         ` Daniel Vetter
2017-03-01  8:35   ` [PATCH] " Daniel Vetter
2017-03-01 17:42     ` Eric Anholt
2017-03-02  7:19     ` Daniel Vetter
2017-03-02 14:41       ` Laurent Pinchart
2017-03-02 15:16 [PATCH 1/6] doc: Explain light-handed markup preference a bit better Daniel Vetter
2017-03-02 15:16 ` [PATCH 2/6] docs-rst: automatically convert Graphviz and SVG images Daniel Vetter
2017-03-02 15:20   ` Laurent Pinchart
2017-03-02 22:15   ` Markus Heiser
2017-03-02 23:19     ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F595B7DD-4BA5-4935-8B4D-37D05EBB8EED@darmarit.de \
    --to=markus.heiser@darmarit.de \
    --cc=corbet@lwn.net \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krisman@collabora.co.uk \
    --cc=linux-doc@vger.kernel.org \
    --cc=mchehab@s-opensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.