From: Jonathan Corbet <corbet@lwn.net>
To: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
Masahiro Yamada <masahiroy@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Michal Marek <michal.lkml@markovi.net>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org
Subject: Re: [PATCH RFC v2] docs: experimental: build PDF with rst2pdf
Date: Fri, 11 Dec 2020 17:03:50 -0700 [thread overview]
Message-ID: <20201211170350.4f27ad8d@lwn.net> (raw)
In-Reply-To: <20201212005435.0e1a0871@coco.lan>
On Sat, 12 Dec 2020 00:54:35 +0100
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:
> I'm not an usual python programmer, so, don't know much about its
> specifics... Yet, I would be expecting that something like this:
>
> try:
> extensions.append("rst2pdf.pdfbuilder")
> except:
> sys.stderr.write('rst2pdf extension not available.\n')
>
>
> Would avoid it to crash, if the extension is not available.
> Silly me :-)
No, that's not going to do it, for a couple of reasons. First being that
all it's doing is appending a string to a list, which pretty much always
succeeds. The attempt to actually import the module happens later.
...and you won't catch that either because it isn't actually throwing an
exception, it's just noting the problem and giving up.
The right solution is probably something like this:
try:
import rst2pdf
extensions.append('rst2pdf.pdfbuilder')
except ModuleNotFoundError:
pass # no rst2pdf for you
This is totally untested, of course.
[Incidentally, a blank "except:" clause like the one you had is, in my
experience, a bad idea. That will catch *anything*, leading to hiding all
kinds of bugs. Not that I've ever committed such a faux pas and suffered
the consequences myself...no...never...honest...]
I'll mess with this a bit more later.
Thanks,
jon
next prev parent reply other threads:[~2020-12-12 1:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-10 10:55 [PATCH 00/13] Address issues with PDF output at media uAPI docs Mauro Carvalho Chehab
2020-12-10 10:55 ` [PATCH 01/13] docs: conf.py: fix sphinx version detection for margin set Mauro Carvalho Chehab
2020-12-10 14:48 ` Jonathan Corbet
2020-12-10 16:01 ` [PATCH RFC] docs: experimental: build PDF with rst2pdf Mauro Carvalho Chehab
2020-12-10 16:29 ` 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 [this message]
2020-12-10 16:03 ` [PATCH 01/13] docs: conf.py: fix sphinx version detection for margin set Mauro Carvalho Chehab
-- strict thread matches above, loose matches on Subject: below --
2020-12-28 17:19 [PATCH RFC v2] docs: experimental: build PDF with rst2pdf Nícolas F. R. A. Prado
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=20201211170350.4f27ad8d@lwn.net \
--to=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).