import: github: Sort releases before picking the latest one.

DoneSubmitted by Arun Isaac.
A
Arun Isaac wrote on Sat May 11 16:53:21+0530 2019
(address . guix-patches@gnu.org)
cu7h8a19qvq.fsf@systemreboot.net
Prior to this, for some packages (e.g., osc in (gnu packages
build-tools)), `guix refresh' could not find the latest version
correctly.
From 33f42ea8a33c6e502062708336a5ab8be871c92b Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Sat, 11 May 2019 16:40:38 +0530
Subject: [PATCH] import: github: Sort releases before picking the latest one.

* guix/import/github.scm (latest-released-version): Sort releases before
picking the first one as the latest.
---
guix/import/github.scm | 55 ++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index 4d12339204..a8af318bc8 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -183,32 +183,35 @@ API when using a GitHub token")
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens"))
- (any
- (lambda (release)
- (let ((tag (or (hash-ref release "tag_name") ;a "release"
- (hash-ref release "name"))) ;a tag
- (name-length (string-length package-name)))
- (cond
- ;; some tags include the name of the package e.g. "fdupes-1.51"
- ;; so remove these
- ((and (< name-length (string-length tag))
- (string=? (string-append package-name "-")
- (substring tag 0 (+ name-length 1))))
- (substring tag (+ name-length 1)))
- ;; some tags start with a "v" e.g. "v0.25.0"
- ;; where some are just the version number
- ((string-prefix? "v" tag)
- (substring tag 1))
- ;; Finally, reject tags that don't start with a digit:
- ;; they may not represent a release.
- ((and (not (string-null? tag))
- (char-set-contains? char-set:digit
- (string-ref tag 0)))
- tag)
- (else #f))))
- (match (remove pre-release? json)
- (() json) ; keep everything
- (releases releases))))))
+ (first
+ (sort
+ (filter-map
+ (lambda (release)
+ (let ((tag (or (hash-ref release "tag_name") ;a "release"
+ (hash-ref release "name"))) ;a tag
+ (name-length (string-length package-name)))
+ (cond
+ ;; some tags include the name of the package e.g. "fdupes-1.51"
+ ;; so remove these
+ ((and (< name-length (string-length tag))
+ (string=? (string-append package-name "-")
+ (substring tag 0 (+ name-length 1))))
+ (substring tag (+ name-length 1)))
+ ;; some tags start with a "v" e.g. "v0.25.0"
+ ;; where some are just the version number
+ ((string-prefix? "v" tag)
+ (substring tag 1))
+ ;; Finally, reject tags that don't start with a digit:
+ ;; they may not represent a release.
+ ((and (not (string-null? tag))
+ (char-set-contains? char-set:digit
+ (string-ref tag 0)))
+ tag)
+ (else #f))))
+ (match (remove pre-release? json)
+ (() json) ; keep everything
+ (releases releases)))
+ version>?)))))

(define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG."
--
2.21.0
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzWsKoACgkQLiXui2GA
K7NdjwgAqQ/YarcqTl9yArKcCvLRCXq0Ta/Y3ZDRf2qz2mTRs/3bPivIQEG+5oJf
BPnlrSA6NQIrku7tM/ryRtNQGag/O8yUEdi496vU7mxa1X6jJlxXYaLOKGat7wp6
ZN6QrjKhx5oUlYUXEtuhRHgLUUlQvTQ95oFhVvP8jf8lC0E3va115Mt3KXMLTm3p
easLET250+FnP5P3Q6+L4XtJ0Wwro7Y6UKnpCeUgI9DcZ0FvVYrbMSbx4wTtf1OT
872RXgiB5JCLxXaqUP+G+96U1+sfZWfnu4tX+QYljQ1wNSMUwd9DZ5QlytvHiOQj
NtkRv8W24JRwrPVphqCEPcrJ7WkqNg==
=vJPD
-----END PGP SIGNATURE-----
L
Ludovic Courtès wrote on Sun May 12 23:47:06+0200 2019
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 35684@debbugs.gnu.org)
87mujrs5ut.fsf@gnu.org
Arun Isaac <arunisaac@systemreboot.net> skribis:

> Prior to this, for some packages (e.g., osc in (gnu packages
> build-tools)), `guix refresh' could not find the latest version
> correctly.

Good catch.

> From 33f42ea8a33c6e502062708336a5ab8be871c92b Mon Sep 17 00:00:00 2001
> From: Arun Isaac <arunisaac@systemreboot.net>
> Date: Sat, 11 May 2019 16:40:38 +0530
> Subject: [PATCH] import: github: Sort releases before picking the latest one.
>
> * guix/import/github.scm (latest-released-version): Sort releases before
> picking the first one as the latest.

