Subject: [PATCH v5 2/3] scripts: lint: Honor package property to exclude checkers.

From: Simon Tournier <[email-masked]>
Date: Fri, 19 Jul 2024 20:38:09 +0200

* guix/scripts/lint.scm (exclude-package-checkers): New procedure, remove the
checker if the package is marked.
(run-checkers, guix-lint): Use it.
* doc/guix.texi: Document 'lint-excluded-checkers' package property.

Change-Id: Idf8e5c67102a1701ebd917bbc6212cfeb6ea2054
---
 doc/guix.texi         | 16 +++++++++++++++-
 guix/scripts/lint.scm | 16 ++++++++++++++--
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 6043962038..0558532077 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -71,7 +71,7 @@
 Copyright @copyright{} 2019 Alex Griffin@*
 Copyright @copyright{} 2019, 2020, 2021, 2022 Guillaume Le Vaillant@*
 Copyright @copyright{} 2020 Liliana Marie Prikler@*
-Copyright @copyright{} 2019, 2020, 2021, 2022, 2023 Simon Tournier@*
+Copyright @copyright{} 2019, 2020, 2021, 2022, 2023, 2024 Simon Tournier@*
 Copyright @copyright{} 2020 Wiktor Żelazny@*
 Copyright @copyright{} 2020 Damien Cassou@*
 Copyright @copyright{} 2020 Jakub Kądziołka@*
@@ -15448,6 +15448,20 @@ Invoking guix lint
 to the new style.
 @end table
 
+When developing a package, sometimes it is not desired to run the same
+checker each time @command{guix lint} is invoked---e.g., because the
+checker takes time or to avoid to send again and again the same request
+for archiving.  Instead of excluding the checker at the command-line via
+the option @code{--exclude}, the package might be marked to skip the
+checker by honoring the property in package definition, e.g.,
+
+@lisp
+(package
+  (name "python-scikit-learn")
+  ;; @dots{}
+  (properties '((lint-excluded-checkers . (archival home-page)))))
+@end lisp
+
 The general syntax is:
 
 @example
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 10abb05cf0..2df0cba948 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2017 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2017, 2018 Efraim Flashner <[email-masked]>
 ;;; Copyright © 2018, 2019 Arun Isaac <[email-masked]>
-;;; Copyright © 2019, 2020 Simon Tournier <[email-masked]>
+;;; Copyright © 2019, 2020, 2024 Simon Tournier <[email-masked]>
 ;;; Copyright © 2020 Brice Waegeneire <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -59,6 +59,15 @@ (define (emit-warnings warnings)
                name version message))))
    warnings))
 
+(define (exclude-package-checkers package checkers)
+  "Filter the CHECKERS list using PACKAGE properties field."
+  (let* ((properties (package-properties package))
+         (excluded-checkers (or (assq-ref properties 'lint-excluded-checkers)
+                                '())))
+    (remove (lambda (checker)
+              (member (lint-checker-name checker) excluded-checkers))
+            checkers)))
+
 (define* (run-checkers package checkers #:key store)
   "Run the given CHECKERS on PACKAGE."
   (let ((tty? (isatty? (current-error-port))))
@@ -72,7 +81,8 @@ (define* (run-checkers package checkers #:key store)
                  (if (lint-checker-requires-store? checker)
                      ((lint-checker-check checker) package #:store store)
                      ((lint-checker-check checker) package))))
-              checkers)
+              (exclude-package-checkers
+               package checkers))
     (when tty?
       (format (current-error-port) "\x1b[K")
       (force-output (current-error-port)))))
@@ -227,6 +237,8 @@ (define-command (guix-lint . args)
           (let* ((name (package-name package))
                  (version (package-version package))
                  (loc (package-location package))
+                 (checkers (exclude-package-checkers
+                            package checkers))
                  (number-checkers (length checkers))
                  (number-all-checkers (length %all-checkers)))
             (cond
-- 
2.41.0