Patchwork [1/7] import cran: Remove more invalid characters from package names.

login
register
mail settings
Submitter Ricardo Wurmus
Date May 23, 2016, 3:40 p.m.
Message ID <1464018008-1767-2-git-send-email-ricardo.wurmus@mdc-berlin.de>
Download mbox | patch
Permalink /patch/12471/
State New
Headers show

Comments

Ricardo Wurmus - May 23, 2016, 3:40 p.m.
* guix/import/cran.scm (guix-name): Replace period and underscore with
  dash; always prepend package names with "r-".
---
 guix/import/cran.scm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Ludovic Courtès - May 30, 2016, 8:48 a.m.
Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:

> * guix/import/cran.scm (guix-name): Replace period and underscore with
>   dash; always prepend package names with "r-".

[...]

> +    (string-append "r-" (string-downcase
> +                         (regexp-substitute/global #f "(_|\\.)" name
> +                                                   'pre "-" 'post))))

I have a preference fro ‘string-map’, which I find more readable than
‘regexp-substitute/global’ in simple cases.  Thoughts?

Otherwise LGTM!

Thanks,
Ludo’.
Ricardo Wurmus - June 14, 2016, 3:02 p.m.
Ludovic Courtès <ludo@gnu.org> writes:

> Ricardo Wurmus <ricardo.wurmus@mdc-berlin.de> skribis:
>
>> * guix/import/cran.scm (guix-name): Replace period and underscore with
>>   dash; always prepend package names with "r-".
>
> [...]
>
>> +    (string-append "r-" (string-downcase
>> +                         (regexp-substitute/global #f "(_|\\.)" name
>> +                                                   'pre "-" 'post))))
>
> I have a preference fro ‘string-map’, which I find more readable than
> ‘regexp-substitute/global’ in simple cases.  Thoughts?
>
> Otherwise LGTM!

Using “string-map” is indeed nicer!  I’m not a fan of
“regexp-substitute/global” (and regular expressions in general), but it
didn’t occur to me to use “string-map”.  Thanks for the hint.

~~ Ricardo

Patch

diff --git a/guix/import/cran.scm b/guix/import/cran.scm
index c1a9e8e..8b368af 100644
--- a/guix/import/cran.scm
+++ b/guix/import/cran.scm
@@ -151,9 +151,9 @@  empty list when the FIELD cannot be found."
   "Return the `package' s-expression for an R package published on REPOSITORY
 from the alist META, which was derived from the R package's DESCRIPTION file."
   (define (guix-name name)
-    (if (string-prefix? "r-" name)
-        (string-downcase name)
-        (string-append "r-" (string-downcase name))))
+    (string-append "r-" (string-downcase
+                         (regexp-substitute/global #f "(_|\\.)" name
+                                                   'pre "-" 'post))))
 
   (let* ((base-url   (case repository
                        ((cran)         %cran-url)