linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nícolas F. R. A. Prado" <nfraprado@protonmail.com>
To: corbet@lwn.net
Cc: linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	masahiroy@kernel.org, mchehab+huawei@kernel.org,
	mchehab@kernel.org, michal.lkml@markovi.net
Subject: Re: [PATCH RFC v2] docs: experimental: build PDF with rst2pdf
Date: Mon, 28 Dec 2020 17:19:18 +0000	[thread overview]
Message-ID: <20201228171907.159028-1-nfraprado@protonmail.com> (raw)

On Fri, Dec 11, 2020 at 05:03:50PM -0700, Jonathan Corbet wrote:
> The right solution is probably something like this:
> 
> 	try:
> 	    import rst2pdf
> 	    extensions.append('rst2pdf.pdfbuilder')
> 	except ModuleNotFoundError:
> 	    pass # no rst2pdf for you

I tested it, but it still fails, and the error message is even more cryptic:

	Sphinx error:
	Builder name pdf not registered or available through entry point
	make[1]: *** [Documentation/Makefile:120: rst2pdf] Error 2
	make: *** [Makefile:1663: rst2pdf] Error 2

It seems to me that the missing dependency should be treated in the Makefile
target rather than in Sphinx. Looking through the Makefile, I took inspiration
from the latex version and did the following:

	HAVE_RST2PDF := $(shell if python -c "import rst2pdf" >/dev/null 2>&1; then echo 1; else echo 0; fi)

	 
	ifeq ($(HAVE_RST2PDF),0)

	rst2pdf:
	       $(warning The 'rst2pdf' python module was not found. Make sure you have it installed to produce PDF output.)
	       @echo "  SKIP    Sphinx $@ target."

	else # HAVE_RST2PDF

	rst2pdf:
	       @$(srctree)/scripts/sphinx-pre-install --version-check
	       @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,pdf,$(var),pdf,$(var)))

	endif # HAVE_RST2PDF

With this, the following message is shown in case it isn't installed:

	Documentation/Makefile:122: The 'rst2pdf' python module was not found. Make sure you have it installed to produce PDF output.
	  SKIP    Sphinx rst2pdf target.

But with that check on the Makefile in place, on the Sphinx side, we can indeed
just do Jon's snippet to only add the extension if it is installed. Another
option would be to split the 'try' into 'try' and 'else', where the 'else' only
executes if the 'try' is succesful. The benefit is that this makes it clearer
that only the import is being "tried":

	# Enable experimental rst2pdf, if available
	try:
	    import rst2pdf
	except ModuleNotFoundError:
	    pass
	else:
	    extensions.append("rst2pdf.pdfbuilder")

Something interesting I noticed is that when building with Sphinx 3, and if
rst2pdf is installed, even when building other targets, like htmldocs, (since
the rst2pdf extension is added based on rst2pdf being installed and not if it is
being used) the following is printed:

	WARNING: the rst2pdf.pdfbuilder extension is not safe for parallel writing
	WARNING: doing serial write

Looking into rst2pdf's pdfbuilder.py, indeed 'parallel_write_safe' is False, so
we should probably make sure rst2pdf isn't negatively impacting build time for
other formats before merging this patch.

Thanks,
Nícolas


             reply	other threads:[~2020-12-28 17:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 17:19 Nícolas F. R. A. Prado [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-12-10 16:29 [PATCH RFC] docs: experimental: build PDF with rst2pdf Mauro Carvalho Chehab
2020-12-11  8:33 ` [PATCH RFC v2] " Mauro Carvalho Chehab
2020-12-11 20:48   ` Jonathan Corbet
2020-12-11 23:54     ` Mauro Carvalho Chehab
2020-12-12  0:03       ` Jonathan Corbet

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=20201228171907.159028-1-nfraprado@protonmail.com \
    --to=nfraprado@protonmail.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=mchehab@kernel.org \
    --cc=michal.lkml@markovi.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).