me
/
guix
Archived
1
0
Fork 0

import/utils: beautify-description: Update to pass tests.

* guix/import/utils.scm (beautify-description): Remove single quote wrapping;
escape @; exclude common abbreviations and titles from double-spacing; detect
more sentence fragments.
master
Ricardo Wurmus 2022-10-05 23:46:27 +02:00
parent 421a87a68a
commit 7d04f3ad28
No known key found for this signature in database
GPG Key ID: 197A5888235FACAC
1 changed files with 45 additions and 20 deletions

View File

@ -273,29 +273,54 @@ with dashes."
"Improve the package DESCRIPTION by turning a beginning sentence fragment into "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 a proper sentence and by using two spaces between sentences, and wrap lines at
LENGTH characters." LENGTH characters."
(let ((cleaned (cond (unless (string? description)
((not (string? description)) (G_ "This package lacks a description. Run \
(G_ "This package lacks a description. Run \
\"info '(guix) Synopses and Descriptions'\" for more information.")) \"info '(guix) Synopses and Descriptions'\" for more information."))
((string-prefix? "A " description)
(string-append "This package provides a" (let* ((fix-word
(substring description 1))) (lambda (word)
((string-prefix? "Provides " description) (fold (lambda (proc acc) (proc acc)) word
(string-append "This package provides" (list
(substring description ;; Remove wrapping in single quotes, common in R packages.
(string-length "Provides")))) (cut string-trim-both <> #\')
((string-prefix? "Implements " description) ;; Escape single @ to prevent it from being understood as
(string-append "This package implements" ;; invalid Texinfo syntax.
(substring description (cut regexp-substitute/global #f "@" <> 'pre "@@" 'post)))))
(string-length "Implements")))) (words
((string-prefix? "Functions " description) (string-tokenize (string-trim-both description)
(string-append "This package provides functions" (char-set-complement
(substring description (char-set #\space #\newline))))
(string-length "Functions")))) (new-words
(else description)))) (match words
(((and (or "A" "Functions" "Methods") first) . rest)
(cons* "This" "package" "provides"
(string-downcase first) rest))
(((and (or "Contains"
"Creates"
"Performs"
"Provides"
"Produces"
"Implements"
"Infers") first) . rest)
(cons* "This" "package"
(string-downcase first) rest))
(_ words)))
(cleaned
(string-join (map fix-word new-words))))
;; Use double spacing between sentences ;; Use double spacing between sentences
(fill-paragraph (regexp-substitute/global #f "\\. \\b" (fill-paragraph (regexp-substitute/global #f "\\. \\b"
cleaned 'pre ". " 'post) cleaned 'pre
(lambda (m)
(let ((pre (match:prefix m))
(abbrevs '("Dr" "Mr" "Mrs"
"Ms" "Prof" "vs"
"e.g")))
(if (or (any (cut string-suffix? <> pre) abbrevs)
(char-upper-case?
(string-ref pre (1- (string-length pre)))))
". "
". ")))
'post)
length))) length)))
(define (beautify-synopsis synopsis) (define (beautify-synopsis synopsis)