unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Bavier <ericbavier@openmailbox.org>
To: Mark H Weaver <mhw@netris.org>
Cc: guix-devel@gnu.org, Eric Bavier <bavier@member.fsf.org>
Subject: Re: [PATCH] guix: lint: Check for version-only origin file names.
Date: Mon, 24 Aug 2015 19:10:24 -0500	[thread overview]
Message-ID: <20150824191024.3da87f41@openmailbox.org> (raw)
In-Reply-To: <87pp2cmgss.fsf@netris.org>

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

On Mon, 24 Aug 2015 19:02:11 -0400
Mark H Weaver <mhw@netris.org> wrote:

> ericbavier@openmailbox.org writes:
> 
> > From: Eric Bavier <bavier@member.fsf.org>
> >
> > * guix/scripts/lint.scm (check-source): Emit warning if source filename
> >   contains only the version of the package.
> 
> This is not a proper review, but I just wanted to add that another
> common case is for the filename to start with "v" followed by the
> version number, e.g. "v3.2.0.tar.gz", so it would be good to check for
> that too.

Indeed.  Attached is an updated patch, with tests and documentation
too! :)
 
> Thank you for working on it!

My pleasure.

`~Eric

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-lint-Check-for-version-only-origin-file-names.patch --]
[-- Type: text/patch, Size: 11440 bytes --]

From 0311d5b383003600ac43d3a9bfdec0ad3c398db2 Mon Sep 17 00:00:00 2001
From: Eric Bavier <bavier@member.fsf.org>
Date: Sun, 23 Aug 2015 18:00:45 -0500
Subject: [PATCH] guix: lint: Check for version-only origin file names.

* guix/scripts/lint.scm (check-source): Emit warning if source filename
  contains only the version of the package.
* tests/lint.scm ("source: filename", "source: filename v",
  "source: filename valid"): New tests.
* doc/guix.texi (Invoking guix lint): Mention file name check.
Offending packages updated.
---
 doc/guix.texi                   |  3 +-
 gnu/packages/algebra.scm        |  1 +
 gnu/packages/audio.scm          |  2 ++
 gnu/packages/bioinformatics.scm |  1 +
 gnu/packages/python.scm         |  1 +
 gnu/packages/telephony.scm      |  3 +-
 gnu/packages/textutils.scm      |  1 +
 guix/scripts/lint.scm           | 68 ++++++++++++++++++++++++++---------------
 tests/lint.scm                  | 43 ++++++++++++++++++++++++++
 9 files changed, 96 insertions(+), 27 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f05376e..153af45 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4133,7 +4133,8 @@ Identify inputs that should most likely be native inputs.
 @item source
 @itemx home-page
 Probe @code{home-page} and @code{source} URLs and report those that are
-invalid.
+invalid.  Check that the source file name contains something other than
+just the version number.
 
 @item formatting
 Warn about obvious source code formatting issues: trailing white space,
diff --git a/gnu/packages/algebra.scm b/gnu/packages/algebra.scm
index 3f23ec9..03019f8 100644
--- a/gnu/packages/algebra.scm
+++ b/gnu/packages/algebra.scm
@@ -386,6 +386,7 @@ cosine/ sine transforms or DCT/DST).")
               (method url-fetch)
               (uri (string-append "https://bitbucket.org/eigen/eigen/get/"
                                   version ".tar.bz2"))
+              (file-name (string-append name "-" version ".tar.bz2"))
               (sha256
                (base32
                 "1yf27mfq1x38wlsghkvpjgs8xd5rvbbikf1wyj2l3qw8h6w6qvjz"))
diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm
index 1537f33..d28fa09 100644
--- a/gnu/packages/audio.scm
+++ b/gnu/packages/audio.scm
@@ -1135,6 +1135,7 @@ aimed at audio/musical applications.")
                (string-append "https://bitbucket.org/breakfastquay/rubberband/get/v"
                               version
                               ".tar.bz2"))
+              (file-name (string-append name "-" version ".tar.bz2"))
               (sha256
                (base32
                 "05amrbrxx0da3w7m237q51799r8xgs4ffqabi2qv06hq8dpcj386"))))
@@ -1689,6 +1690,7 @@ synthesizer written in C++.")
        (method url-fetch)
        (uri (string-append "https://github.com/Themaister/RSound/archive/v"
                            version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32 "1wzs40c0k5zpkmm5ffl6c17xmr399sxli7ys0fbb9ib0fd334knx"))))
     (build-system gnu-build-system)
diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 7a50a85..e98e028 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -608,6 +608,7 @@ multiple sequence alignments.")
               (uri (string-append
                     "https://github.com/YeoLab/clipper/archive/"
                     version ".tar.gz"))
+              (file-name (string-append name "-" version ".tar.gz"))
               (sha256
                (base32
                 "1q7jpimsqln7ic44i8v2rx2haj5wvik8hc1s2syd31zcn0xk1iyq"))
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 940efec..0f7a482 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -2444,6 +2444,7 @@ and is very extensible.")
        (uri (string-append
              "https://github.com/scikit-learn/scikit-learn/archive/"
              version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32
          "140skabifgc7lvvj873pnzlwx0ni6q8qkrsyad2ccjb3h8rxzkih"))))
diff --git a/gnu/packages/telephony.scm b/gnu/packages/telephony.scm
index f0d5dff..ee8b2cb 100644
--- a/gnu/packages/telephony.scm
+++ b/gnu/packages/telephony.scm
@@ -192,7 +192,8 @@ internet.")
     (source (origin
              (method url-fetch)
              (uri (string-append "https://github.com/cisco/libsrtp/archive/v"
-                                  version ".tar.gz"))
+                                 version ".tar.gz"))
+             (file-name (string-append name "-" version ".tar.gz"))
              (sha256
               (base32
                "1njf62f6sazz2q7qc4j495v1pga385whkmxxyr8hfz1ragiyzqc6"))))
diff --git a/gnu/packages/textutils.scm b/gnu/packages/textutils.scm
index 08b1b64..c7cb243 100644
--- a/gnu/packages/textutils.scm
+++ b/gnu/packages/textutils.scm
@@ -72,6 +72,7 @@ handy front-end to the library.")
        (method url-fetch)
        (uri (string-append
              "https://github.com/nijel/enca/archive/" version ".tar.gz"))
+       (file-name (string-append name "-" version ".tar.gz"))
        (sha256
         (base32 "1xik00x0yvhswsw2isnclabhv536xk1s42cf5z54gfbpbhc7ni8l"))))
     (build-system gnu-build-system)
diff --git a/guix/scripts/lint.scm b/guix/scripts/lint.scm
index 14ac8cb..443103f 100644
--- a/guix/scripts/lint.scm
+++ b/guix/scripts/lint.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
-;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
+;;; Copyright © 2014, 2015 Eric Bavier <bavier@member.fsf.org>
 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -20,6 +20,7 @@
 
 (define-module (guix scripts lint)
   #:use-module (guix store)
+  #:use-module (guix derivations)
   #:use-module (guix base32)
   #:use-module (guix download)
   #:use-module (guix ftp-client)
@@ -466,31 +467,48 @@ descriptions maintained upstream."
                           uris))
       '()))
 
+  (define (origin-version-name? origin)
+    ;; Return #t if the source file name contains only a version; indicates
+    ;; that the origin needs a 'file-name' field.
+    (let ((filename (store-path-package-name
+                     (with-store store
+                       (derivation->output-path
+                        (package-source-derivation store origin)))))
+          (version (package-version package)))
+      (or (string-prefix? version filename)
+          ;; Common in many projects is for the filename to start with a "v"
+          ;; followed by the version, e.g. "v3.2.0.tar.gz".
+          (string-prefix? (string-append "v" version) filename))))
+
   (let ((origin (package-source package)))
-    (when (and origin
-               (eqv? (origin-method origin) url-fetch))
-      (let* ((strings (origin-uri origin))
-             (uris (if (list? strings)
-                       (map string->uri strings)
-                       (list (string->uri strings)))))
-
-        ;; Just make sure that at least one of the URIs is valid.
-        (call-with-values
-            (lambda () (try-uris uris))
-          (lambda (success? warnings)
-            ;; When everything fails, report all of WARNINGS, otherwise don't
-            ;; report anything.
-            ;;
-            ;; XXX: Ideally we'd still allow warnings to be raised if *some*
-            ;; URIs are unreachable, but distinguish that from the error case
-            ;; where *all* the URIs are unreachable.
-            (unless success?
-              (emit-warning package
-                            (_ "all the source URIs are unreachable:")
-                            'source)
-              (for-each (lambda (warning)
-                          (display warning (guix-warning-port)))
-                        (reverse warnings)))))))))
+    (when origin
+      (if (eqv? (origin-method origin) url-fetch)
+          (let* ((strings (origin-uri origin))
+                 (uris (if (list? strings)
+                           (map string->uri strings)
+                           (list (string->uri strings)))))
+
+            ;; Just make sure that at least one of the URIs is valid.
+            (call-with-values
+                (lambda () (try-uris uris))
+              (lambda (success? warnings)
+                ;; When everything fails, report all of WARNINGS, otherwise don't
+                ;; report anything.
+                ;;
+                ;; XXX: Ideally we'd still allow warnings to be raised if *some*
+                ;; URIs are unreachable, but distinguish that from the error case
+                ;; where *all* the URIs are unreachable.
+                (unless success?
+                  (emit-warning package
+                                (_ "all the source URIs are unreachable:")
+                                'source)
+                  (for-each (lambda (warning)
+                              (display warning (guix-warning-port)))
+                            (reverse warnings)))))))
+      (if (origin-version-name? origin)
+          (emit-warning package
+                        (_ "the source filename should contain the package name")
+                        'source)))))
 
 (define (check-derivation package)
   "Emit a warning if we fail to compile PACKAGE to a derivation."
diff --git a/tests/lint.scm b/tests/lint.scm
index 5d56420..0973741 100644
--- a/tests/lint.scm
+++ b/tests/lint.scm
@@ -392,6 +392,49 @@ requests."
           (check-home-page pkg))))
     "not reachable: 404")))
 
+(test-assert "source: filename"
+  (->bool
+   (string-contains
+    (with-warnings
+      (let ((pkg (dummy-package "x"
+                   (version "3.2.1")
+                   (source
+                    (origin
+                      (method url-fetch)
+                      (uri "http://www.example.com/3.2.1.tar.gz")
+                      (sha256 %null-sha256))))))
+        (check-source pkg)))
+    "filename should contain the package name")))
+
+(test-assert "source: filename v"
+  (->bool
+   (string-contains
+    (with-warnings
+      (let ((pkg (dummy-package "x"
+                   (version "3.2.1")
+                   (source
+                    (origin
+                      (method url-fetch)
+                      (uri "http://www.example.com/v3.2.1.tar.gz")
+                      (sha256 %null-sha256))))))
+        (check-source pkg)))
+    "filename should contain the package name")))
+
+(test-assert "source: filename valid"
+  (not
+   (->bool
+    (string-contains
+     (with-warnings
+       (let ((pkg (dummy-package "x"
+                    (version "3.2.1")
+                    (source
+                     (origin
+                       (method url-fetch)
+                       (uri "http://www.example.com/x-3.2.1.tar.gz")
+                       (sha256 %null-sha256))))))
+         (check-source pkg)))
+     "filename should contain the package name"))))
+
 (test-skip (if %http-server-socket 0 1))
 (test-equal "source: 200"
   ""
-- 
2.4.3


  reply	other threads:[~2015-08-25  5:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 23:05 [PATCH] guix: lint: Check for version-only origin file names ericbavier
2015-08-24 23:02 ` Mark H Weaver
2015-08-25  0:10   ` Eric Bavier [this message]
2015-08-28  7:48     ` Ludovic Courtès
2015-09-10 20:50       ` Eric Bavier
2015-09-11  4:04         ` Eric Bavier
2015-09-13 16:59           ` Ludovic Courtès
2015-09-14 23:11             ` Eric Bavier

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=20150824191024.3da87f41@openmailbox.org \
    --to=ericbavier@openmailbox.org \
    --cc=bavier@member.fsf.org \
    --cc=guix-devel@gnu.org \
    --cc=mhw@netris.org \
    /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).