From: ludo@gnu.org (Ludovic Courtès)
To: Amirouche Boubekki <amirouche@hypermove.net>
Cc: Guix Devel <guix-devel@gnu.org>,
guix-devel-bounces+amirouche=hypermove.net@gnu.org
Subject: Re: [PATCH] guix: scripts: Add --dependencies=PACKAGE commmand
Date: Wed, 24 Jun 2015 22:18:18 +0200 [thread overview]
Message-ID: <87y4j8x3lh.fsf@gnu.org> (raw)
In-Reply-To: <3a40a61b01f71c422f8fd787fbfbeddf@hypermove.net> (Amirouche Boubekki's message of "Sat, 20 Jun 2015 19:07:55 +0200")
Amirouche Boubekki <amirouche@hypermove.net> skribis:
> From fca3a1020af9d4abe71ab8ab4e2a52011688f272 Mon Sep 17 00:00:00 2001
> From: amz3 <amirouche@hypermove.net>
> Date: Sat, 20 Jun 2015 18:23:26 +0200
> Subject: [PATCH] guix: scripts: add --dependencies=PACKAGE command
>
> exemple usage:
>
> guix package --dependencies=qsynth | dot -Tpng > qsynth-deps.png
>
> * guix/scripts/package.scm: add --dependencies command
> * guix/scripts/dependencies.scm: graph datastructure and helpers
Thanks for working on this, this is a useful tool!
Please take some time to read the “Contributing” section of the manual,
and in particular the part about commit logs and coding style. You’ll
quickly notice several things that need to be adjusted. ;-)
Here’s a quick review:
> +++ b/guix/scripts/dependencies.scm
> @@ -0,0 +1,312 @@
> +;; FIXME: copyright
Indeed.
> +;; FIXME: Taken from Guile, should be in (srfi srfi-99)
> +;; adapted to make it possible to declare record type like `<abc>' and keep
> +;; field accessor bracket free. record name *must* have brackets or everything
> +;; is broken
> +;;
> +;; Usage:
> +;;
> +;; (define-record-type <abc> field-one field-two)
> +;; (define zzz (make-abc 1 2))
> +;; (abc-field-one zzz) ;; => 1
> +;;
> +;; FIXME: maybe this is less useful than the immutable record of (srfi srfi-9 gnu)
> +;; Right I will use `set-field` and `set-fields`
> +(define-syntax define-record-type*
Please don’t add another ‘define-record-type’; the one from SRFI-9 will
be good enough here.
> +;;;
> +;;; Store
> +;;;
> +;;; Memory bound immutable association
> +;;;
> +
> +
> +;; XXX: It's assumed that keys are strings.
> +;;
> +;; This replace scheme assoc, because:
> +;; 1) there is no immutable `assoc-set` in scheme
> +;; 2) `acons` (and friends) can replace `assoc-set` but memory will grow without bound
> +;; 3) `assoc-ref` (and friends) always return `#f` when no values is found
That’s not a sufficient argument: one could just
(define (assoc-set alist key value)
(alist-cons key value
(alist-delete key alist)))
Regardless, it may be that vhashes would work better here.
> +;;;
> +;;; Graph
> +;;;
> +
> +(define-record-type* <graph> label nodes edges properties)
[...]
> +(define (graph-get-uid store)
> + (define CHARS "AZERTYUIOPQSDFGHJKLMWXCVBN1029384756")
> +
> + (define (random-id)
> + (let loop ((count 4)
> + (id ""))
> + (if (eq? count 0)
> + id
> + (loop (1- count) (format #f "~a~a" id (string-ref CHARS (random 36)))))))
> +
> + (let loop ()
> + (let ((id (random-id)))
> + (if (null? (store-ref store id))
> + id
> + (loop)))))
What about:
(define (graph-unique-identifier graph)
"Return a unique identifier for GRAPH for use in the ‘dot’ output.”
(number->string (object-address graph) 16))
?
> + (if (package? (cadar packages))
> + (let ((dependency (package-name (cadar packages))))
> + (let*-values (((graph package-uid) (maybe-create-node graph (package-name package)))
> + ((graph dependency-uid) (maybe-create-node graph dependency)))
> + (let* ((label (string-append (package-name (cadar packages)) "--(depends)-->" dependency))
> + (graph (maybe-create-edge graph package-uid label dependency-uid))
> + (graph (package-dependency-graph (cadar packages) graph)))
> + (loop (cdr packages) graph))))
> + (loop (cdr packages) graph)))))
car, cdr, cadar etc. are banned. Please use ‘match’ or some specific
accessor (it may be that a record would be more appropriate here?)
> +(define (graph-dot graph port)
‘graph->dot’
> + ;; (let-values (((name version)
> + ;; (package-name->name+version arg)))
> +
> + ;; ;; (display-dependencies (find-packages-by-name name))
> + ;; (values (cons #f result) #f))))
Leftover.
More importantly, I think this should be in a separate command, or maybe
as an option in ‘guix gc’ since ‘guix gc’ already has --references & co.
WDYT?
I think the graph part should be abstracted so that it can work on (1)
packages, (2) bags, and (3) derivations. Ideally users would be able to
choose which of these they want to represent, from coarse-grain to
fine-grain. (That part could be implemented as a later patch, but the
framework has to be prepared for that.)
Also, I’m not completely sure a separate graph representation (<node>,
<edge>, and <graph>) is needed. Wouldn’t it be sufficient to work
directly on packages objects (or bags or derivations)?
Thanks,
Ludo’.
prev parent reply other threads:[~2015-06-24 20:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-20 16:45 [PATCH] guix: scripts: Add --dependencies=PACKAGE commmand Amirouche Boubekki
2015-06-20 17:07 ` Amirouche Boubekki
2015-06-24 20:18 ` Ludovic Courtès [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4j8x3lh.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=amirouche@hypermove.net \
--cc=guix-devel-bounces+amirouche=hypermove.net@gnu.org \
--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 external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.