GNU bug report logs - #53548
[PATCH] Harden beautify-description

Previous Next

Package: guix-patches;

Reported by: Alice BRENON <alice.brenon <at> ens-lyon.fr>

Date: Wed, 26 Jan 2022 09:42:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 53548 in the body.
You can then email your comments to 53548 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#53548; Package guix-patches. (Wed, 26 Jan 2022 09:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alice BRENON <alice.brenon <at> ens-lyon.fr>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 26 Jan 2022 09:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alice BRENON <alice.brenon <at> ens-lyon.fr>
To: guix-patches <at> gnu.org
Cc: Julien Lepiller <julien <at> lepiller.eu>, Xinglu Chen <public <at> yoctocell.xyz>
Subject: [PATCH] Harden beautify-description
Date: Wed, 26 Jan 2022 10:41:39 +0100
[Message part 1 (text/plain, inline)]
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
[0001-guix-import-Harden-beautify-description.patch (text/x-patch, attachment)]

Information forwarded to guix-patches <at> gnu.org:
bug#53548; Package guix-patches. (Mon, 31 Jan 2022 23:10:02 GMT) Full text and rfc822 format available.

Message #8 received at 53548 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Alice BRENON <alice.brenon <at> ens-lyon.fr>
Cc: 53548 <at> debbugs.gnu.org, Xinglu Chen <public <at> yoctocell.xyz>,
 Julien Lepiller <julien <at> lepiller.eu>
Subject: Re: bug#53548: [PATCH] Harden beautify-description
Date: Tue, 01 Feb 2022 00:09:40 +0100
Hi Alice,

Alice BRENON <alice.brenon <at> ens-lyon.fr> skribis:

> 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).

Thanks for explaining!  Some comments:

> From 22f0523ef3599b45af9448bd4f31f7b8f8ce6af2 Mon Sep 17 00:00:00 2001
> From: Alice BRENON <alice.brenon <at> ens-lyon.fr>
> 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).

[...]

>    #: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))

It can’t hurt.

> +                  ((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)))

I’d avoid the URL and maybe make the string translatable, like so:

  (G_ "This package lacks a description …
Run \"info '(guix) Synopses and Descriptions'\" for more information.")

… where ‘G_’ comes from (guix i18n).

WDYT?

This looks like a welcome improvement to me.

Thanks!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#53548; Package guix-patches. (Wed, 02 Feb 2022 15:38:02 GMT) Full text and rfc822 format available.

Message #11 received at 53548 <at> debbugs.gnu.org (full text, mbox):

From: Alice BRENON <alice.brenon <at> ens-lyon.fr>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 53548 <at> debbugs.gnu.org, Xinglu Chen <public <at> yoctocell.xyz>,
 Julien Lepiller <julien <at> lepiller.eu>
Subject: Re: bug#53548: [PATCH] Harden beautify-description
Date: Wed, 2 Feb 2022 16:37:31 +0100
[Message part 1 (text/plain, inline)]
Hi !

Thank you again for the help. I think it looks really better with the
translated reference to the info page. I feared the issues I raised
would yield unending discussions but actually with your edit it's
already pretty neat while remaining very simple. That's inspiring.

For the others interested in this thread, I also made the import of G_
from (guix i18n) explicit because it was being re-exported from (guix
ui), and while I was at it, I made the only used import from (guix ui),
that is fill-paragraph, explicit.

Hope you like this second version better : )

Alice


Le Tue, 01 Feb 2022 00:09:40 +0100,
Ludovic Courtès <ludo <at> gnu.org> a écrit :

> Hi Alice,
> 
> Alice BRENON <alice.brenon <at> ens-lyon.fr> skribis:
> 
> > 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).  
> 
> Thanks for explaining!  Some comments:
> 
> > From 22f0523ef3599b45af9448bd4f31f7b8f8ce6af2 Mon Sep 17 00:00:00
> > 2001 From: Alice BRENON <alice.brenon <at> ens-lyon.fr>
> > 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).  
> 
> [...]
> 
> >    #: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))  
> 
> It can’t hurt.
> 
> > +                  ((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)))  
> 
> I’d avoid the URL and maybe make the string translatable, like so:
> 
>   (G_ "This package lacks a description …
> Run \"info '(guix) Synopses and Descriptions'\" for more
> information.")
> 
> … where ‘G_’ comes from (guix i18n).
> 
> WDYT?
> 
> This looks like a welcome improvement to me.
> 
> Thanks!
> 
> Ludo’.

[0001-guix-import-Harden-beautify-description.patch (text/x-patch, attachment)]

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Tue, 08 Feb 2022 09:53:02 GMT) Full text and rfc822 format available.

Notification sent to Alice BRENON <alice.brenon <at> ens-lyon.fr>:
bug acknowledged by developer. (Tue, 08 Feb 2022 09:53:02 GMT) Full text and rfc822 format available.

Message #16 received at 53548-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Alice BRENON <alice.brenon <at> ens-lyon.fr>
Cc: 53548-done <at> debbugs.gnu.org, Xinglu Chen <public <at> yoctocell.xyz>,
 Julien Lepiller <julien <at> lepiller.eu>
Subject: Re: bug#53548: [PATCH] Harden beautify-description
Date: Tue, 08 Feb 2022 10:51:51 +0100
[Message part 1 (text/plain, inline)]
Hi!

Alice BRENON <alice.brenon <at> ens-lyon.fr> skribis:

> From cfb57a40a90bfc31d1b846f3e981469285f1bd7b Mon Sep 17 00:00:00 2001
> From: Alice BRENON <alice.brenon <at> ens-lyon.fr>
> 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.
> [use-modules]: Explicitly import G_ from (guix i18n) and make (guix ui)
> import explicit.
> * guix/import/opam.scm: [use-modules] Make imports explicit for module
> (guix import utils).

Applied.

I removed extra space from the message, as shown below.

Thanks!

Ludo’.

[Message part 2 (text/x-patch, inline)]
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 934b224bec..9cadbb3d5f 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -244,8 +244,8 @@ (define* (beautify-description description #:optional (length 80))
 LENGTH characters."
   (let ((cleaned (cond
                   ((not (string? description))
-                   (G_ "This package lacks a description.  Run \"info '(guix)
-                       Synopses and Descriptions'\" for more information."))
+                   (G_ "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."))
                   ((string-prefix? "A " description)
                    (string-append "This package provides a"
                                   (substring description 1)))

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 08 Mar 2022 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 101 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.