From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6OuLE2FigmHWhQEAgWs5BA (envelope-from ) for ; Wed, 03 Nov 2021 11:20:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id snpKD2FigmFzFgAAB5/wlQ (envelope-from ) for ; Wed, 03 Nov 2021 10:20:17 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B6C3813887 for ; Wed, 3 Nov 2021 11:20:14 +0100 (CET) Received: from localhost ([::1]:51290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miDNN-0002t8-I3 for larch@yhetil.org; Wed, 03 Nov 2021 06:20:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miDND-0002sc-1G for guix-patches@gnu.org; Wed, 03 Nov 2021 06:20:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miDNC-0005fr-Ox for guix-patches@gnu.org; Wed, 03 Nov 2021 06:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1miDNC-00013a-LI for guix-patches@gnu.org; Wed, 03 Nov 2021 06:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51581] [PATCH 1/2] import: utils: Add =?UTF-8?Q?=E2=80=98wrap-lines=E2=80=99?= procedure. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 03 Nov 2021 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51581 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51581@debbugs.gnu.org Received: via spool by 51581-submit@debbugs.gnu.org id=B51581.16359347663991 (code B ref 51581); Wed, 03 Nov 2021 10:20:02 +0000 Received: (at 51581) by debbugs.gnu.org; 3 Nov 2021 10:19:26 +0000 Received: from localhost ([127.0.0.1]:39099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1miDMb-00012I-W6 for submit@debbugs.gnu.org; Wed, 03 Nov 2021 06:19:26 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:45492 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1miDMZ-000122-Sv for 51581@debbugs.gnu.org; Wed, 03 Nov 2021 06:19:24 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1635934757; bh=JPjC/7Zjf6NWv4vNGlSahLNZ6gcbOg+AWJtiq6tixjI=; h=From:To:Subject:In-Reply-To:References:Date; b=kpyT46X2EkKGufJK3wKQjQvmY/xIpUnrfhp8bL5xYP5oEW+J0u5O26Qm6ukJlYQVh Gp2Eb/9Owi57ymVFf/hlzIRcjWMUpNt4/JS25AO87Nw9k4kOfDS8hE8EhUtxowdWY0 9INw9w4q2wAhAHj6IkcHG6yY/1zNKGVMBk0BFnnA= In-Reply-To: References: Message-Id: Date: Wed, 03 Nov 2021 11:19:16 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635934814; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=B8ltAtbiADa2JAWVVKkHN90gZzwH9UudBrWE76E2enA=; b=MEiyIGNMZXUx7oF1c5SFFoP9cArg8SxEiOQtR9g8SFo83dArdCeV/Q+a99eNJsOsFaqxmb JF0Oy1gLRNYpIl5OJx4TJ+PamffeFahEUWf9Hys2lzI2w/Abl9KQUNDxOvmek/MeamplFt LCCEeTYwi7pb6d5jAFDlmKIZTISOuDwD1XdZ7RQ4lbny1JNAu3dVwtZtjx6oyAUzKxcdbq KkLxtx0XSr60VxstCxSQBQjQMUzNoekOuH3LAAx8STQH/U5zvVcwXK7GSMqkIW9qwhEG47 L4A60NCZCFwawK4J88XfgjKO4a2o+bwg4e+QA6hvnWCoRw6Z+PsWFXix1OL1hw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635934814; a=rsa-sha256; cv=none; b=uw6cQCggNsXZonO1wDcHPx9DoDndzhiH4nZtW/5UaB2Qtic1aJsvnBhBIr7SFVy4y7cr29 TwzxyzerzsgLLrftkEF68+St/SvuhNWLTX6oNgJgCGYBE1OYjMTVGupcJhnN1y45jcRm5d 9DkbA0wNmYeGmkDn0MAGalp9CMdUpVV47U+k+04KdcW5063/vb3ZgldnsgU/2Xexcbpqn7 UIxmvaj8ilVGgPrMjTow4j3SlwOa4NGXXA8WmIUwGEASejpbKNGV05LBD6BlmfLHjB76Ue 1ObtH+iF7PQ5PhWXLxWd63qJZjcDcK/gJF/GJPn9nzQGZwUqNkjQSCxaV1PTFg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=kpyT46X2; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=kpyT46X2; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: B6C3813887 X-Spam-Score: -0.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: d9UjyYx1Xkhz * guix/import/utils.scm (wrap-lines): New procedure. (beautify-description): Use it; add optional =E2=80=98length=E2=80=99 argum= ent. * 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 =C2=A9 2020 Martin Becze ;;; Copyright =C2=A9 2021 Maxim Cournoyer ;;; Copyright =C2=A9 2021 Sarah Morgensen +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -66,6 +67,7 @@ (define-module (guix import utils) license->symbol =20 snake-case + wrap-lines beautify-description =20 alist->package @@ -231,9 +233,32 @@ (define (snake-case str) with dashes." (string-join (string-split (string-downcase str) #\_) "-")) =20 -(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 (=3D (string-length acc) 0)) + (=3D (modulo (string-length acc) length) 0) + (not (=3D counter 1))) + (let ((before (substring acc 0 (- counter 1))) + (after (substring acc counter))) + (aux str (string-append before "\n" after) 1))) + ((char=3D? (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 fragmen= t into +a proper sentence and by using two spaces between sentences, and wrap line= s 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))) =20 (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 =C2=A9 2016 Ben Woodcroft ;;; Copyright =C2=A9 2020 Martin Becze ;;; Copyright =C2=A9 2021 Sarah Morgensen +;;; Copyright =C2=A9 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -31,6 +32,10 @@ (define-module (test-import-utils) =20 (test-begin "import-utils") =20 +(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, se= d 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 --=20 2.33.0