Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9458499pxu; Mon, 28 Dec 2020 17:17:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCUcTt4DKC1MWNdYrt/r5rdweHTtIhw45IL7ZhfCDb1XuMfL8qcXTfcj5AFDwyL/YWfiXU X-Received: by 2002:a17:906:8152:: with SMTP id z18mr45076343ejw.317.1609204628541; Mon, 28 Dec 2020 17:17:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609204628; cv=none; d=google.com; s=arc-20160816; b=VLIoIHKRPu5BkTDdZ4mlXjpgtg4zMiZ5ZBR8sN+0aek1lTXAnBIhAXjx815seR086D HHJHgb+P2aXjFHO0BqD5d0KrTf/OZo0X0QD8rFEyfrmW0Qp2+4BsHSOrx4p+swmHJXg1 J74m8zAOc8GdOAFcyfG75DmSkVLNZ3O/cX7QaNrWsqHNFhXxv6C+FQkEiFvksXP74I9G MhomArCrlmwfVTPcmOAdU6dPIAy00XMbG1hCa68V8icvTKBMn8+fQW6IbFfnbcjEaQT/ JyIhrlaZTYv+0Bx4w7va26XsVrwJwXRYQbvD2YmVJF0bSgyUZ9BhbooEuV0ZGdWz/DTH Uh2A== 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 :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=leLQ7HLOOBAi96gGzZ6lvQ1zwU5ypDUPyx8uomLDoZU=; b=GgkyIM9MhgzOSqW9rVLyaU+7DpslAhkd2ePJOAWG+z+p16eB26+sRFetEvA1JQD1X4 8mxEsDTVngRZ2q6wyj8Sc1wn5mZ3USFBXnnEZLAJbC9YjT4OR5trdxy8e8cOeyF00R84 AkaR4nIn4xYK8zrGsEZvwLCtRw+wsJBSZnVzDrXVEhiN+GidCVfgKISrT4Ora9lPWjNC sqyN9Q8z5//OU5IqDDqQG5o/WNo41j8G92oYSt+zpbRDVo3KonbM+fM6QgvD1h8wZhUR uwQ05It3BJHWVQIJAUURDIv3nVyC59tslvhfKHMW9EqopGY+bOsae3oPzzPVEm4YfmxC uTDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=owzcvxZo; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y90si21677420edy.314.2020.12.28.17.16.46; Mon, 28 Dec 2020 17:17:08 -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=@protonmail.com header.s=protonmail header.b=owzcvxZo; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728150AbgL1RUI (ORCPT + 99 others); Mon, 28 Dec 2020 12:20:08 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:19452 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728135AbgL1RUI (ORCPT ); Mon, 28 Dec 2020 12:20:08 -0500 Date: Mon, 28 Dec 2020 17:19:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1609175964; bh=leLQ7HLOOBAi96gGzZ6lvQ1zwU5ypDUPyx8uomLDoZU=; h=Date:To:From:Cc:Reply-To:Subject:From; b=owzcvxZoYmH6GH6qBht0MRdwycosO+m3EClz9L2BwFJ6YUKGyav9wa+6bTOWNxVOj zLNFA2FnmwvyibgCn2XXc8jvK0dPbxhqc2KICloFMk7ETmoGMEamdbsD3OWZrtkJK9 TM5DR3BH52g27kH0uGavOJyIJiekVnf0KkDfH2p8= To: corbet@lwn.net From: =?utf-8?Q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= 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 Reply-To: =?utf-8?Q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Subject: Re: [PATCH RFC v2] docs: experimental: build PDF with rst2pdf Message-ID: <20201228171907.159028-1-nfraprado@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 11, 2020 at 05:03:50PM -0700, Jonathan Corbet wrote: > The right solution is probably something like this: >=20 > =09try: > =09 import rst2pdf > =09 extensions.append('rst2pdf.pdfbuilder') > =09except ModuleNotFoundError: > =09 pass # no rst2pdf for you I tested it, but it still fails, and the error message is even more cryptic= : =09Sphinx error: =09Builder name pdf not registered or available through entry point =09make[1]: *** [Documentation/Makefile:120: rst2pdf] Error 2 =09make: *** [Makefile:1663: rst2pdf] Error 2 It seems to me that the missing dependency should be treated in the Makefil= e target rather than in Sphinx. Looking through the Makefile, I took inspirat= ion from the latex version and did the following: =09HAVE_RST2PDF :=3D $(shell if python -c "import rst2pdf" >/dev/null 2>&1;= then echo 1; else echo 0; fi) =09=20 =09ifeq ($(HAVE_RST2PDF),0) =09rst2pdf: =09 $(warning The 'rst2pdf' python module was not found. Make sure yo= u have it installed to produce PDF output.) =09 @echo " SKIP Sphinx $@ target." =09else # HAVE_RST2PDF =09rst2pdf: =09 @$(srctree)/scripts/sphinx-pre-install --version-check =09 @+$(foreach var,$(SPHINXDIRS),$(call loop_cmd,sphinx,pdf,$(var),p= df,$(var))) =09endif # HAVE_RST2PDF With this, the following message is shown in case it isn't installed: =09Documentation/Makefile:122: The 'rst2pdf' python module was not found. M= ake sure you have it installed to produce PDF output. =09 SKIP Sphinx rst2pdf target. But with that check on the Makefile in place, on the Sphinx side, we can in= deed 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 clear= er that only the import is being "tried": =09# Enable experimental rst2pdf, if available =09try: =09 import rst2pdf =09except ModuleNotFoundError: =09 pass =09else: =09 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, (sin= ce the rst2pdf extension is added based on rst2pdf being installed and not if = it is being used) the following is printed: =09WARNING: the rst2pdf.pdfbuilder extension is not safe for parallel writi= ng =09WARNING: 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=C3=ADcolas