From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Marusich Subject: bug#35588: [PATCH] ui: Search matches additional package outputs., bug#35588: [PATCH] ui: Search matches additional package outputs. Date: Tue, 07 May 2019 23:50:29 -0700 Message-ID: <878svhv3re.fsf@gmail.com> References: <87r29czo6e.fsf@gmail.com> <20190505214153.32372-1-me@tobias.gr> <87bm0g6jbp.fsf@garuda.local.i-did-not-set--mail-host-address--so-tickle-me> <87muk0kjxf.fsf@gnu.org> <87zhnzxer9.fsf@gmail.com> <87r29czo6e.fsf@gmail.com> <20190505214153.32372-1-me@tobias.gr> <87bm0g6jbp.fsf@garuda.local.i-did-not-set--mail-host-address--so-tickle-me> <87muk0kjxf.fsf@gnu.org> <87zhnzxer9.fsf@gmail.com> <87mujy8yd8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:46892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOGPw-0001Vp-2i for bug-guix@gnu.org; Wed, 08 May 2019 02:51:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOGPu-0000yC-Fy for bug-guix@gnu.org; Wed, 08 May 2019 02:51:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:46673) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOGPu-0000xp-CK for bug-guix@gnu.org; Wed, 08 May 2019 02:51:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hOGPu-0004lr-47 for bug-guix@gnu.org; Wed, 08 May 2019 02:51:02 -0400 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <87mujy8yd8.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Tue, 07 May 2019 10:25:39 +0200, Wed, 8 May 2019 00:24:39 +0200") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , swedebugia Cc: 35588@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: >> (match (field obj) >> (#f relevance) >> - (str (+ relevance >> - (* (score str) weight))))))) >> + ((? string? str) (+ relevance >> + (* (score str) weight))) >> + ((? list? lst) (+ relevance >> + (* weight >> + (apply + (map score lst))))))))) > > Nitpick: it=E2=80=99s a bit subjective, but I think this clause might be > slightly nicer like this: > > ((lst ...) > (+ relevance (* weight (reduce + 0 (map score lst))))) Works for me! I've changed the match clause accordingly in the attached patch. swedebugia writes: > On 2019-05-07 02:57, Chris Marusich wrote: >> + ;; Match against uncommon outputs. >> + (,(lambda (package) >> + (filter (lambda (output) >> + (not (member output >> + ;; Some common outpus shared by many pac= kages. >> + '("out" "debug" "doc" "static")))) > > I suggest we add "gui" and "lib" to this list. Actually, I was curious about this, so I checked how many outputs are being used by all our packages today. Here are the results: =2D-8<---------------cut here---------------start------------->8--- scheme@(guix-user)> ,use (gnu packages) (guix packages) scheme@(guix-user)> (define (increment table key) (hash-set! table key (+ 1= (hash-ref table key 0)))) scheme@(guix-user)> (define (increment-outputs package table) (for-each (la= mbda (output) (increment table output)) (package-outputs package)) table) scheme@(guix-user)> (define outputs-to-count (fold-packages increment-outpu= ts (make-hash-table))) scheme@(guix-user)> ,pp (sort (hash-map->list cons outputs-to-count) (lambd= a (a b) (< (cdr a) (cdr b)))) $1 =3D (("kernel-patch" . 1) ("pcf-8bit" . 1) ("python2" . 1) ("schema" . 1) ("octave" . 1) ("jp" . 1) ("db" . 1) ("gtk3" . 1) ("kr" . 1) ("subtree" . 1) ("pulseaudio" . 1) ("cn" . 1) ("ruby" . 1) ("fbgrab" . 1) ("credential-netrc" . 1) ("front-end" . 1) ("psf" . 1) ("tw" . 1) ("libedataserverui" . 1) ("gtk2" . 1) ("pcf" . 1) ("send-email" . 1) ("jack" . 1) ("python3" . 1) ("ndiff" . 1) ("installer" . 1) ("svn" . 1) ("image" . 1) ("tiles" . 2) ("fortran" . 3) ("include" . 3) ("utils" . 3) ("tests" . 3) ("python" . 4) ("tk" . 4) ("metis" . 4) ("gui" . 4) ("examples" . 5) ("jdk" . 6) ("bin" . 8) ("cargo" . 16) ("static" . 33) ("lib" . 38) ("debug" . 87) ("doc" . 134) ("out" . 9811)) scheme@(guix-user)>=20 =2D-8<---------------cut here---------------end--------------->8--- In light of that, I've chosen to exclude all of the following outputs: '("out" "doc" "debug" "lib" "static" "bin" "examples" "gui" "tests" "utils" "include") I've also added a test to verify that package outputs are included in search results. What do you all think of this latest version? =2D-=20 Chris --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-ui-Make-package-outputs-searchable.patch Content-Transfer-Encoding: quoted-printable From=20dedea618bdd0d557e3e1183c403ff4e11d1757f8 Mon Sep 17 00:00:00 2001 From: Chris Marusich Date: Mon, 6 May 2019 01:51:30 -0700 Subject: [PATCH] ui: Make package outputs searchable. * guix/ui.scm (relevance): Allow the "field" procedure of a metric to return a list, and handle that case appropriately. Update docstring. (%package-metrics): Add a metric for package outputs. * guix/scripts/package.scm (find-packages-by-description): Update docstring. * tests/guix-package.sh: Add a test case to verify that package outputs are included in search results. Co-authored-by: Tobias Geerinckx-Rice =2D-- guix/scripts/package.scm | 6 +++--- guix/ui.scm | 25 ++++++++++++++++++++----- tests/guix-package.sh | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index aa27984ea2..06e4cf5b9c 100644 =2D-- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -180,9 +180,9 @@ hooks\" run when building the profile." ;;; =20 (define (find-packages-by-description regexps) =2D "Return two values: the list of packages whose name, synopsis, or =2Ddescription matches at least one of REGEXPS sorted by relevance, and the= list =2Dof relevance scores." + "Return two values: the list of packages whose name, synopsis, descripti= on, +or output matches at least one of REGEXPS sorted by relevance, and the lis= t of +relevance scores." (let ((matches (fold-packages (lambda (package result) (if (package-superseded package) result diff --git a/guix/ui.scm b/guix/ui.scm index 92c845e944..8f95c00361 100644 =2D-- a/guix/ui.scm +++ b/guix/ui.scm @@ -11,6 +11,8 @@ ;;; Copyright =C2=A9 2016 Benz Schenk ;;; Copyright =C2=A9 2018 Kyle Meyer ;;; Copyright =C2=A9 2018 Ricardo Wurmus +;;; Copyright =C2=A9 2019 Chris Marusich +;;; Copyright =C2=A9 2019 Tobias Geerinckx-Rice ;;; ;;; This file is part of GNU Guix. ;;; @@ -1370,9 +1372,9 @@ WIDTH columns. EXTRA-FIELDS is a list of symbol/valu= e pairs to emit." (define (relevance obj regexps metrics) "Compute a \"relevance score\" for OBJ as a function of its number of matches of REGEXPS and accordingly to METRICS. METRICS is list of =2Dfield/weight pairs, where FIELD is a procedure that returns a string =2Ddescribing OBJ, and WEIGHT is a positive integer denoting the weight of = this =2Dfield in the final score. +field/weight pairs, where FIELD is a procedure that returns a string or li= st +of strings describing OBJ, and WEIGHT is a positive integer denoting the +weight of this field in the final score. =20 A score of zero means that OBJ does not match any of REGEXPS. The higher = the score, the more relevant OBJ is to REGEXPS." @@ -1394,8 +1396,10 @@ score, the more relevant OBJ is to REGEXPS." ((field . weight) (match (field obj) (#f relevance) =2D (str (+ relevance =2D (* (score str) weight))))))) + ((? string? str) + (+ relevance (* (score str) weight))) + ((lst ...) + (+ relevance (* weight (apply + (map score lst))))))))) 0 metrics)) =20 @@ -1404,6 +1408,17 @@ score, the more relevant OBJ is to REGEXPS." ;; of regexps. `((,package-name . 4) =20 + ;; Match against uncommon outputs. + (,(lambda (package) + (filter (lambda (output) + (not (member output + ;; Some common outpus shared by many packag= es. + '("out" "doc" "debug" "lib" "static" "bin" + "examples" "gui" "tests" "utils" + "include")))) + (package-outputs package))) + . 1) + ;; Match regexps on the raw Texinfo since formatting it is quite expen= sive ;; and doesn't have much of an effect on search results. (,(lambda (package) diff --git a/tests/guix-package.sh b/tests/guix-package.sh index 0d60481895..262d29bd59 100644 =2D-- a/tests/guix-package.sh +++ b/tests/guix-package.sh @@ -398,3 +398,28 @@ else grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \ "$module_dir/stderr" fi + +# Verify that package outputs are included in search results. +rm -rf "$module_dir" +mkdir "$module_dir" +cat > "$module_dir/foo.scm"< /tmp/out +test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" =3D "= name: dummy-package" +rm -rf "$module_dir" =2D-=20 2.20.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAlzSfDUACgkQ3UCaFdgi Rp1xwg/+NTUP1dIArj6abV7Sdr+sKDaOPxKDxPcMjSeHvgYDoPtA9LKyEcJdwqnN SPcEgHsUMLdjiKSlkzrOlP+TFIPpLOI6Ttl8g7DSzk8nunUbzo4/GtnrACQB0+PM x+rr20a2PNqtZslmqicIJ8S3i63v+8b7K9+4CUuN/uQzNenufk5+XW2Fk6T0G4/e 1EKEiayOSDy/yZ4R177X1wlr+MPrwc7+M7OfavTAf0VPJ6EBUpAO1PltuJGSR9oY LVTcIUOligLrcguYE6Ftc5wCwC7tV7V81cQj8FwudR/EIB3qGU2NZQi1866SiPoq +poynWV7ZB03BD6ttossmyM3ZTrF2PzrGTADajHCwHalZf6Sc49ZHV5JXXyEcYKL Y0h+tdMInF4JhMm+5b3lbDPQ1zCyukABiEdg2RGzH3SL8HRfzDbPfMKq4f9YrMxw WfcmC3abU8d7upU0mtYXTTOWRoRLwV01lDHYq0wJGfotudcoaZUCX30iSl1/4dOT 8EQSSNhudqr3uqYcEWoo8cqY6e3if+JxMwaNkngsb5bEyg2ed3eykjBNA3wvNnk4 FihDjqpvT4JQOry/c8Wg+sUR6pgaKhanhQQT+1PCSuMYbGUi7ImBRrN/g/NdEA+Q TwDrLV8++2gRwqX8A65RycsADgrVC+d3PhSwT8g4wSDQejmLTFQ= =imKk -----END PGP SIGNATURE----- --==-=-=--