unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Julien Lepiller <julien@lepiller.eu>
Cc: 31736@debbugs.gnu.org
Subject: [bug#31736] [PATCH] Add an opam importer
Date: Sun, 10 Jun 2018 23:28:26 +0200	[thread overview]
Message-ID: <871sdecow5.fsf@gnu.org> (raw)
In-Reply-To: <20180606193740.44bef2ea@lepiller.eu> (Julien Lepiller's message of "Wed, 6 Jun 2018 19:37:40 +0200")

Salut Julien!

Julien Lepiller <julien@lepiller.eu> skribis:

> From a5250186722305961f0a5d77cb8f7f36cdae0da0 Mon Sep 17 00:00:00 2001
> From: Julien Lepiller <julien@lepiller.eu>
> Date: Wed, 6 Jun 2018 19:14:39 +0200
> Subject: [PATCH] guix: Add opam importer.
>
> * guix/scripts/import.scm (importers): Add opam.
> * guix/scripts/import/opam.scm: New file.
> * guix/import/opam.scm: New file.
> * Makefile.am: Add them.

Very nice!  I hope that’ll help create bridges with more fellow OCaml
hackers.  :-)

I have some comments, mostly about style:

> +(define (htable-update htable line)
> +  "Parse @var{line} to get the name and version of the package and adds them
> +to the hashtable."
> +  (let* ((line (string-split line #\ ))
> +         (url (car line)))
> +    (unless (equal? url "repo")
> +      (let ((sp (string-split url #\/)))
> +        (when (equal? (car sp) "packages")
> +          (let* ((versionstr (car (cdr (cdr sp))))
> +                 (name1 (car (cdr sp)))
> +                 (name2 (car (string-split versionstr #\.)))
> +                 (version (string-join (cdr (string-split versionstr #\.)) ".")))
> +            (when (equal? name1 name2)
> +              (let ((curr (hash-ref htable name1 '())))
> +                (hash-set! htable name1 (cons version curr))))))))))

There are a couple of things that don’t fully match the coding style
(see <https://www.gnu.org/software/guix/manual/html_node/Coding-Style.html>):
try to use full names for identifiers, favor a functional style (here
maybe you could use a vhash¹ instead of a hash table), and, last but not
least, use ‘match’ instead of ‘car’ and ‘cdr’.  :-)

¹ https://www.gnu.org/software/guile/manual/html_node/VHashes.html

> +(define (fetch-url uri)
> +  "Fetch and parse the url file.  Return the URL the package can be downloaded
> +from."

Maybe ‘fetch-url-list’ or ‘fetch-package-urls’?

> +(define (fetch-metadata uri)
> +  "Fetch and parse the opam file.  Return an association list containing the
> +homepage, the license and the list of inputs."

Maybe ‘fetch-package-metadata’ to clarify that it’s per-package?

> +(define (deps->inputs deps)
> +  "Transform the list of dependencies in a list of inputs.  Filter out anything
> +that looks like a native-input."

So that would be ‘dependencies->inputs’.  :-)

> +  (if (eq? deps #f)

Rather: (if (not dependencies) …)

> +    (let ((inputs
> +            (map (lambda (input)
> +                   (list input (list 'unquote (string->symbol input))))
> +              (map (lambda (input)
> +                     (cond
> +                       ((equal? input "ocamlfind") "ocaml-findlib")
> +                       ((string-prefix? "ocaml" input) input)
> +                       (else (string-append "ocaml-" input))))
> +                (filter (lambda (input) (not (string-prefix? "conf-" input))) deps)))))

The indentation is misleading: the 2nd argument to ‘map’ should be
aligned with the 1st.

Perhaps you can use ‘filter-map’ here?

> +      (if (eq? (length inputs) 0) '() inputs))))

(eq? (length inputs) 0) → (null? inputs)

Note that ‘null?’ is constant-time whereas ‘length’ is O(n).

Could you add:

  • A few lines in guix.texi, under “Invoking guix import”;

  • Tests in tests/opam.scm (you can take a look at tests/cpan.scm,
    tests/elpa.scm, etc. for inspiration.)

Thank you!

Ludo’.

  reply	other threads:[~2018-06-10 21:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-06 17:23 [bug#31736] [PATCH] Add an opam importer Julien Lepiller
2018-06-06 17:37 ` Julien Lepiller
2018-06-10 21:28   ` Ludovic Courtès [this message]
2018-07-07 21:56     ` Julien Lepiller
2018-07-09 12:44       ` Ludovic Courtès
2018-07-10 11:47         ` bug#31736: " Julien Lepiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871sdecow5.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=31736@debbugs.gnu.org \
    --cc=julien@lepiller.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).