[...]

> + (first
> + (sort
> + (filter-map
> + (lambda (release)
> + (let ((tag (or (hash-ref release "tag_name") ;a "release"
> + (hash-ref release "name"))) ;a tag
> + (name-length (string-length package-name)))
> + (cond
> + ;; some tags include the name of the package e.g. "fdupes-1.51"
> + ;; so remove these
> + ((and (< name-length (string-length tag))
> + (string=? (string-append package-name "-")
> + (substring tag 0 (+ name-length 1))))
> + (substring tag (+ name-length 1)))
> + ;; some tags start with a "v" e.g. "v0.25.0"
> + ;; where some are just the version number
> + ((string-prefix? "v" tag)
> + (substring tag 1))
> + ;; Finally, reject tags that don't start with a digit:
> + ;; they may not represent a release.
> + ((and (not (string-null? tag))
> + (char-set-contains? char-set:digit
> + (string-ref tag 0)))
> + tag)
> + (else #f))))
> + (match (remove pre-release? json)
> + (() json) ; keep everything
> + (releases releases)))
> + version>?)))))

LGTM, but…

… while you’re at it, would you mind cleaning this up a bit? :-)
Namely, I think this big ‘lambda’ could be given a name and moved out of
the way to make ‘latest-released-version’ easier to read. Also, it
would probably be reasonable to avoid ‘first’ and instead write:

(match (sort …)
((first . _) first)
(()
(leave (G_ "no releases found etc.~%"))))

WDYT? :-)

If you’d rather leave that for later, you can also just go ahead and
commit your patch.

Thanks,
Ludo’.


A
Arun Isaac wrote on Mon May 13 13:38:37+0530 2019
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 35684@debbugs.gnu.org)
cu7zhnq93p6.fsf@systemreboot.net
> Namely, I think this big ‘lambda’ could be given a name and moved out of
> the way to make ‘latest-released-version’ easier to read. Also, it
> would probably be reasonable to avoid ‘first’ and instead write:
>
> (match (sort …)
> ((first . _) first)
> (()
> (leave (G_ "no releases found etc.~%"))))
>
> WDYT? :-)
>
> If you’d rather leave that for later, you can also just go ahead and
> commit your patch.

No problem! :-) Here is the updated patch.
From d3f28de8fedc41732a07edf2ea91222208ccc73f Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Sat, 11 May 2019 16:40:38 +0530
Subject: [PATCH] import: github: Sort releases before picking the latest one.

* guix/import/github.scm (latest-released-version): Sort releases before
picking the first one as the latest.
---
guix/import/github.scm | 56 ++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index 4d12339204..cdac70420a 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -174,6 +174,29 @@ the package e.g. 'bedtools2'. Return #f if there is no releases"
(define (pre-release? x)
(hash-ref x "prerelease"))

