guix-devel
[Top][All Lists]
Advanced

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

Package graph queries


From: Ludovic Courtès
Subject: Package graph queries
Date: Sun, 31 Jul 2016 00:19:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Jelle Licht <address@hidden> skribis:

> On Jul 29, 2016 16:53, "Catonano" <address@hidden> wrote:

[...]

>> For example: which are the packages with less or no dependencies (and a
>> lot of dependants) ?
>> Because those should be imported first, in my opinion.

[...]

> ^ This, I like. Does anyone have any suggestions on tools that could help
> me do this in guile?

I understand you want to perform these queries on NPM packages, not Guix
packages, but if you could hook your NPM package representation in (guix
graph)¹, you could do the same as this:

--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,use(guix graph)
scheme@(guile-user)> ,use(guix scripts graph)
scheme@(guile-user)> ,use(gnu packages)
scheme@(guile-user)> ,use(guix monad-repl)
scheme@(guile-user)> ,enter-store-monad
store-monad@(guile-user) [1]> (node-back-edges %bag-node-type (fold-packages 
cons '()))
$4 = #<procedure 59ac880 at guix/graph.scm:87:17 (node)>
store-monad@(guile-user) [1]> ,q
scheme@(guile-user)> ,use(srfi srfi-1)
scheme@(guile-user)> (filter (lambda (p)
                               (> (node-reachable-count (list p) $4)
                                  600))
                             (fold-packages cons '()))
$5 = (#<package address@hidden gnu/packages/xorg.scm:973 325e3c0> #<package 
address@hidden gnu/packages/xorg.scm:1690 326c000> #<package address@hidden 
gnu/packages/xorg.scm:2308 328df00> #<package address@hidden 
gnu/packages/xorg.scm:1302 326ca80> #<package address@hidden 
gnu/packages/xorg.scm:1187 326cd80> #<package address@hidden 
gnu/packages/xorg.scm:4711 32c0240> #<package address@hidden 
gnu/packages/xorg.scm:4408 32c09c0> #<package address@hidden 
gnu/packages/xorg.scm:5139 32cf9c0> #<package address@hidden 
gnu/packages/xorg.scm:1277 326cb40> #<package address@hidden 
gnu/packages/xorg.scm:1160 326ce40> #<package address@hidden 
gnu/packages/xorg.scm:4577 32c0540> #<package address@hidden 
gnu/packages/xorg.scm:2061 327e600> #<package address@hidden 
gnu/packages/xorg.scm:997 325e300> […])
scheme@(guile-user)> (length $5)
$6 = 119
--8<---------------cut here---------------end--------------->8---

The code above lists all the packages with more than 600 dependents.

It’s inefficient (a bit less than a minute here) because
‘node-reachable-count’ does a complete graph traversal (you could
have a variant of it that caches the value for each node, instead).

HTH,
Ludo’.

¹ All you need is to define a <node-type>, which is essentially 4
  methods.



reply via email to

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