guix-patches
[Top][All Lists]
Advanced

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

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


From: Julien Lepiller
Subject: [bug#42338] [PATCH 01/34] guix: import: Add composer importer.
Date: Fri, 18 Sep 2020 00:43:33 +0200

Le Mon, 07 Sep 2020 16:06:13 +0200,
Ludovic Courtès <ludo@gnu.org> a écrit :

> 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 <julien@lepiller.eu> skribis:
> 
> > * guix/import/composer.scm: New file.
> > * guix/scripts/import/composer.scm: New file.
> > * Makefile.am: 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 NAME, +or #f on failure."
> > +  (let ((package (json-fetch
> > +                   (string-append "https://repo.packagist.org/p/";
> > 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.
> 
> Thanks!
> 
> Ludo’.

Thanks, here's a new version

Attachment: 0001-guix-import-Add-composer-importer.patch
Description: Text Data


reply via email to

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