unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: swedebugia <swedebugia@riseup.net>
To: guix-devel <guix-devel@gnu.org>
Subject: Adding versioning to our recursive importer
Date: Mon, 14 Jan 2019 10:53:54 +0100	[thread overview]
Message-ID: <7ef35401-5d2f-1107-0bd4-c9ece71cc663@riseup.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 3280 bytes --]

Hi

I would like some help from someone who understands the recursive importer.

The reason is that in our npm-importer we have to support different 
versions of the same packages to avoid circular dependencies (which 
happen e.g. when importing gulp when not considering versions).

Doing this manually is... not viable. (see the svgz attached)

For every dependency I expect the procedure below to handle a list 
dependency pairs of name+version instead of just name.

Our very nice recursive importer looks like this:

(define* (recursive-import package-name repo
                            #:key repo->guix-package guix-name
                            #:allow-other-keys)
   "Generate a stream of package expressions for PACKAGE-NAME and all its
dependencies."
   (receive (package . dependencies)
       (repo->guix-package package-name repo)
     (if (not package)
         stream-null

         ;; Generate a lazy stream of package expressions for all unknown
         ;; dependencies in the graph.
         (let* ((make-state (lambda (queue done)
                              (cons queue done)))
                (next       (match-lambda
                              (((next . rest) . done) next)))
                (imported   (match-lambda
                              ((queue . done) done)))
                (done?      (match-lambda
                              ((queue . done)
                               (zero? (length queue)))))
                (unknown?   (lambda* (dependency #:optional (done '()))
                              (and (not (member dependency
                                                done))
                                   (null? (find-packages-by-name
                                           (guix-name dependency))))))
                (update     (lambda (state new-queue)
                              (match state
                                (((head . tail) . done)
                                 (make-state (lset-difference
                                              equal?
                                              (lset-union equal? 
new-queue tail)
                                              done)
                                             (cons head done)))))))
           (stream-cons
            package
            (stream-unfold
             ;; map: produce a stream element
             (lambda (state)
               (repo->guix-package (next state) repo))

             ;; predicate
             (negate done?)

             ;; generator: update the queue
             (lambda (state)
               (receive (package . dependencies)
                   (repo->guix-package (next state) repo)
                 (if package
                     (update state (filter (cut unknown? <>
                                                (cons (next state)
                                                      (imported state)))
                                           (car dependencies)))
                     ;; TODO: Try the other archives before giving up
                     (update state (imported state)))))

             ;; initial state
             (make-state (filter unknown? (car dependencies))
                         (list package-name))))))))

Any ideas?

-- 
Cheers Swedebugia

[-- Attachment #2: gulp.svgz --]
[-- Type: image/svg+xml-compressed, Size: 74131 bytes --]

             reply	other threads:[~2019-01-14  9:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14  9:53 swedebugia [this message]
2019-01-26  0:00 ` Adding versioning to our recursive importer Ivan Petkov

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=7ef35401-5d2f-1107-0bd4-c9ece71cc663@riseup.net \
    --to=swedebugia@riseup.net \
    --cc=guix-devel@gnu.org \
    /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).