[PATCH] guix: lint: Add checker to check if inputs are sorted.

  • Done
  • quality assurance status badge
Details
7 participants
  • Arun Isaac
  • Oleg Pykhalov
  • ???
  • Ludovic Courtès
  • Maxim Cournoyer
  • Tobias Geerinckx-Rice
  • swedebugia
Owner
unassigned
Submitted by
Arun Isaac
Severity
normal
A
A
Arun Isaac wrote on 2 Dec 2018 08:42
(address . guix-patches@gnu.org)(name . Arun Isaac)(address . arunisaac@systemreboot.net)
20181202074210.31361-1-arunisaac@systemreboot.net
* guix/scripts/lint.scm (check-inputs-should-be-sorted): New procedure.
(%checkers): Add it.
---
guix/scripts/lint.scm | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

Toggle diff (48 lines)
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 2314f3b28..37e8a1ec5 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -8,6 +8,7 @@
;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
+;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -301,6 +302,22 @@ of a package, and INPUT-NAMES, a list of package specifications such as
(package-input-intersection (package-direct-inputs package)
input-names))))
+(define (check-inputs-should-be-sorted package)
+ ;; Emit a warning if inputs, native inputs or propagated inputs of PACKAGE
+ ;; are not lexicographically ordered.
+ (define (check-inputs inputs-accessor input-type)
+ (unless (sorted? (map (match-lambda
+ ((name input) name))
+ (inputs-accessor package))
+ string<?)
+ (emit-warning
+ package
+ (format #f (G_ "~a should be in lexicographic order") input-type))))
+
+ (check-inputs package-inputs (G_ "inputs"))
+ (check-inputs package-native-inputs (G_ "native inputs"))
+ (check-inputs package-propagated-inputs (G_ "propagated inputs")))
+
(define (package-name-regexp package)
"Return a regexp that matches PACKAGE's name as a word at the beginning of a
line."
@@ -1032,6 +1049,10 @@ them for PACKAGE."
(name 'inputs-should-not-be-input)
(description "Identify inputs that shouldn't be inputs at all")
(check check-inputs-should-not-be-an-input-at-all))
+ (lint-checker
+ (name 'inputs-should-be-sorted)
+ (description "Verify that inputs are in lexicographic order")
+ (check check-inputs-should-be-sorted))
(lint-checker
(name 'patch-file-names)
(description "Validate file names and availability of patches")
--
2.19.1
L
L
Ludovic Courtès wrote on 3 Dec 2018 14:31
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 33575@debbugs.gnu.org)
87y3967n3z.fsf@gnu.org
Hello,

Arun Isaac <arunisaac@systemreboot.net> skribis:

Toggle quote (26 lines)
> * guix/scripts/lint.scm (check-inputs-should-be-sorted): New procedure.
> (%checkers): Add it.
> ---
> guix/scripts/lint.scm | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
> index 2314f3b28..37e8a1ec5 100644
> --- a/guix/scripts/lint.scm
> +++ b/guix/scripts/lint.scm
> @@ -8,6 +8,7 @@
> ;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
> ;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
> ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il>
> +;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -301,6 +302,22 @@ of a package, and INPUT-NAMES, a list of package specifications such as
> (package-input-intersection (package-direct-inputs package)
> input-names))))
>
> +(define (check-inputs-should-be-sorted package)
> + ;; Emit a warning if inputs, native inputs or propagated inputs of PACKAGE
> + ;; are not lexicographically ordered.

It’s something we rarely do so we’d get warnings for most packages. As
a side effect, people may pay less attention to what ‘guix lint’ says.

As for the goal itself, I think sorting is a good idea when there are
lots of inputs (things like IceCat), but otherwise I personally don’t
think it matters that much.

What do people think?

Thanks,
Ludo’.
O
O
Oleg Pykhalov wrote on 6 Dec 2018 01:42
(name . Ludovic Courtès)(address . ludo@gnu.org)
87k1knpjta.fsf@gmail.com
Hello,

ludo@gnu.org (Ludovic Courtès) writes:

[…]

Toggle quote (3 lines)
> It’s something we rarely do so we’d get warnings for most packages. As
> a side effect, people may pay less attention to what ‘guix lint’ says.

I think this should not stop us from improving a linter and an option
like --misc-checks=sort-input,foo,bar could be used for such cases.

[…]

Oleg.
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEcjhxI46s62NFSFhXFn+OpQAa+pwFAlwIcHEACgkQFn+OpQAa
+pyBnhAAicRVr9oSkGLOEMlUMqbkj3J3F3j7VbY1c5QCxnD7TOC3GqaaeowLz/OT
W6KSQFFvqSZGeJKhRejA2Fkrgh5HAr24+zQxJPqJqn+mtc4O/7Oga5oM/8IJ4frP
v6q82YJGaAaE0rTHpiB696L4Ie1IKYCMrHQe3ZwWdum/DA47wU6e+yL+3qI6/zWX
vP773ts07wQMn0jL3a69Y/7eFHh/tXJUdrrSdV5IRiuFFDPKIgVG58foGG2BBCsu
0qPknTPk3YURsQ7sV9HXxQQmx6XRJl8tuNWTM9CRrL6H7JkPiFJfFU1ijO8CtCpx
O+NkrgAAuOuV40Y/+IdSOa6oNVusE93DS+DQPa70mEgys8ftwERJK6Ln+e1fbc/g
ETTEIWIYfKyJcbOq0tykfy7UFSnJEvtHk/VgZB4pCO2TTameR7MmiW+x6PcslBXm
L0c+65DlHGrvsXm97bczZiEzNEsERFDJklyxgW7gi466KjpkF52FFRvJiihxfqW5
fKc/f1tAeDz2e+ZgqNNRucdX3AAMw+pNJJ6DGPcE1dy8VeD7SHwY4aohDxeexRjW
Slol9vZtg9U7RjziSTRbhp+aFDkzdnJkZtlZsNd+AnJNSVCxmkq7WFzFvjoHMELk
hwhV/FQvi9rmfiI6gKUqe3TXBk536HL4OshpCC6/iduHHW9LXYk=
=+G1B
-----END PGP SIGNATURE-----

S
S
swedebugia wrote on 6 Dec 2018 13:31
(name . Oleg Pykhalov)(address . go.wigust@gmail.com)
1f7a7e5589c465c0ad913b388374cf4b@riseup.net
On 2018-12-06 01:42, Oleg Pykhalov wrote:
Toggle quote (12 lines)
> Hello,
>
> ludo@gnu.org (Ludovic Courtès) writes:
>
> […]
>
>> It’s something we rarely do so we’d get warnings for most packages. As
>> a side effect, people may pay less attention to what ‘guix lint’ says.
>
> I think this should not stop us from improving a linter and an option
> like --misc-checks=sort-input,foo,bar could be used for such cases.

I agree with Oleg here.

If many packages needs inputs to be sorted lets write a guix lint --sort
modelling the updater (that is make the changes in the work tree to be
committed).

--
Cheers
Swedebugia
M
M
Maxim Cournoyer wrote on 7 Dec 2018 14:08
(address . swedebugia@riseup.net)
87zhthmqma.fsf@gmail.com
swedebugia@riseup.net writes:

Toggle quote (19 lines)
> On 2018-12-06 01:42, Oleg Pykhalov wrote:
>> Hello,
>>
>> ludo@gnu.org (Ludovic Courtès) writes:
>>
>> […]
>>
>>> It’s something we rarely do so we’d get warnings for most packages. As
>>> a side effect, people may pay less attention to what ‘guix lint’ says.
>>
>> I think this should not stop us from improving a linter and an option
>> like --misc-checks=sort-input,foo,bar could be used for such cases.
>
> I agree with Oleg here.
>
> If many packages needs inputs to be sorted lets write a guix lint --sort
> modelling the updater (that is make the changes in the work tree to be
> committed).

+1
?
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 33575@debbugs.gnu.org)
87sgz8ekvk.fsf@member.fsf.org
Arun Isaac <arunisaac@systemreboot.net> writes:

Toggle quote (8 lines)
> * guix/scripts/lint.scm (check-inputs-should-be-sorted): New procedure.
> (%checkers): Add it.
> [...]
>
> +(define (check-inputs-should-be-sorted package)
> + ;; Emit a warning if inputs, native inputs or propagated inputs of PACKAGE
> + ;; are not lexicographically ordered.

Hello, consider 'gspell', it has some native-inputs for build and some
for test:

(native-inputs
`(("glib" ,glib "bin")
("pkg-config" ,pkg-config)
("xmllint" ,libxml2)

;; For tests.
("aspell-dict-en" ,aspell-dict-en)
("xorg-server" ,xorg-server)))

Currently I'd seperated them by a comment like this.

If they are sorted, I have to add comment for each test input:

`(("aspell-dict-en", aspecll-dict-en) ; for test
("glib" ,glib "bin")
("pkg-config" ,pkg-config)
("xmllint" ,libxml2)
("xorg-server" ,xorg-server)) ; for test

Which will be a little annoying...
T
T
Tobias Geerinckx-Rice wrote on 4 Dec 2018 10:13
(name . Ludovic =?utf-8?Q?Court=C3=A8s?=)(address . ludo@gnu.org)
87woopk639.fsf@nckx
Ludo', Arun,

Ludovic Courtès wrote:
Toggle quote (10 lines)
>> + ;; Emit a warning if inputs, native inputs or propagated
>> inputs
>> of PACKAGE
>> + ;; are not lexicographically ordered.
>
> It's something we rarely do so we'd get warnings for most
> packages. As
> a side effect, people may pay less attention to what ‘guix lint’
> says.

Even I agree :-) There are valid reasons not to sort them.

Toggle quote (6 lines)
> As for the goal itself, I think sorting is a good idea when
> there are
> lots of inputs (things like IceCat), but otherwise I personally
> don't
> think it matters that much.

Do we already check for duplication?

I sometimes order inputs for the same reason I sort module
imports: to catch duplicates. These are usually harmless and
produce no errors.

Kind regards,

T G-R
S
S
swedebugia wrote on 8 Dec 2018 08:58
(address . iyzsong@member.fsf.org)
f2b8429f1eaf8611fcb148c055733e04@riseup.net
On 2018-12-08 04:51, iyzsong@member.fsf.org wrote:
Toggle quote (34 lines)
> Arun Isaac <arunisaac@systemreboot.net> writes:
>
>> * guix/scripts/lint.scm (check-inputs-should-be-sorted): New procedure.
>> (%checkers): Add it.
>> [...]
>>
>> +(define (check-inputs-should-be-sorted package)
>> + ;; Emit a warning if inputs, native inputs or propagated inputs of PACKAGE
>> + ;; are not lexicographically ordered.
>
> Hello, consider 'gspell', it has some native-inputs for build and some
> for test:
>
> (native-inputs
> `(("glib" ,glib "bin")
> ("pkg-config" ,pkg-config)
> ("xmllint" ,libxml2)
>
> ;; For tests.
> ("aspell-dict-en" ,aspell-dict-en)
> ("xorg-server" ,xorg-server)))
>
> Currently I'd seperated them by a comment like this.
>
> If they are sorted, I have to add comment for each test input:
>
> `(("aspell-dict-en", aspecll-dict-en) ; for test
> ("glib" ,glib "bin")
> ("pkg-config" ,pkg-config)
> ("xmllint" ,libxml2)
> ("xorg-server" ,xorg-server)) ; for test
>
> Which will be a little annoying...

You convinced me sorting is a bad idea. Thanks for providing a good
argument :)

--
Cheers
Swedebugia
L
L
Ludovic Courtès wrote on 8 Dec 2018 14:29
(name . Tobias Geerinckx-Rice)(address . somebody@not-sent-or-endorsed-by.tobias.gr)
87zhtg87u2.fsf@gnu.org
Hello,

Tobias Geerinckx-Rice <somebody@not-sent-or-endorsed-by.tobias.gr>
skribis:

Toggle quote (2 lines)
> Ludovic Courtès wrote:

[...]

Toggle quote (8 lines)
>> As for the goal itself, I think sorting is a good idea when
>> there are
>> lots of inputs (things like IceCat), but otherwise I personally
>> don't
>> think it matters that much.
>
> Do we already check for duplication?

No but it would be a worthy check!

Ludo’.
A
A
Arun Isaac wrote on 8 Dec 2018 14:34
(name . ???)(address . iyzsong@member.fsf.org)(address . 33575@debbugs.gnu.org)
cu7tvjo3zwo.fsf@systemreboot.net
Toggle quote (10 lines)
> If they are sorted, I have to add comment for each test input:
>
> `(("aspell-dict-en", aspecll-dict-en) ; for test
> ("glib" ,glib "bin")
> ("pkg-config" ,pkg-config)
> ("xmllint" ,libxml2)
> ("xorg-server" ,xorg-server)) ; for test
>
> Which will be a little annoying...

I too find this convincing. It's not a good idea to enforce sorted
inputs all the time. If there is sufficient consensus, we can close this
bug report.
M
M
Maxim Cournoyer wrote on 9 Dec 2018 23:49
(name . Arun Isaac)(address . arunisaac@systemreboot.net)
87efaql3hy.fsf@gmail.com
Hi,

Arun Isaac <arunisaac@systemreboot.net> writes:

Toggle quote (14 lines)
>> If they are sorted, I have to add comment for each test input:
>>
>> `(("aspell-dict-en", aspecll-dict-en) ; for test
>> ("glib" ,glib "bin")
>> ("pkg-config" ,pkg-config)
>> ("xmllint" ,libxml2)
>> ("xorg-server" ,xorg-server)) ; for test
>>
>> Which will be a little annoying...
>
> I too find this convincing. It's not a good idea to enforce sorted
> inputs all the time. If there is sufficient consensus, we can close this
> bug report.

Maybe our test inputs should have their own field? This would make their
raison d'être explicit and remove the need of using comments.

Maxim
?
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 33575@debbugs.gnu.org)
87a7ldmxxd.fsf@member.fsf.org
Arun Isaac <arunisaac@systemreboot.net> writes:

Toggle quote (14 lines)
>> If they are sorted, I have to add comment for each test input:
>>
>> `(("aspell-dict-en", aspecll-dict-en) ; for test
>> ("glib" ,glib "bin")
>> ("pkg-config" ,pkg-config)
>> ("xmllint" ,libxml2)
>> ("xorg-server" ,xorg-server)) ; for test
>>
>> Which will be a little annoying...
>
> I too find this convincing. It's not a good idea to enforce sorted
> inputs all the time. If there is sufficient consensus, we can close this
> bug report.

Yes, I think so. Thank you!
?
(name . Maxim Cournoyer)(address . maxim.cournoyer@gmail.com)
875zw1mwq3.fsf@member.fsf.org
Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

Toggle quote (21 lines)
> Hi,
>
> Arun Isaac <arunisaac@systemreboot.net> writes:
>
>>> If they are sorted, I have to add comment for each test input:
>>>
>>> `(("aspell-dict-en", aspecll-dict-en) ; for test
>>> ("glib" ,glib "bin")
>>> ("pkg-config" ,pkg-config)
>>> ("xmllint" ,libxml2)
>>> ("xorg-server" ,xorg-server)) ; for test
>>>
>>> Which will be a little annoying...
>>
>> I too find this convincing. It's not a good idea to enforce sorted
>> inputs all the time. If there is sufficient consensus, we can close this
>> bug report.
>
> Maybe our test inputs should have their own field? This would make their
> raison d'être explicit and remove the need of using comments.

Yeah, something like:

(package
...
(inputs ...)
(test:inputs ...)
(test:native-inputs ...))

If we plan to support build packages with tests disabled, this would be
the way to go. And due to how build works in guix, if tests are
disabled, it would be considered as a different derivation/package, so
the main use case may be:

- I disable substitute servers to build all packages from sources
locally.
- I want to disable tests for some packages as they are too slow...

I don't have this use case now, and seperate package inputs will be a
big change, so I think the current way is totally ok.
A
A
Arun Isaac wrote on 18 Dec 2018 21:36
(address . 33575-done@debbugs.gnu.org)
cu7tvjao9lo.fsf@systemreboot.net
I'm closing this bug report since I believe we have reached a consensus
that this patch is unnecessary. Thank you all for your thoughts!
Closed
?