From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: bug-guix@gnu.org
Subject: Re: [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with 'find-packages'.
Date: Thu, 07 Mar 2013 00:28:13 +0100 [thread overview]
Message-ID: <87lia09khe.fsf@gnu.org> (raw)
In-Reply-To: <87sj48gxzp.fsf_-_@karetnikov.org> (Nikita Karetnikov's message of "Wed, 06 Mar 2013 22:54:34 +0400")
Nikita Karetnikov <nikita@karetnikov.org> skribis:
>> Also, I think it should process fields, and return an alist, or even
>> better, a ‘gnu-package-descriptor’ record (say).
>>
>> (define-record-type <gnu-package-descriptor>
>> gnu-package-descriptor?
>> (gnu-package-descriptor name logo-url doc-category ...)
>> ...
>> )
>>
>> (official-gnu-packages)
>> => (#<gnu-package-descriptor name: "guix" logo-url: "http://..." ...#> ...)
>>
>> WDYT?
>
> Oh, I forgot about this when I was writing the attached patch. Is it
> fine? Should I rewrite it using records?
Yes please, that would be better.
> I guess that it will work faster if I use 'cons' in 'loop' instead of
> 'append'. Is it worth it?
In general yes: always cons, and reverse at the end (that makes the
complexity linear.)
> Examples:
>
> scheme@(guile-user)> ,use (guix gnu-maintenance)
> scheme@(guile-user)> (find-packages "guix")
> $1 = (("package: guix" "logo: /software/guix/graphics/guix-logo.small.png" "doc-category: Sysadmin" "doc-summary: Managing installed software packages and versions" "doc-url: none" "gplv3-status: should-be-ok" "activity-status: newpkg/20121117"))
Since it has to read all the package file, I’d rather keep an
‘official-gnu-packages’ that would return a list of all the packages
(we’re talking about less than 1 MiB of RAM), and then use ‘filter’ on
that.
(Alternately, ‘official-gnu-packages’ could be a stream (in the sense of
(ice-9 stream)), but then there’s going to be issues with connection
timeouts, so a plain old list is better.)
> + "Return an input port with the textual data at URI, a string."
> + (let*-values (((resp port)
> + (http-get* (string->uri uri)))
This code is run by the user’s Guile, which may be older than 2.0.7
(‘http-get*’ was introduced in 2.0.7), so you can’t rely on it.
What you can do is something along the lines of what (guix build
download) does, but always return a port. Maybe there’s a way to share
code.
A couple of stylistic comments:
> + (define (group-packages port state)
> + ;; Return a list of packages.
> + (let ((line (read-line port)))
> + (define (loop str)
> + (match str
> + ('""
> + (group-packages port (append state '(()))))
> + (str
> + (group-packages port (append (drop-right state 1)
> + (list (append (last state)
> + (list str))))))))
It’s called ‘loop’ but it doesn’t loop.
I’d rather change ‘group-packages’ to ‘read-package-fields’ or something
like that.
> + (filter (lambda (lst)
> + (not (null-list? lst)))
> + state)
(remove null-list? state)
> + (and=> (regexp-exec package-line-rx (first sublst))
> + (lambda _
> + sublst)))
identity
Thanks,
Ludo’.
next prev parent reply other threads:[~2013-03-06 23:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 5:29 [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package-list' Nikita Karetnikov
2013-02-22 10:00 ` Ludovic Courtès
2013-03-06 18:54 ` [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with 'find-packages' Nikita Karetnikov
2013-03-06 23:28 ` Ludovic Courtès [this message]
2013-03-16 19:30 ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add the related procedures Nikita Karetnikov
2013-03-16 23:13 ` Ludovic Courtès
2013-03-22 1:37 ` Nikita Karetnikov
2013-03-22 10:08 ` Brandon Invergo
2013-03-22 12:30 ` Ludovic Courtès
2013-03-22 12:19 ` Ludovic Courtès
2013-03-26 20:22 ` Nikita Karetnikov
2013-03-26 20:50 ` Ludovic Courtès
2013-03-26 20:59 ` Nikita Karetnikov
2013-03-26 21:21 ` Ludovic Courtès
2013-03-27 6:05 ` Nikita Karetnikov
2013-03-27 10:08 ` Ludovic Courtès
2013-03-31 22:50 ` Ludovic Courtès
2013-03-26 20:49 ` Nikita Karetnikov
2013-03-26 21:02 ` Ludovic Courtès
2013-03-28 2:08 ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add " Nikita Karetnikov
2013-03-28 16:48 ` Ludovic Courtès
2013-03-28 22:40 ` Nikita Karetnikov
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=87lia09khe.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=bug-guix@gnu.org \
--cc=nikita@karetnikov.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.