all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages
@ 2021-11-03 10:17 Xinglu Chen
  2021-11-03 10:19 ` [bug#51581] [PATCH 1/2] import: utils: Add ‘wrap-lines’ procedure Xinglu Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-11-03 10:17 UTC (permalink / raw)
  To: 51581

[-- Attachment #1: Type: text/plain, Size: 2316 bytes --]

This series adds a ‘wrap-lines’ procedure which wraps the line in a
string, similar to ‘fill-paragraph’ in Emacs.  This is used to chop the
description of imported packages into multiple lines, instead of just
having one really long line.

Before:

--8<---------------cut here---------------start------------->8---
(description
    "Hakyll is a static website compiler library. It provides you with the tools to create a simple or advanced static website using a Haskell DSL and formats such as markdown or RST. You can find more information, including a tutorial, on the website: . * <http://jaspervdj.be/hakyll> . If you seek assistance, there's: . * A google group: <http://groups.google.com/group/hakyll> . * An IRC channel, @#hakyll@ on irc.libera.chat (we *do not* have a channel on Freenode anymore) . Additionally, there's the Haddock documentation in the different modules, meant as a reference.")
--8<---------------cut here---------------end--------------->8---

After:

--8<---------------cut here---------------start------------->8---
(description
    "Hakyll is a static website compiler library. It provides you with the tools to
create a simple or advanced static website using a Haskell DSL and formats such
as markdown or RST. You can find more information, including a tutorial, on the
website: . * <http://jaspervdj.be/hakyll> . If you seek assistance, there's: . *
A google group: <http://groups.google.com/group/hakyll> . * An IRC channel,
@#hakyll@ on irc.libera.chat (we *do not* have a channel on Freenode anymore) .
Additionally, there's the Haddock documentation in the different modules, meant as
a reference.")
--8<---------------cut here---------------end--------------->8---


Xinglu Chen (2):
  import: utils: Add ‘wrap-lines’ procedure.
  import: Beautify descriptions when appropriate.

 guix/import/elpa.scm     |  2 +-
 guix/import/gnu.scm      |  3 ++-
 guix/import/hackage.scm  |  4 ++--
 guix/import/minetest.scm |  2 +-
 guix/import/opam.scm     |  3 ++-
 guix/import/pypi.scm     |  2 +-
 guix/import/utils.scm    | 36 +++++++++++++++++++++++++++++++-----
 tests/import-utils.scm   |  5 +++++
 8 files changed, 45 insertions(+), 12 deletions(-)


base-commit: 0e19713c1fbfd3a01347e0d490434a53a596ed3c
-- 
2.33.0




[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#51581] [PATCH 1/2] import: utils: Add ‘wrap-lines’ procedure.
  2021-11-03 10:17 [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Xinglu Chen
@ 2021-11-03 10:19 ` Xinglu Chen
  2021-11-03 10:19 ` [bug#51581] [PATCH 2/2] import: Beautify descriptions when appropriate Xinglu Chen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-11-03 10:19 UTC (permalink / raw)
  To: 51581

* guix/import/utils.scm (wrap-lines): New procedure.
(beautify-description): Use it; add optional ‘length’ argument.
* tests/import-utils.scm ("wrap-lines: 80 characters"): Test it.
---
 guix/import/utils.scm  | 36 +++++++++++++++++++++++++++++++-----
 tests/import-utils.scm |  5 +++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index a180742ca3..103ec2ffe1 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
 ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -66,6 +67,7 @@ (define-module (guix import utils)
             license->symbol
 
             snake-case
+            wrap-lines
             beautify-description
 
             alist->package
@@ -231,9 +233,32 @@ (define (snake-case str)
 with dashes."
   (string-join (string-split (string-downcase str) #\_) "-"))
 
-(define (beautify-description description)
-  "Improve the package DESCRIPTION by turning a beginning sentence fragment
-into a proper sentence and by using two spaces between sentences."
+(define* (wrap-lines str #:optional (length 80))
+  "Given a string STR, wrap lines at LENGTH characters"
+  (define (aux str acc counter)
+    (cond
+     ((string-null? str) acc)
+     ((and (not (= (string-length acc) 0))
+           (= (modulo (string-length acc) length) 0)
+           (not (= counter 1)))
+      (let ((before (substring acc 0 (- counter 1)))
+            (after (substring acc counter)))
+        (aux str (string-append before "\n" after) 1)))
+     ((char=? (string-ref str 0) #\space)
+      (aux (substring str 1)
+           (string-append acc (char-set->string (char-set (string-ref str 0))))
+           (+ (string-length acc) 1)))
+     (else
+      (aux (substring str 1)
+           (string-append acc (char-set->string (char-set (string-ref str 0))))
+           counter))))
+
+  (aux str "" 1))
+
+(define* (beautify-description description #:optional (length 80))
+  "Improve the package DESCRIPTION by turning a beginning sentence fragment into
+a proper sentence and by using two spaces between sentences, and wrap lines at
+LENGTH characters."
   (let ((cleaned (cond
                   ((string-prefix? "A " description)
                    (string-append "This package provides a"
@@ -248,8 +273,9 @@ (define (beautify-description description)
                                              (string-length "Functions"))))
                   (else description))))
     ;; Use double spacing between sentences
-    (regexp-substitute/global #f "\\. \\b"
-                              cleaned 'pre ".  " 'post)))
+    (wrap-lines (regexp-substitute/global #f "\\. \\b"
+                                          cleaned 'pre ".  " 'post)
+                length)))
 
 (define* (package-names->package-inputs names #:optional (output #f))
   "Given a list of PACKAGE-NAMES or (PACKAGE-NAME VERSION) pairs, and an
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 7c6c782917..c6790f624a 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
 ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -31,6 +32,10 @@ (define-module (test-import-utils)
 
 (test-begin "import-utils")
 
+(test-equal "wrap-lines: 80 characters"
+  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua."
+  (wrap-lines "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."))
+
 (test-equal "beautify-description: use double spacing"
   "This is a package.  It is great.  Trust me Mr.  Hendrix."
   (beautify-description
-- 
2.33.0







^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [bug#51581] [PATCH 2/2] import: Beautify descriptions when appropriate.
  2021-11-03 10:17 [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Xinglu Chen
  2021-11-03 10:19 ` [bug#51581] [PATCH 1/2] import: utils: Add ‘wrap-lines’ procedure Xinglu Chen
@ 2021-11-03 10:19 ` Xinglu Chen
  2021-11-12 22:44 ` [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Ludovic Courtès
       [not found] ` <cover.1639735009.git.public@yoctocell.xyz>
  3 siblings, 0 replies; 6+ messages in thread
From: Xinglu Chen @ 2021-11-03 10:19 UTC (permalink / raw)
  To: 51581

* guix/import/elpa.scm (elpa-package->sexp)
* guix/import/gnu.scm (gnu-package->sexp)
* guix/import/hackage.scm (hackage-module->sexp)
* guix/import/minetest.scm (make-minetest-sexp)
* guix/import/opam.scm (opam->guix-package)
* guix/import/pypi.scm (make-pypi-sexp): Beautify descriptions.
---
 guix/import/elpa.scm     | 2 +-
 guix/import/gnu.scm      | 3 ++-
 guix/import/hackage.scm  | 4 ++--
 guix/import/minetest.scm | 2 +-
 guix/import/opam.scm     | 3 ++-
 guix/import/pypi.scm     | 2 +-
 6 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm
index 96ebc17af1..8daa77bfcd 100644
--- a/guix/import/elpa.scm
+++ b/guix/import/elpa.scm
@@ -390,7 +390,7 @@ (define melpa-source
             '())
       (home-page ,(elpa-package-home-page pkg))
       (synopsis ,(elpa-package-synopsis pkg))
-      (description ,(elpa-package-description pkg))
+      (description ,(beautify-description (elpa-package-description pkg)))
       (license ,license))
    dependencies-names))
 
diff --git a/guix/import/gnu.scm b/guix/import/gnu.scm
index 51d5b77d34..2b9b71feb0 100644
--- a/guix/import/gnu.scm
+++ b/guix/import/gnu.scm
@@ -100,7 +100,8 @@ (define sig-url
                         (file-sha256 tarball))))))
           (build-system gnu-build-system)
           (synopsis ,(gnu-package-doc-summary package))
-          (description ,(gnu-package-doc-description package))
+          (description ,(beautify-description
+                         (gnu-package-doc-description package)))
           (home-page ,(match (gnu-package-doc-urls package)
                         ((head . tail) (qualified-url head))))
           (license find-by-yourself!)))
diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm
index 03881f1a3d..95955e27a0 100644
--- a/guix/import/hackage.scm
+++ b/guix/import/hackage.scm
@@ -32,7 +32,7 @@ (define-module (guix import hackage)
   #:use-module ((guix utils) #:select (package-name->name+version
                                        canonical-newline-port))
   #:use-module (guix http-client)
-  #:use-module ((guix import utils) #:select (factorize-uri recursive-import))
+  #:use-module (guix import utils)
   #:use-module (guix import cabal)
   #:use-module (guix store)
   #:use-module (gcrypt hash)
@@ -315,7 +315,7 @@ (define (maybe-arguments)
         ,@(maybe-arguments)
         (home-page ,(cabal-package-home-page cabal))
         (synopsis ,(cabal-package-synopsis cabal))
-        (description ,(cabal-package-description cabal))
+        (description ,(beautify-description (cabal-package-description cabal)))
         (license ,(string->license (cabal-package-license cabal))))
      (append hackage-dependencies hackage-native-dependencies))))
 
diff --git a/guix/import/minetest.scm b/guix/import/minetest.scm
index 0f3ab473ca..abddd885ee 100644
--- a/guix/import/minetest.scm
+++ b/guix/import/minetest.scm
@@ -322,7 +322,7 @@ (define (make-minetest-sexp author/name version repository commit
      ,@(maybe-propagated-inputs (map contentdb->package-name inputs))
      (home-page ,home-page)
      (synopsis ,(delete-cr synopsis))
-     (description ,(delete-cr description))
+     (description ,(beautify-description (delete-cr description)))
      (license ,(if (eq? media-license license)
                    license
                    `(list ,media-license ,license)))
diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index fe13d29f03..395019d758 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -371,7 +371,8 @@ (define* (opam->guix-package name #:key (repo '()) version)
                                ,(list 'quasiquote `((upstream-name . ,name))))))
                        (home-page ,(metadata-ref opam-content "homepage"))
                        (synopsis ,(metadata-ref opam-content "synopsis"))
-                       (description ,(metadata-ref opam-content "description"))
+                       (description ,(beautify-description
+                                      (metadata-ref opam-content "description")))
                        (license ,(spdx-string->license
                                   (metadata-ref opam-content "license"))))
                     (filter
diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm
index f908136481..3d463a0775 100644
--- a/guix/import/pypi.scm
+++ b/guix/import/pypi.scm
@@ -474,7 +474,7 @@ (define (maybe-upstream-name name)
                    ,@(maybe-inputs native-inputs 'native-inputs)
                    (home-page ,home-page)
                    (synopsis ,synopsis)
-                   (description ,description)
+                   (description ,(beautify-description description))
                    (license ,(license->symbol license)))
                 upstream-dependencies))))))))
 
-- 
2.33.0







^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages
  2021-11-03 10:17 [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Xinglu Chen
  2021-11-03 10:19 ` [bug#51581] [PATCH 1/2] import: utils: Add ‘wrap-lines’ procedure Xinglu Chen
  2021-11-03 10:19 ` [bug#51581] [PATCH 2/2] import: Beautify descriptions when appropriate Xinglu Chen
@ 2021-11-12 22:44 ` Ludovic Courtès
  2021-12-01 15:32   ` Ludovic Courtès
       [not found] ` <cover.1639735009.git.public@yoctocell.xyz>
  3 siblings, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2021-11-12 22:44 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 51581

Hi!

Xinglu Chen <public@yoctocell.xyz> skribis:

> This series adds a ‘wrap-lines’ procedure which wraps the line in a
> string, similar to ‘fill-paragraph’ in Emacs.  This is used to chop the
> description of imported packages into multiple lines, instead of just
> having one really long line.

Does (@ (guix ui) fill-paragraph) suit your needs?  :-)

If so, could you send updated patches?  The rest LGTM.

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages
  2021-11-12 22:44 ` [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Ludovic Courtès
@ 2021-12-01 15:32   ` Ludovic Courtès
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Courtès @ 2021-12-01 15:32 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 51581

Ping!  :-)

Ludovic Courtès <ludo@gnu.org> skribis:

> Hi!
>
> Xinglu Chen <public@yoctocell.xyz> skribis:
>
>> This series adds a ‘wrap-lines’ procedure which wraps the line in a
>> string, similar to ‘fill-paragraph’ in Emacs.  This is used to chop the
>> description of imported packages into multiple lines, instead of just
>> having one really long line.
>
> Does (@ (guix ui) fill-paragraph) suit your needs?  :-)
>
> If so, could you send updated patches?  The rest LGTM.
>
> Thanks,
> Ludo’.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#51581: [PATCH v2 0/2] Wrap lines in the description of generated packages
       [not found] ` <cover.1639735009.git.public@yoctocell.xyz>
@ 2021-12-17 15:53   ` Ludovic Courtès
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Courtès @ 2021-12-17 15:53 UTC (permalink / raw)
  To: Xinglu Chen; +Cc: 51581-done

Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

>   import: utils: Wrap files in description.
>   import: Beautify descriptions when appropriate.

Applied, thanks!

Ludo’.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-17 15:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 10:17 [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Xinglu Chen
2021-11-03 10:19 ` [bug#51581] [PATCH 1/2] import: utils: Add ‘wrap-lines’ procedure Xinglu Chen
2021-11-03 10:19 ` [bug#51581] [PATCH 2/2] import: Beautify descriptions when appropriate Xinglu Chen
2021-11-12 22:44 ` [bug#51581] [PATCH 0/2] Wrap lines in the description of generated packages Ludovic Courtès
2021-12-01 15:32   ` Ludovic Courtès
     [not found] ` <cover.1639735009.git.public@yoctocell.xyz>
2021-12-17 15:53   ` bug#51581: [PATCH v2 " Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.