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 <me@tobias.gr>
This commit is contained in:
parent
063edf928a
commit
387e6b9e34
|
@ -180,9 +180,9 @@ hooks\" run when building the profile."
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(define (find-packages-by-description regexps)
|
(define (find-packages-by-description regexps)
|
||||||
"Return two values: the list of packages whose name, synopsis, or
|
"Return two values: the list of packages whose name, synopsis, description,
|
||||||
description matches at least one of REGEXPS sorted by relevance, and the list
|
or output matches at least one of REGEXPS sorted by relevance, and the list of
|
||||||
of relevance scores."
|
relevance scores."
|
||||||
(let ((matches (fold-packages (lambda (package result)
|
(let ((matches (fold-packages (lambda (package result)
|
||||||
(if (package-superseded package)
|
(if (package-superseded package)
|
||||||
result
|
result
|
||||||
|
|
23
guix/ui.scm
23
guix/ui.scm
|
@ -11,6 +11,8 @@
|
||||||
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
|
;;; Copyright © 2016 Benz Schenk <benz.schenk@uzh.ch>
|
||||||
;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
|
;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
|
||||||
;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
|
||||||
|
;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
|
||||||
|
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -1370,9 +1372,9 @@ WIDTH columns. EXTRA-FIELDS is a list of symbol/value pairs to emit."
|
||||||
(define (relevance obj regexps metrics)
|
(define (relevance obj regexps metrics)
|
||||||
"Compute a \"relevance score\" for OBJ as a function of its number of
|
"Compute a \"relevance score\" for OBJ as a function of its number of
|
||||||
matches of REGEXPS and accordingly to METRICS. METRICS is list of
|
matches of REGEXPS and accordingly to METRICS. METRICS is list of
|
||||||
field/weight pairs, where FIELD is a procedure that returns a string
|
field/weight pairs, where FIELD is a procedure that returns a string or list
|
||||||
describing OBJ, and WEIGHT is a positive integer denoting the weight of this
|
of strings describing OBJ, and WEIGHT is a positive integer denoting the
|
||||||
field in the final score.
|
weight of this field in the final score.
|
||||||
|
|
||||||
A score of zero means that OBJ does not match any of REGEXPS. The higher the
|
A score of zero means that OBJ does not match any of REGEXPS. The higher the
|
||||||
score, the more relevant OBJ is to REGEXPS."
|
score, the more relevant OBJ is to REGEXPS."
|
||||||
|
@ -1394,8 +1396,10 @@ score, the more relevant OBJ is to REGEXPS."
|
||||||
((field . weight)
|
((field . weight)
|
||||||
(match (field obj)
|
(match (field obj)
|
||||||
(#f relevance)
|
(#f relevance)
|
||||||
(str (+ relevance
|
((? string? str)
|
||||||
(* (score str) weight)))))))
|
(+ relevance (* (score str) weight)))
|
||||||
|
((lst ...)
|
||||||
|
(+ relevance (* weight (apply + (map score lst)))))))))
|
||||||
0
|
0
|
||||||
metrics))
|
metrics))
|
||||||
|
|
||||||
|
@ -1404,6 +1408,15 @@ score, the more relevant OBJ is to REGEXPS."
|
||||||
;; of regexps.
|
;; of regexps.
|
||||||
`((,package-name . 4)
|
`((,package-name . 4)
|
||||||
|
|
||||||
|
;; Match against uncommon outputs.
|
||||||
|
(,(lambda (package)
|
||||||
|
(filter (lambda (output)
|
||||||
|
(not (member output
|
||||||
|
;; Some common outpus shared by many packages.
|
||||||
|
'("out" "doc" "debug" "lib" "include" "bin"))))
|
||||||
|
(package-outputs package)))
|
||||||
|
. 1)
|
||||||
|
|
||||||
;; Match regexps on the raw Texinfo since formatting it is quite expensive
|
;; Match regexps on the raw Texinfo since formatting it is quite expensive
|
||||||
;; and doesn't have much of an effect on search results.
|
;; and doesn't have much of an effect on search results.
|
||||||
(,(lambda (package)
|
(,(lambda (package)
|
||||||
|
|
|
@ -398,3 +398,28 @@ else
|
||||||
grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
|
grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \
|
||||||
"$module_dir/stderr"
|
"$module_dir/stderr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Verify that package outputs are included in search results.
|
||||||
|
rm -rf "$module_dir"
|
||||||
|
mkdir "$module_dir"
|
||||||
|
cat > "$module_dir/foo.scm"<<EOF
|
||||||
|
(define-module (foo)
|
||||||
|
#:use-module (guix packages)
|
||||||
|
#:use-module (guix build-system trivial))
|
||||||
|
|
||||||
|
(define-public dummy-package
|
||||||
|
(package
|
||||||
|
(name "dummy-package")
|
||||||
|
(version "dummy-version")
|
||||||
|
(outputs '("out" "dummy-output"))
|
||||||
|
(source #f)
|
||||||
|
;; Without a real build system, the "guix pacakge -s" command will fail.
|
||||||
|
(build-system trivial-build-system)
|
||||||
|
(synopsis "dummy-synopsis")
|
||||||
|
(description "dummy-description")
|
||||||
|
(home-page "https://dummy-home-page")
|
||||||
|
(license #f)))
|
||||||
|
EOF
|
||||||
|
guix package -L "$module_dir" -s dummy-output > /tmp/out
|
||||||
|
test "`guix package -L "$module_dir" -s dummy-output | grep ^name:`" = "name: dummy-package"
|
||||||
|
rm -rf "$module_dir"
|
||||||
|
|
Loading…
Reference in New Issue