+ (define (release->version release)
+ (let ((tag (or (hash-ref release "tag_name") ;a "release"
+ (hash-ref release "name"))) ;a tag
+ (name-length (string-length package-name)))
+ (cond
+ ;; some tags include the name of the package e.g. "fdupes-1.51"
+ ;; so remove these
+ ((and (< name-length (string-length tag))
+ (string=? (string-append package-name "-")
+ (substring tag 0 (+ name-length 1))))
+ (substring tag (+ name-length 1)))
+ ;; some tags start with a "v" e.g. "v0.25.0"
+ ;; where some are just the version number
+ ((string-prefix? "v" tag)
+ (substring tag 1))
+ ;; Finally, reject tags that don't start with a digit:
+ ;; they may not represent a release.
+ ((and (not (string-null? tag))
+ (char-set-contains? char-set:digit
+ (string-ref tag 0)))
+ tag)
+ (else #f))))
+
(let* ((json (fetch-releases-or-tags url)))
(if (eq? json #f)
(if (%github-token)
@@ -183,32 +206,13 @@ API when using a GitHub token")
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens"))
- (any
- (lambda (release)
- (let ((tag (or (hash-ref release "tag_name") ;a "release"
- (hash-ref release "name"))) ;a tag
- (name-length (string-length package-name)))
- (cond
- ;; some tags include the name of the package e.g. "fdupes-1.51"
- ;; so remove these
- ((and (< name-length (string-length tag))
- (string=? (string-append package-name "-")
- (substring tag 0 (+ name-length 1))))
- (substring tag (+ name-length 1)))
- ;; some tags start with a "v" e.g. "v0.25.0"
- ;; where some are just the version number
- ((string-prefix? "v" tag)
- (substring tag 1))
- ;; Finally, reject tags that don't start with a digit:
- ;; they may not represent a release.
- ((and (not (string-null? tag))
- (char-set-contains? char-set:digit
- (string-ref tag 0)))
- tag)
- (else #f))))
- (match (remove pre-release? json)
- (() json) ; keep everything
- (releases releases))))))
+ (match (sort (filter-map release->version
+ (match (remove pre-release? json)
+ (() json) ; keep everything
+ (releases releases)))
+ version>?)
+ ((latest-release . _) latest-release)
+ (() #f)))))

(define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG."
--
2.21.0
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzZJgUACgkQLiXui2GA
K7O7jQf/eXgA1csQzNoh9vbbaBl+LkHeniV6rinV/90/ml+2/xkYjFOzmLrL4i7y
B1KKfFjgNezcL9AWvr1XJSrPRnZV/ERhSkgIAxSaZPRD7BgkmAfYo2kSBu9XWYjO
ljMc72/Oqd2cSxfkGJbNf2sAG/LgabLxnSZ8Avfgh6l77LzCYgCoyt0Ytf/N1PU3
k295117JlnGRoyb0O5lJVKNPk0x7dhz87BU7tTowa1O5hMSrNXiPcXhg5ov1Gx41
sb4sW8asgU7JPxprxVlMe1oHZaY3s0sTgLPkRYc6d8rqkdAooz7TWn48Jy6TaUAw
Pb0v8GSAXtkVo0LxWs4agGUw5Tw2yg==
=6lPO
-----END PGP SIGNATURE-----
L
Ludovic Courtès wrote on Mon May 13 15:42:57+0200 2019
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 35684@debbugs.gnu.org)
87d0kmsc66.fsf@gnu.org
Arun Isaac <arunisaac@systemreboot.net> skribis:

> From d3f28de8fedc41732a07edf2ea91222208ccc73f Mon Sep 17 00:00:00 2001
> From: Arun Isaac <arunisaac@systemreboot.net>
> Date: Sat, 11 May 2019 16:40:38 +0530
> Subject: [PATCH] import: github: Sort releases before picking the latest one.
>
> * guix/import/github.scm (latest-released-version): Sort releases before
> picking the first one as the latest.

Very nice, LGTM! If you don’t mind, you can make it two patches for
clarity (one that defines ‘release->version’, and one that adds the call
to ‘sort’); otherwise just amend the commit log above to mention
‘release->version’.

Thank you!

Ludo’.


A
Arun Isaac wrote on Tue May 14 15:49:08+0530 2019
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 35684@debbugs.gnu.org)
cu7y3398hk3.fsf@systemreboot.net
> If you don’t mind, you can make it two patches for clarity (one that
> defines ‘release->version’, and one that adds the call to ‘sort’)

Sure, pleae find attached.
From c96956bc6e944f9691773640e402c15215078943 Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Tue, 14 May 2019 15:44:46 +0530
Subject: [PATCH 1/2] import: github: Improve readability.

* guix/import/github.scm (latest-released-version)[release->version]: Separate
out release->version as a new function.
---
guix/import/github.scm | 53 +++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index 4d12339204..5f4d9c7267 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -174,6 +174,29 @@ the package e.g. 'bedtools2'. Return #f if there is no releases"
(define (pre-release? x)
(hash-ref x "prerelease"))

+ (define (release->version release)
+ (let ((tag (or (hash-ref release "tag_name") ;a "release"
+ (hash-ref release "name"))) ;a tag
+ (name-length (string-length package-name)))
+ (cond
+ ;; some tags include the name of the package e.g. "fdupes-1.51"
+ ;; so remove these
+ ((and (< name-length (string-length tag))
+ (string=? (string-append package-name "-")
+ (substring tag 0 (+ name-length 1))))
+ (substring tag (+ name-length 1)))
+ ;; some tags start with a "v" e.g. "v0.25.0"
+ ;; where some are just the version number
+ ((string-prefix? "v" tag)
+ (substring tag 1))
+ ;; Finally, reject tags that don't start with a digit:
+ ;; they may not represent a release.
+ ((and (not (string-null? tag))
+ (char-set-contains? char-set:digit
+ (string-ref tag 0)))
+ tag)
+ (else #f))))
+
(let* ((json (fetch-releases-or-tags url)))
(if (eq? json #f)
(if (%github-token)
@@ -183,32 +206,10 @@ API when using a GitHub token")
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens"))
- (any
- (lambda (release)
- (let ((tag (or (hash-ref release "tag_name") ;a "release"
- (hash-ref release "name"))) ;a tag
- (name-length (string-length package-name)))
- (cond
- ;; some tags include the name of the package e.g. "fdupes-1.51"
- ;; so remove these
- ((and (< name-length (string-length tag))
- (string=? (string-append package-name "-")
- (substring tag 0 (+ name-length 1))))
- (substring tag (+ name-length 1)))
- ;; some tags start with a "v" e.g. "v0.25.0"
- ;; where some are just the version number
- ((string-prefix? "v" tag)
- (substring tag 1))
- ;; Finally, reject tags that don't start with a digit:
- ;; they may not represent a release.
- ((and (not (string-null? tag))
- (char-set-contains? char-set:digit
- (string-ref tag 0)))
- tag)
- (else #f))))
- (match (remove pre-release? json)
- (() json) ; keep everything
- (releases releases))))))
+ (any release->version
+ (match (remove pre-release? json)
+ (() json) ; keep everything
+ (releases releases))))))

(define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG."
--
2.21.0
From 8192712f8108d0abcd527ff6b16af073c453b780 Mon Sep 17 00:00:00 2001
From: Arun Isaac <arunisaac@systemreboot.net>
Date: Tue, 14 May 2019 15:46:19 +0530
Subject: [PATCH 2/2] import: github: Sort releases before picking the latest
one.

* guix/import/github.scm (latest-released-version): Sort releases before
picking the first one as the latest.
---
guix/import/github.scm | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/guix/import/github.scm b/guix/import/github.scm
index 5f4d9c7267..cdac70420a 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -206,10 +206,13 @@ API when using a GitHub token")
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens"))
- (any release->version
- (match (remove pre-release? json)
- (() json) ; keep everything
- (releases releases))))))
+ (match (sort (filter-map release->version
+ (match (remove pre-release? json)
+ (() json) ; keep everything
+ (releases releases)))
+ version>?)
+ ((latest-release . _) latest-release)
+ (() #f)))))

(define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG."
--
2.21.0
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzalhwACgkQLiXui2GA
K7PzBAgAoyQgzvScfXVyu3WxGjqIydu+o3e4bzwrPP7VvZWLMky+km0rYjxqrcyo
vAADbQp1jLKOYAiKBFpyHj7p84H9TSv4PY/QMlbRrROgl06SPo64IbN/v8cZCzi4
kq7U0ALlLgj2XapAa1LNoc1stfxR+CTj9QRVdnzXrPBKM58gg8Z0KXPvfQrJBnLh
2i4MMkud9dziXvn3yUGPHvKMKH6k0F1lPJ/iXnXd2zeMnTzVIfPF2CreGg9JXk3i
uUbbwtnW9vjBPcawdU4YSGIGrDnIC3nqRjJXKNJk/88wxiMMG+IapkJ1MK5o9v4z
CD6IeRzEKc8bWDPi1r8D+HYeilGMdg==
=Wc/a
-----END PGP SIGNATURE-----
L
Ludovic Courtès wrote on Tue May 14 22:59:34+0200 2019
(name . Arun Isaac)(address . arunisaac@systemreboot.net)(address . 35684@debbugs.gnu.org)
87tvdwwy4p.fsf@gnu.org
Arun Isaac <arunisaac@systemreboot.net> skribis:

>> If you don’t mind, you can make it two patches for clarity (one that
>> defines ‘release->version’, and one that adds the call to ‘sort’)
>
> Sure, pleae find attached.

Thank you, it still LGTM. :-)

Ludo’.


A
Arun Isaac wrote on Wed May 15 13:55:35+0530 2019
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 35684-done@debbugs.gnu.org)
cu77eas86ps.fsf@systemreboot.net
Pushed to master, thanks!
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzbzP8ACgkQLiXui2GA
K7MGjAgAx7hqY3JZmUSRupNO1F5QrsdjBCY7vaNZ6ux0C0tgJxaf3uvVQZrN6hNE
4H+4vnApCgoQn4ulZfT6qnZKcocyx9jn5o67rr7aN+dinNxPyLfDCcFmVZ8hLI17
IIV0CqSY3acPwo9j0WNmnrchrRRnBv7Em/bcm3S5hWLyUqG2eprbJxTzNZHXAsup
um11iJz2GhEeXMakfrE0cBuh39abysBqjLzQ/s2pM8dx33cyt2cJE2kbw0+WD5TI
+1TR5tIR35dVcMRDl7cf4Ka6x5CtMVh+CnXvB9LvBK4vJ2G76Z71GfsVMW0/hLBM
YAAQvdUPlZIhSbNmNjx6dAOMQD/+Gg==
=iFRv
-----END PGP SIGNATURE-----
Closed
?
Your comment

Comments via the web interface are not currently supported. To comment on this conversation send email to 35684@debbugs.gnu.org

  • Arun Isaac
  • Ludovic Courtès
unassigned
normal
Done