guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#71697] [PATCH v5 1/3] scripts: lint: Add 'dry-run' option.


From: Maxim Cournoyer
Subject: [bug#71697] [PATCH v5 1/3] scripts: lint: Add 'dry-run' option.
Date: Fri, 26 Jul 2024 11:06:16 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

Hi,

Simon Tournier <zimon.toutoune@gmail.com> writes:

> * guix/scripts/lint.scm (guix-lint)[show-package-checkers]: New procedure.
> (show-help, %options): Add 'dry-run' option.
> * doc/guix.texi: Document it.
>
> Change-Id: I8c96e376d52c0961ccf2ab39f1fc856c762b089d
> ---
>  doc/guix.texi         |  3 +++
>  guix/scripts/lint.scm | 54 +++++++++++++++++++++++++++++++++++++++----
>  2 files changed, 53 insertions(+), 4 deletions(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 5b77c84b4a..6043962038 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -15463,6 +15463,9 @@ Invoking guix lint
>  List and describe all the available checkers that will be run on packages
>  and exit.
>  
> +@item --dry-run
> +Do not run the checkers.

Maybe, "Show which checkers would run with the provided lint options." ?

>  @item --checkers
>  @itemx -c
>  Only enable the checkers specified in a comma-separated list using the
> diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
> index ee3de51fb1..10abb05cf0 100644
> --- a/guix/scripts/lint.scm
> +++ b/guix/scripts/lint.scm
> @@ -100,6 +100,8 @@ (define (show-help)
>    (display (G_ "Usage: guix lint [OPTION]... [PACKAGE]...
>  Run a set of checkers on the specified package; if none is specified,
>  run the checkers on all packages.\n"))
> +  (display (G_ "
> +      --dry-run          do not run checkers "))

Perhaps, "print the lint checkers that would run" or similar

>    (display (G_ "
>    -c, --checkers=CHECKER1,CHECKER2...
>                           only run the specified checkers"))
> @@ -154,6 +156,9 @@ (define %options
>          (option '(#\n "no-network") #f #f
>                  (lambda (opt name arg result)
>                    (alist-cons 'no-network? #t result)))
> +        (option '("dry-run") #f #f
> +                (lambda (opt name arg result)
> +                  (alist-cons 'dry-run? #t result)))
>          (find (lambda (option)
>                  (member "load-path" (option-names option)))
>                %standard-build-options)
> @@ -218,14 +223,55 @@ (define-command (guix-lint . args)
>                  (proc store))
>                (proc #f)))
>  
> +        (define (show-package-checkers package checkers)
> +          (let* ((name (package-name package))
> +                 (version (package-version package))
> +                 (loc (package-location package))
> +                 (number-checkers (length checkers))
> +                 (number-all-checkers (length %all-checkers)))
> +            (cond
> +             ((= number-all-checkers number-checkers)
> +              (info loc (G_ "~a@~a: all the ~d checkers would run.~%")
> +                    name version
> +                    number-all-checkers))
> +             ((= 0 number-checkers)
> +              (info loc (G_ "~a@~a: none of ~d checkers would run~%")
> +                    name version
> +                    number-all-checkers))
> +             (else
> +              (let* ((excluded-checkers (lset-difference eq? %all-checkers 
> checkers))
> +                     (number-excluded-checkers (length excluded-checkers))
> +                     (number-difference (- number-all-checkers 
> number-excluded-checkers))
> +                     (sorter (lambda (list-checkers)
> +                               (sort (map (compose symbol->string 
> lint-checker-name)
> +                                          list-checkers)
> +                                     string<?))))

Lines should be <= 80 chars, not 100.

> +                (info loc (G_ "~a@~a: ~d/~d checkers would run")
> +                      name version
> +                      number-checkers
> +                      number-all-checkers)
> +                (if (< number-excluded-checkers number-difference)
> +                    (format (current-error-port)
> +                            (G_ " at the exclusion of:~{ ~a~}.~%")
> +                            (sorter excluded-checkers))
> +                    (format (current-error-port)
> +                            ":~{ ~a~}.~%"
> +                            (sorter checkers))))))))
> +
>          (call-maybe-with-store
>           (lambda (store)
>             (cond
>              ((null? args)
> -             (fold-packages (lambda (p r) (run-checkers p checkers
> -                                                        #:store store)) '()))
> +             (when (assoc-ref opts 'dry-run?)
> +               (leave (G_ "too much information to display, did nothing and 
> exit~%") ""))

Here also, the line width doesn't match our convention.

> +             (fold-packages (lambda (p r)
> +                              (unless (assoc-ref opts 'dry-run?)
> +                                  (run-checkers p checkers
> +                                                #:store store))) '()))
>              (else
>               (for-each (lambda (package)
> -                         (run-checkers package checkers
> -                                       #:store store))
> +                         (if (assoc-ref opts 'dry-run?)
> +                             (show-package-checkers package checkers)
> +                             (run-checkers package checkers
> +                                           #:store store)))
>                         args)))))))))

The rest looks reasonable to me, although like Greg I've come to wonder
whether disabling lint checks via package properties is not a bit of a
misfeature since it wouldn't be used by the Guix project itself, and
could lead to misunderstandings.

-- 
Thanks,
Maxim





reply via email to

[Prev in Thread] Current Thread [Next in Thread]