From patchwork Wed Jan 26 09:41:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alice BRENON X-Patchwork-Id: 36819 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 81A4627BBEA; Wed, 26 Jan 2022 09:42:13 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id EB1FF27BBE9 for ; Wed, 26 Jan 2022 09:42:12 +0000 (GMT) Received: from localhost ([::1]:54596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCeod-0005m8-Vz for patchwork@mira.cbaines.net; Wed, 26 Jan 2022 04:42:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCeoV-0005lZ-87 for guix-patches@gnu.org; Wed, 26 Jan 2022 04:42:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:58080) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nCeoU-000338-68 for guix-patches@gnu.org; Wed, 26 Jan 2022 04:42:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nCeoU-0007GC-2U for guix-patches@gnu.org; Wed, 26 Jan 2022 04:42:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53548] [PATCH] Harden beautify-description Resent-From: Alice BRENON Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 26 Jan 2022 09:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53548 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53548@debbugs.gnu.org Cc: Julien Lepiller , Xinglu Chen X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.164319011327893 (code B ref -1); Wed, 26 Jan 2022 09:42:01 +0000 Received: (at submit) by debbugs.gnu.org; 26 Jan 2022 09:41:53 +0000 Received: from localhost ([127.0.0.1]:50983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCeoG-0007Fj-SJ for submit@debbugs.gnu.org; Wed, 26 Jan 2022 04:41:53 -0500 Received: from lists.gnu.org ([209.51.188.17]:56686) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nCeoE-0007Fb-Qn for submit@debbugs.gnu.org; Wed, 26 Jan 2022 04:41:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCeoE-0005fU-Hb for guix-patches@gnu.org; Wed, 26 Jan 2022 04:41:46 -0500 Received: from lxc-smtp2.ens-lyon.fr ([140.77.167.81]:47308) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nCeoC-00032D-Er for guix-patches@gnu.org; Wed, 26 Jan 2022 04:41:46 -0500 Received: from localhost (localhost [127.0.0.1]) by lxc-smtp2.ens-lyon.fr (Postfix) with ESMTP id 9D9E1E2CDE; Wed, 26 Jan 2022 10:41:40 +0100 (CET) X-Virus-Scanned: by amavisd-new-2.11.0 (20160426) (Debian) at ens-lyon.fr Received: from lxc-smtp2.ens-lyon.fr ([127.0.0.1]) by localhost (lxc-smtp2.ens-lyon.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Rq6n6D1-2U2q; Wed, 26 Jan 2022 10:41:40 +0100 (CET) Received: from localhost (unknown [193.52.208.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by lxc-smtp2.ens-lyon.fr (Postfix) with ESMTPSA id 28FB3E2B7B; Wed, 26 Jan 2022 10:41:40 +0100 (CET) Date: Wed, 26 Jan 2022 10:41:39 +0100 From: Alice BRENON Message-ID: <20220126104139.17df3cbb@ens-lyon.fr> Organization: ENS de Lyon X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=140.77.167.81; envelope-from=alice.brenon@ens-lyon.fr; helo=lxc-smtp2.ens-lyon.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi all, Missing metadata in packages used to break their imports, at least for opam packages, until this was fixed by Julien in 24aa7b3c21309b63cc6e8e18d6417d2cddccf6c6. When Xinglu improved the output of descriptions in 155fc235b5e1b41b4665c782365dd2bf11beae9c, it made the imports break again in the case when the `description` field is missing and Julien's fix applies, returning #f in `metadata-ref` instead of crashing. Trouble is: beautify-description expects its description argument to be a string and will crash if this assumption isn't met (when calling the `string-prefix?` predicate). This patch hopes to fix this by prepending a catch-all case in `beautify-description` to intercept all calls to it without a proper string as description. In addition, since I had to search for beautify-description in all the code base I made its import from opam.scm explicit, to carry on what I think is a good practice which I would like to see progressively enforced in guix' source code: explicit imports everywhere, to prevent accidental namespace collisions and to ease source code browsing by pointing out where everything comes from in a given source file. This patch can probably not be pushed as-is and should be improved first: - In the generated description, I think it'd be useful to point the user to the documentation page helping them to understand what is expected in a good description, so I generated a link to it on the web-hosted manual. However, this choice is arbitrary: why not an info page or the PDF ? Is there an consensus on how to refer to a page in the documentation in guix's output ? If not and we stick to the web, perhaps the `home-url` and `doc-path` variable could be declared outside of (guix import utils), perhaps turned into functions and localized to the user's preference instead of the built-in english version I used. - If all-explict use-modules policy is relevant, it should be applied to the other import modules that Xinglu edited in 155fc23. If not, then my change in guix/import/opam.scm should perhaps not be applied at all. Thanks for your feedback on this proposal ! Best regards, Alice From 22f0523ef3599b45af9448bd4f31f7b8f8ce6af2 Mon Sep 17 00:00:00 2001 From: Alice BRENON Date: Wed, 26 Jan 2022 09:27:12 +0100 Subject: [PATCH] guix: import: Harden beautify-description. * guix/import/utils.scm (beautify-description): Handle non-string arguments. * guix/import/opam.scm: [use-modules] Make imports explicit for module (guix import utils). --- guix/import/opam.scm | 8 ++++++-- guix/import/utils.scm | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/guix/import/opam.scm b/guix/import/opam.scm index a6f6fe8c9f..f569c921b1 100644 --- a/guix/import/opam.scm +++ b/guix/import/opam.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2020 Martin Becze ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2021 Sarah Morgensen -;;; Copyright © 2021 Alice Brenon +;;; Copyright © 2021, 2022 Alice Brenon ;;; ;;; This file is part of GNU Guix. ;;; @@ -42,7 +42,11 @@ (define-module (guix import opam) #:use-module ((guix utils) #:select (cache-directory version>? call-with-temporary-output-file)) - #:use-module (guix import utils) + #:use-module ((guix import utils) #:select (beautify-description + guix-hash-url + recursive-import + spdx-string->license + url-fetch)) #:use-module ((guix licenses) #:prefix license:) #:export (opam->guix-package opam-recursive-import diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 1c3cfa3e0b..cd716e3dc7 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -10,6 +10,7 @@ ;;; Copyright © 2021 Maxim Cournoyer ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Alice Brenon ;;; ;;; This file is part of GNU Guix. ;;; @@ -241,6 +242,15 @@ (define* (beautify-description description #:optional (length 80)) a proper sentence and by using two spaces between sentences, and wrap lines at LENGTH characters." (let ((cleaned (cond + ((not (string? description)) + (let ((home-url "https://guix.gnu.org/") + (doc-path "fr/manual/devel/en/html_node/") + (page + "Synopses-and-Descriptions.html#Synopses-and-Descriptions")) + (string-append + "Please fill in the description of your package before " + "submitting ! See " + home-url doc-path page))) ((string-prefix? "A " description) (string-append "This package provides a" (substring description 1))) -- 2.34.0