unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars-Dominik Braun <lars@6xq.net>
To: 58136@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>, zimoun <zimon.toutoune@gmail.com>
Subject: [bug#58136] [PATCH] ui: Improve sort order when searching package names.
Date: Fri, 9 Dec 2022 12:49:32 +0100	[thread overview]
Message-ID: <Y5MgzLjZGb49LVa4@noor.fritz.box> (raw)
In-Reply-To: <YzQTieJZSCJGTGY2@noor.fritz.box>

[-- Attachment #1: Type: text/plain, Size: 282 bytes --]

Hi,

attached is version 2 of my initial patch, which simply moves prefix
detection into PACKAGE-UPSTREAM-NAME* (as suggested by Ludo) and reduces
the score to 2 (as suggested by Simon). It’s therefore quite tailored
to the “ggplot2 problem”, but does the job.

Thanks,
Lars


[-- Attachment #2: 0001-packages-Add-package-upstream-name.patch --]
[-- Type: text/plain, Size: 2840 bytes --]

From e0092d786b29f4f1cdc35217212a86804f36cdb4 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Fri, 9 Dec 2022 11:46:37 +0100
Subject: [PATCH v2 1/2] packages: Add 'package-upstream-name*'.

* guix/packages.scm (package-upstream-name*): New procedure.
* tests/packages.scm ("package-upstream-name*"): New test.
---
 guix/packages.scm  | 33 +++++++++++++++++++++++++++++++++
 tests/packages.scm |  4 ++++
 2 files changed, 37 insertions(+)

diff --git a/guix/packages.scm b/guix/packages.scm
index 8f119d9fa7..5e8e3a4ff4 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -89,6 +89,7 @@ (define-module (guix packages)
             this-package
             package-name
             package-upstream-name
+            package-upstream-name*
             package-version
             package-full-name
             package-source
@@ -691,6 +692,38 @@ (define (package-upstream-name package)
   (or (assq-ref (package-properties package) 'upstream-name)
       (package-name package)))
 
+(define (package-upstream-name* package)
+  "Return the upstream name of PACKAGE, accounting for commonly-used
+package name prefixes in addition to the @code{upstream-name} property."
+  (let ((namespaces (list "cl-"
+                          "ecl-"
+                          "emacs-"
+                          "ghc-"
+                          "go-"
+                          "guile-"
+                          "java-"
+                          "julia-"
+                          "lua-"
+                          "minetest-"
+                          "node-"
+                          "ocaml-"
+                          "perl-"
+                          "python-"
+                          "r-"
+                          "ruby-"
+                          "rust-"
+                          "sbcl-"
+                          "texlive-"))
+        (name (package-name package)))
+    (or (assq-ref (package-properties package) 'upstream-name)
+        (let loop ((prefixes namespaces))
+          (match prefixes
+            ('() name)
+            ((prefix rest ...)
+              (if (string-prefix? prefix name)
+                (substring name (string-length prefix))
+                (loop (cdr prefixes)))))))))
+
 (define (hidden-package p)
   "Return a \"hidden\" version of P--i.e., one that 'fold-packages' and thus,
 user interfaces, ignores."
diff --git a/tests/packages.scm b/tests/packages.scm
index a5819d8de3..f58c47817b 100644
--- a/tests/packages.scm
+++ b/tests/packages.scm
@@ -626,6 +626,10 @@ (define read-at
     (build-derivations %store (list drv))
     (call-with-input-file output get-string-all)))
 
+(test-equal "package-upstream-name*"
+  (package-upstream-name* (specification->package "guile-gcrypt"))
+  "gcrypt")
+
 \f
 ;;;
 ;;; Source derivation with snippets.
-- 
2.37.4


[-- Attachment #3: 0002-ui-Take-package-upstream-name-into-account-when-sear.patch --]
[-- Type: text/plain, Size: 746 bytes --]

From 5e0e8c0145a728d0ed49116596f06cc15e1e865d Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Fri, 9 Dec 2022 12:01:31 +0100
Subject: [PATCH v2 2/2] ui: Take package upstream name into account when
 searching.

* guix/ui.scm (%package-metrics): Add PACKAGE-UPSTREAM-NAME*.
---
 guix/ui.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/guix/ui.scm b/guix/ui.scm
index 45eccb7335..3bca3b1e40 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1668,6 +1668,7 @@ (define %package-metrics
   ;; Metrics used to compute the "relevance score" of a package against a set
   ;; of regexps.
   `((,package-name . 4)
+    (,package-upstream-name* . 2)
 
     ;; Match against uncommon outputs.
     (,(lambda (package)
-- 
2.37.4


  parent reply	other threads:[~2022-12-09 11:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  9:27 [bug#58136] [PATCH] ui: Improve sort order when searching package names Lars-Dominik Braun
2022-09-28 14:26 ` zimoun
2022-09-28 20:23   ` Maxime Devos
2022-09-28 20:45     ` Maxime Devos
2022-09-28 21:40     ` zimoun
2022-09-28 21:43       ` Maxime Devos
2022-10-01 21:42   ` Ludovic Courtès
2022-10-02  8:26     ` zimoun
2022-10-12 11:24   ` Lars-Dominik Braun
2022-10-17  7:46     ` Ludovic Courtès
2022-10-17  8:19       ` zimoun
2022-12-09 11:49 ` Lars-Dominik Braun [this message]
2022-12-13 13:28   ` bug#58136: " Ludovic Courtès
2022-12-13 14:53     ` [bug#58136] " Lars-Dominik Braun
2022-12-13 16:40       ` Ludovic Courtès

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

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y5MgzLjZGb49LVa4@noor.fritz.box \
    --to=lars@6xq.net \
    --cc=58136@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).