Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2124439pxu; Sun, 13 Dec 2020 14:39:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwE/ddsV176BjhjbCvq/AGAY7VyKbc9OdFIIth2NEs0Los3cGqUQKprsgHZJLGV8ZoyuMwC X-Received: by 2002:a17:906:8354:: with SMTP id b20mr20184572ejy.397.1607899194050; Sun, 13 Dec 2020 14:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607899194; cv=none; d=google.com; s=arc-20160816; b=lb0TYENPJnrqFzrh5xoVpwOQg7VYA8fVXnpIkHfyTOosKSmmfwRtHti3gEA1n3Mb2S xXyz7kECWcKb/pxoY4KgVG5nVF8fUQI6fN8prGyGLklxWNEAOveF9mccWsk+MMQ9QZwy tXAUbTx+TyZDZwtdblACWglRdsyLrU+Aqtl31DgggJhNd4q8KgF0/fKBZx366Wdsu57S uXqpPwXUNPysxBYjyHGZ7239fcLwZdbEduyAH3JFfW+kEfAbvpakDWi5NY3pOnydHMuM 2sdkO5U2X8rfT4XZZov+8f1p218tPR1Rp/yMHdIWnrcnJEPQ/LEPlfI3E5G9PpXIu36E Znqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature:dkim-filter; bh=o++ZPZqcqfuEVZJsJirVpVOijN/mx4tZnsSRtY15qIk=; b=MjJK7EUvF0mqin6s50vaHpXaqrYiG+rpTlVaCwerd/Ez5BPhQW0jfM9xtwUcOM1O9I B1n/fnuSJZ/9tC3Se0gXrxs6igXiAOtWkyBhActx6AGWzvjeqK53M93bFNUQjcCAfEQ0 6m3wZRNdMkAkvi0smjaRW3jZrPSg3L3Z02E6Gw0LtqD1MFSzuosuscIjsCqcJhvB0PWs dLDWS8+9fBvNI4dKObcLvmN9QX1FLbH76ZkNoeF9PwoVterq4Zs7eXxfLSyk3Dziak6Y 603mww/bIua/JAAB+rxjREiqiIghLyVJZXBOrcCT+1fMnCQCvSO/o/lPTDKp0s7yQAuZ SFdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=qBh0TvjL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si5636577edo.323.2020.12.13.14.39.17; Sun, 13 Dec 2020 14:39:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=qBh0TvjL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404698AbgLLAEo (ORCPT + 99 others); Fri, 11 Dec 2020 19:04:44 -0500 Received: from ms.lwn.net ([45.79.88.28]:48070 "EHLO ms.lwn.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393137AbgLLAEc (ORCPT ); Fri, 11 Dec 2020 19:04:32 -0500 X-Greylist: delayed 11692 seconds by postgrey-1.27 at vger.kernel.org; Fri, 11 Dec 2020 19:04:32 EST Received: from lwn.net (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id B39E67C0; Sat, 12 Dec 2020 00:03:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net B39E67C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1607731432; bh=o++ZPZqcqfuEVZJsJirVpVOijN/mx4tZnsSRtY15qIk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qBh0TvjL2YDOaZBh9ywPwJCPKqhfTLFImC/0QxbXsfldcSbB/waTdnk2GRSV7JqWC 6Sz1G8nL8rGZMDCI1aE6iEjsM6rdnmfkPojETyrSKina6bX00opP9MqIGIsUHXl2gj MgWv+LzF913n+ZzFPJ+f+mRA6SmPZESH8iKSrGyv02Ew2TxlXh91/6x0PE3OM8Q0f+ W2iiM+WgTqRdMiihOq/V6x0WfvEbfEo3VGnyYqD+UFkn+v+Jwu+PpqRGOiu0wWJ953 Qj/9UrT+WXrLzJBBbRAlTFftCl9v13x+x3bKKlWWIPufSRHuFGDeGG55oLsTp1mLlr PF0Hkf3Nb9Q5w== Date: Fri, 11 Dec 2020 17:03:50 -0700 From: Jonathan Corbet To: Mauro Carvalho Chehab Cc: Linux Doc Mailing List , Masahiro Yamada , Mauro Carvalho Chehab , Michal Marek , 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 Message-ID: <20201211170350.4f27ad8d@lwn.net> In-Reply-To: <20201212005435.0e1a0871@coco.lan> References: <20201210172938.3b3086b6@coco.lan> <20201211134859.5ab8e0c2@lwn.net> <20201212005435.0e1a0871@coco.lan> Organization: LWN.net MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 12 Dec 2020 00:54:35 +0100 Mauro Carvalho Chehab 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