Re: [PATCH RFC v2] docs: experimental: build PDF with rst2pdf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 12 Dec 2020 00:54:35 +0100
Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx> 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



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux