* [bug#35935] [PATCH] guix: import: simplify recursive import
@ 2019-05-27 20:07 Robert Vollmert
2019-06-02 19:52 ` Ludovic Courtès
2019-06-02 20:19 ` [bug#35935] [PATCH] guix: import: Simplify " Robert Vollmert
0 siblings, 2 replies; 7+ messages in thread
From: Robert Vollmert @ 2019-05-27 20:07 UTC (permalink / raw)
To: 35935; +Cc: Robert Vollmert
This simplifies the logic of recursive-import, intending no
major functional changes. The package import function is no
longer called twice per package. Failed imports now make it
to the package stream as '() instead of #f.
* guix/import/utils.scm: Simplify recursive-import.
---
guix/import/utils.scm | 86 ++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 54 deletions(-)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 516c0cfaa2..ff548b809a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -378,57 +378,35 @@ separated by PRED."
#: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))))))))
+ (define (exists? dependency)
+ (not (null? (find-packages-by-name (guix-name dependency)))))
+ (define initial-state (list #f (list package-name) (list)))
+ (define (step state)
+ (match state
+ ((prev (next . rest) done)
+ (define (handle? dep)
+ (and
+ (not (equal? dep next))
+ (not (member dep done))
+ (not (exists? dep))))
+ (receive (package . dependencies) (repo->guix-package next repo)
+ (list
+ (if package package '()) ;; default #f on failure would interrupt
+ (if package
+ (lset-union equal? rest (filter handle? (car dependencies)))
+ rest)
+ (cons next done))))
+ ((prev '() done)
+ (list #f '() done))))
+
+ ;; Generate a lazy stream of package expressions for all unknown
+ ;; dependencies in the graph.
+ (stream-unfold
+ ;; map: produce a stream element
+ (match-lambda ((latest queue done) latest))
+ ;; predicate
+ (match-lambda ((latest queue done) latest))
+ ;; generator: update the queue
+ step
+ ;; initial state
+ (step initial-state)))
--
2.20.1 (Apple Git-117)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [bug#35935] [PATCH] guix: import: simplify recursive import
2019-05-27 20:07 [bug#35935] [PATCH] guix: import: simplify recursive import Robert Vollmert
@ 2019-06-02 19:52 ` Ludovic Courtès
2019-06-02 20:23 ` Robert Vollmert
2019-06-02 20:19 ` [bug#35935] [PATCH] guix: import: Simplify " Robert Vollmert
1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2019-06-02 19:52 UTC (permalink / raw)
To: Robert Vollmert; +Cc: 35935
Hello Robert,
Robert Vollmert <rob@vllmrt.net> skribis:
> This simplifies the logic of recursive-import, intending no
> major functional changes. The package import function is no
> longer called twice per package. Failed imports now make it
> to the package stream as '() instead of #f.
>
> * guix/import/utils.scm: Simplify recursive-import.
^
Minor issue: please make sure to mention the modified entities here
(procedures, variables, etc.); see
<https://www.gnu.org/prep/standards/html_node/Change-Logs.html>.
I think Oleg worked on this part before; Oleg, could you comment
and/or apply?
‘tests/import-utils.scm’ doesn’t seem to be testing this procedure,
perhaps that’s something we should fix eventually.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [bug#35935] [PATCH] guix: import: Simplify recursive import.
2019-05-27 20:07 [bug#35935] [PATCH] guix: import: simplify recursive import Robert Vollmert
2019-06-02 19:52 ` Ludovic Courtès
@ 2019-06-02 20:19 ` Robert Vollmert
1 sibling, 0 replies; 7+ messages in thread
From: Robert Vollmert @ 2019-06-02 20:19 UTC (permalink / raw)
To: 35935; +Cc: Robert Vollmert
This simplifies the logic of recursive-import, intending no
major functional changes. The package import function is no
longer called twice per package. Failed imports now make it
to the package stream as '() instead of #f.
* guix/import/utils.scm (recursive-import): Simplify.
---
guix/import/utils.scm | 86 ++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 54 deletions(-)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 516c0cfaa2..ff548b809a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -378,57 +378,35 @@ separated by PRED."
#: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))))))))
+ (define (exists? dependency)
+ (not (null? (find-packages-by-name (guix-name dependency)))))
+ (define initial-state (list #f (list package-name) (list)))
+ (define (step state)
+ (match state
+ ((prev (next . rest) done)
+ (define (handle? dep)
+ (and
+ (not (equal? dep next))
+ (not (member dep done))
+ (not (exists? dep))))
+ (receive (package . dependencies) (repo->guix-package next repo)
+ (list
+ (if package package '()) ;; default #f on failure would interrupt
+ (if package
+ (lset-union equal? rest (filter handle? (car dependencies)))
+ rest)
+ (cons next done))))
+ ((prev '() done)
+ (list #f '() done))))
+
+ ;; Generate a lazy stream of package expressions for all unknown
+ ;; dependencies in the graph.
+ (stream-unfold
+ ;; map: produce a stream element
+ (match-lambda ((latest queue done) latest))
+ ;; predicate
+ (match-lambda ((latest queue done) latest))
+ ;; generator: update the queue
+ step
+ ;; initial state
+ (step initial-state)))
--
2.20.1 (Apple Git-117)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [bug#35935] [PATCH] guix: import: simplify recursive import
2019-06-02 19:52 ` Ludovic Courtès
@ 2019-06-02 20:23 ` Robert Vollmert
2019-06-03 19:56 ` Oleg Pykhalov
0 siblings, 1 reply; 7+ messages in thread
From: Robert Vollmert @ 2019-06-02 20:23 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 35935
> On 2. Jun 2019, at 21:52, Ludovic Courtès <ludo@gnu.org> wrote:
> Robert Vollmert <rob@vllmrt.net> skribis:
>> * guix/import/utils.scm: Simplify recursive-import.
> ^
> Minor issue: please make sure to mention the modified entities here
> (procedures, variables, etc.); see
> <https://www.gnu.org/prep/standards/html_node/Change-Logs.html>.
Fixed, thanks for the heads up.
> I think Oleg worked on this part before; Oleg, could you comment
> and/or apply?
>
> ‘tests/import-utils.scm’ doesn’t seem to be testing this procedure,
> perhaps that’s something we should fix eventually.
Agreed. It does seem to be covered somewhat by tests/gem.scm.
I also tested it a bit by hand, with some haskell packages.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [bug#35935] [PATCH] guix: import: simplify recursive import
2019-06-02 20:23 ` Robert Vollmert
@ 2019-06-03 19:56 ` Oleg Pykhalov
2019-06-03 19:59 ` Robert Vollmert
0 siblings, 1 reply; 7+ messages in thread
From: Oleg Pykhalov @ 2019-06-03 19:56 UTC (permalink / raw)
To: Robert Vollmert; +Cc: 35935
[-- Attachment #1: Type: text/plain, Size: 929 bytes --]
Hello Robert,
Robert Vollmert <rob@vllmrt.net> writes:
[…]
>> I think Oleg worked on this part before; Oleg, could you comment
>> and/or apply?
>>
>> ‘tests/import-utils.scm’ doesn’t seem to be testing this procedure,
>> perhaps that’s something we should fix eventually.
>
> Agreed. It does seem to be covered somewhat by tests/gem.scm.
> I also tested it a bit by hand, with some haskell packages.
True, ‘tests/gem.scm’ file tests ‘recursive-import’ procedure by
invoking ‘gem-recursive-import’. I think this test is good enough for
our purpose - use ‘recursive-import’ in other package importers and make
sure it works. Thoughts?
I also added a copyright line if you don't mind:
;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
Is it OK, Robert? I tested manually with ‘gem’ and ‘elpa’ recursive
importers and ready to push :-)
Thanks,
Oleg.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [bug#35935] [PATCH] guix: import: simplify recursive import
2019-06-03 19:56 ` Oleg Pykhalov
@ 2019-06-03 19:59 ` Robert Vollmert
2019-06-03 20:31 ` bug#35935: " Oleg Pykhalov
0 siblings, 1 reply; 7+ messages in thread
From: Robert Vollmert @ 2019-06-03 19:59 UTC (permalink / raw)
To: Oleg Pykhalov; +Cc: 35935
Hello Oleg,
thanks for having a look.
> On 3. Jun 2019, at 21:56, Oleg Pykhalov <go.wigust@gmail.com> wrote:
[…]
> I also added a copyright line if you don't mind:
>
> ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
>
> Is it OK, Robert? I tested manually with ‘gem’ and ‘elpa’ recursive
> importers and ready to push :-)
Yes, of course. (Should I generally be adding copyright lines when edit
a file?
Cheers
Robert
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#35935: [PATCH] guix: import: simplify recursive import
2019-06-03 19:59 ` Robert Vollmert
@ 2019-06-03 20:31 ` Oleg Pykhalov
0 siblings, 0 replies; 7+ messages in thread
From: Oleg Pykhalov @ 2019-06-03 20:31 UTC (permalink / raw)
To: Robert Vollmert; +Cc: 35935-done
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
Robert Vollmert <rob@vllmrt.net> writes:
[…]
>> I also added a copyright line if you don't mind:
>>
>> ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
>>
>> Is it OK, Robert? I tested manually with ‘gem’ and ‘elpa’ recursive
>> importers and ready to push :-)
>
> Yes, of course. (Should I generally be adding copyright lines when edit
> a file?
Yes.
Pushed as 5b315f3ea93020df52bc11105064a1398687e572 to master.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-06-03 20:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-27 20:07 [bug#35935] [PATCH] guix: import: simplify recursive import Robert Vollmert
2019-06-02 19:52 ` Ludovic Courtès
2019-06-02 20:23 ` Robert Vollmert
2019-06-03 19:56 ` Oleg Pykhalov
2019-06-03 19:59 ` Robert Vollmert
2019-06-03 20:31 ` bug#35935: " Oleg Pykhalov
2019-06-02 20:19 ` [bug#35935] [PATCH] guix: import: Simplify " Robert Vollmert
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).