[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#42338] [PATCH 01/34] guix: import: Add composer importer.

From: Ludovic Courtès
Subject: [bug#42338] [PATCH 01/34] guix: import: Add composer importer.
Date: Mon, 07 Sep 2020 16:06:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi Julien,

There’s a lot of interesting work in here!  I’m not familiar with PHP;
I’ll just make a bird’s eye review.

Julien Lepiller <> skribis:

> * guix/import/composer.scm: New file.
> * guix/scripts/import/composer.scm: New file.
> * Add them.
> * guix/scripts/import.scm: Add composer importer.

Please add tests and a mention in “Invoking guix import” in the manual.

For tests, a strategy that I think works well is that used in
tests/cpan.scm, where we spawn an HTTP server to mock the real one.

> +(define* (composer-fetch name #:optional version)
> +  "Return an alist representation of the Composer metadata for the package 
> +or #f on failure."
> +  (let ((package (json-fetch
> +                   (string-append ""; name 
> ".json"))))
> +    (if package
> +        (let* ((packages (assoc-ref package "packages"))
> +               (package (assoc-ref packages name))
> +               (versions (filter
> +                           (lambda (version)
> +                             (and (not (string-contains version "dev"))
> +                                  (not (string-contains version "beta"))))
> +                           (map car package)))
> +               (versions (map
> +                           (lambda (version)
> +                             (cons (fix-version version) version))
> +                           versions))
> +               (version (or (if (null? version) #f version)
> +                            (latest-version (map car versions)))))
> +          (assoc-ref package (assoc-ref versions version)))
> +        #f)))

I recommend using ‘define-json-mapping’ instead of browsing alists: it’s
less error-prone, hides the JSON details away, and leads to more
readable code.  The pypi, crates, cpan importers use it.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]