From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Package graph queries Date: Sun, 31 Jul 2016 00:19:44 +0200 Message-ID: <87twf6ahvj.fsf_-_@gnu.org> References: <8737mxflz4.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTcbq-00055y-1c for guix-devel@gnu.org; Sat, 30 Jul 2016 18:19:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTcbl-0003LU-PK for guix-devel@gnu.org; Sat, 30 Jul 2016 18:19:52 -0400 In-Reply-To: (Jelle Licht's message of "Fri, 29 Jul 2016 17:26:53 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Jelle Licht Cc: guix-devel Jelle Licht skribis: > On Jul 29, 2016 16:53, "Catonano" 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)=C2=B9, 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-package= s cons '())) $4 =3D # 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 =3D (# # # # # # #= # # # # # # [=E2=80=A6]) scheme@(guile-user)> (length $5) $6 =3D 119 --8<---------------cut here---------------end--------------->8--- The code above lists all the packages with more than 600 dependents. It=E2=80=99s inefficient (a bit less than a minute here) because =E2=80=98node-reachable-count=E2=80=99 does a complete graph traversal (you= could have a variant of it that caches the value for each node, instead). HTH, Ludo=E2=80=99. =C2=B9 All you need is to define a , which is essentially 4 methods.