GNU logs - #53828, boring messages


Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#53828] [PATCH] guix: opam: Allow importing local files.
Resent-From: Julien Lepiller <julien@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 06 Feb 2022 21:43:02 +0000
Resent-Message-ID: <handler.53828.B.164418373724190 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 53828
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: 53828 <at> debbugs.gnu.org
X-Debbugs-Original-To: guix-patches@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.164418373724190
          (code B ref -1); Sun, 06 Feb 2022 21:43:02 +0000
Received: (at submit) by debbugs.gnu.org; 6 Feb 2022 21:42:17 +0000
Received: from localhost ([127.0.0.1]:39975 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1nGpIW-0006I6-NA
	for submit <at> debbugs.gnu.org; Sun, 06 Feb 2022 16:42:17 -0500
Received: from lists.gnu.org ([209.51.188.17]:37360)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <julien@HIDDEN>) id 1nGpIV-0006Hy-3W
 for submit <at> debbugs.gnu.org; Sun, 06 Feb 2022 16:42:15 -0500
Received: from eggs.gnu.org ([209.51.188.92]:55344)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <julien@HIDDEN>)
 id 1nGpIU-0007wM-ML
 for guix-patches@HIDDEN; Sun, 06 Feb 2022 16:42:14 -0500
Received: from [2a00:5884:8208::1] (port=35922 helo=lepiller.eu)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <julien@HIDDEN>)
 id 1nGpI2-0006Lw-3K
 for guix-patches@HIDDEN; Sun, 06 Feb 2022 16:41:49 -0500
Received: from lepiller.eu (localhost [127.0.0.1])
 by lepiller.eu (OpenSMTPD) with ESMTP id 5c328a32
 for <guix-patches@HIDDEN>; Sun, 6 Feb 2022 21:41:39 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from
 :to:subject:message-id:mime-version:content-type; s=dkim; bh=V5n
 maPMXPc32Hoqgk9j6lNhM0FesZDhSCkXEZ9qBakE=; b=mV+E8Q7kAyLAfWLMHhW
 Kt8i/eZwvldjss7CJtovIG3pTffPTRxj+JCTYj0hFkE+7cU/YW4oosngn3idopVX
 lBe8CTz8N/SDr9NZ1qv2SJYTXBSHn9XFo3y16eK4sLLR016C+X6pz6aZrb1Dmqyk
 MEXzL3Gq1Eqv4l3RQ4AizbV6u/fPVquBr1KAfBNErIy8AIxNny3glWUkURpHTh75
 zVBH0tD5WMCPYDOCRaGr5vcnbpdvzz/MuE4qmk4GEVJe70icrlxlvfCxPTCRZH1q
 jusdlQ4PX6fGArL9D7AfUsGDoaUJBY0cF38BMptWRdwdLzxCkFO9SPUIEK/wPoLt
 yVA==
Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 7855a846
 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for <guix-patches@HIDDEN>;
 Sun, 6 Feb 2022 21:41:39 +0000 (UTC)
Date: Sun, 6 Feb 2022 22:41:30 +0100
From: Julien Lepiller <julien@HIDDEN>
Message-ID: <20220206224130.2220aae9@HIDDEN>
X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="MP_/GxuYmKHeuMF5J7IXm2T6L90"
X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:5884:8208::1 (failed)
Received-SPF: pass client-ip=2a00:5884:8208::1;
 envelope-from=julien@HIDDEN; helo=lepiller.eu
X-Spam_score_int: -12
X-Spam_score: -1.3
X-Spam_bar: -
X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RDNS_NONE=0.793,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--MP_/GxuYmKHeuMF5J7IXm2T6L90
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi Guix!

This patch lets you import opam packages from a local file. This is a
feature that was requested a few times, and there it is :)

Now, if you have an OCaml package sources that provides an opam file
(usually called opam, or with the .opam extension), you can import the
package, recursively or not with something like:

guix import opam foo -f foo.opam -r

instead of fetching foo from the repositories, it will fetch the data
directly from the given file. WDYT?

--MP_/GxuYmKHeuMF5J7IXm2T6L90
Content-Type: text/x-patch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=0001-guix-opam-Allow-importing-local-files.patch

From b027391357eef4d6fa1bb8741528cf9650aef568 Mon Sep 17 00:00:00 2001
Message-Id: <b027391357eef4d6fa1bb8741528cf9650aef568.1644183523.git.julien@HIDDEN>
From: Julien Lepiller <julien@HIDDEN>
Date: Sun, 6 Feb 2022 22:35:14 +0100
Subject: [PATCH] guix: opam: Allow importing local files.

* guix/scripts/import/opam.scm (guix-import-opam): Support `--file` flag.
* guix/import/utils.scm (recursive-import): Add optional file argument.
Pass it to the first iteration when available.
* guix/import/opam.scm (opam-fetch): Fetch from file when available.
(opam->guix-source): Factorize source out of opam->guix-package.
(opam->guix-package): Add file argument.  Ensure it does not fail when
name, version and url are not available.
---
 guix/import/opam.scm         | 101 +++++++++++++++++++----------------
 guix/import/utils.scm        |  17 +++---
 guix/scripts/import/opam.scm |  11 +++-
 3 files changed, 75 insertions(+), 54 deletions(-)

diff --git a/guix/import/opam.scm b/guix/import/opam.scm
index a6f6fe8c9f..05f79110f8 100644
--- a/guix/import/opam.scm
+++ b/guix/import/opam.scm
@@ -310,8 +310,11 @@ (define (dependency-list->inputs lst)
   (map string->symbol
        (ocaml-names->guix-names lst)))
 
-(define* (opam-fetch name #:optional (repositories-specs '("opam")))
-  (or (fold (lambda (repository others)
+(define* (opam-fetch name #:optional (repositories-specs '("opam")) (file #f))
+  (or (and file (let ((metadata (get-metadata file)))
+                  `(("metadata" . ,metadata)
+                    ("version" . #f))))
+      (fold (lambda (repository others)
               (match (find-latest-version name repository)
                 ((_ version file) `(("metadata" ,@(get-metadata file))
                                     ("version" . ,version)))
@@ -320,17 +323,29 @@ (define* (opam-fetch name #:optional (repositories-specs '("opam")))
             (filter-map get-opam-repository repositories-specs))
       (warning (G_ "opam: package '~a' not found~%") name)))
 
-(define* (opam->guix-package name #:key (repo 'opam) version)
+(define (opam->guix-source url-dict)
+  (let ((source-url (and url-dict
+                         (or (metadata-ref url-dict "src")
+                             (metadata-ref url-dict "archive")))))
+    (if source-url
+        (call-with-temporary-output-file
+          (lambda (temp port)
+            (and (url-fetch source-url temp)
+                 `(origin
+                    (method url-fetch)
+                    (uri ,source-url)
+                    (sha256 (base32 ,(guix-hash-url temp)))))))
+        'no-source-information)))
+
+(define* (opam->guix-package name #:key (repo '("opam")) (file #f) version)
   "Import OPAM package NAME from REPOSITORY (a directory name) or, if
-REPOSITORY is #f, from the official OPAM repository.  Return a 'package' sexp
+REPOSITORY is #f, from the official OPAM repository.  When FILE is defined,
+import the packaged defined in the opam FILE instead.  Return a 'package' sexp
 or #f on failure."
   (and-let* ((with-opam (if (member "opam" repo) repo (cons "opam" repo)))
-             (opam-file (opam-fetch name with-opam))
-             (version (assoc-ref opam-file "version"))
+             (opam-file (opam-fetch name with-opam file))
              (opam-content (assoc-ref opam-file "metadata"))
-             (url-dict (metadata-ref opam-content "url"))
-             (source-url (or (metadata-ref url-dict "src")
-                             (metadata-ref url-dict "archive")))
+             (source (opam->guix-source (metadata-ref opam-content "url")))
              (requirements (metadata-ref opam-content "depends"))
              (names (dependency-list->names requirements))
              (dependencies (filter-dependencies names))
@@ -344,47 +359,41 @@ (define* (opam->guix-package name #:key (repo 'opam) version)
                                   (not (member name '("dune" "jbuilder"))))
                                 native-dependencies))))
         (let ((use-dune? (member "dune" names)))
-          (call-with-temporary-output-file
-            (lambda (temp port)
-              (and (url-fetch source-url temp)
-                   (values
-                    `(package
-                       (name ,(ocaml-name->guix-name name))
-                       (version ,version)
-                       (source
-                         (origin
-                           (method url-fetch)
-                           (uri ,source-url)
-                           (sha256 (base32 ,(guix-hash-url temp)))))
-                       (build-system ,(if use-dune?
-                                          'dune-build-system
-                                          'ocaml-build-system))
-                       ,@(if (null? inputs)
-                           '()
-                           `((propagated-inputs (list ,@inputs))))
-                       ,@(if (null? native-inputs)
-                           '()
-                           `((native-inputs (list ,@native-inputs))))
-                       ,@(if (equal? name (guix-name->opam-name (ocaml-name->guix-name name)))
-                           '()
-                           `((properties
-                               ,(list 'quasiquote `((upstream-name . ,name))))))
-                       (home-page ,(metadata-ref opam-content "homepage"))
-                       (synopsis ,(metadata-ref opam-content "synopsis"))
-                       (description ,(beautify-description
-                                      (metadata-ref opam-content "description")))
-                       (license ,(spdx-string->license
-                                  (metadata-ref opam-content "license"))))
-                    (filter
-                      (lambda (name)
-                        (not (member name '("dune" "jbuilder"))))
-                      dependencies))))))))
+          (values
+           `(package
+              (name ,(and name (ocaml-name->guix-name name)))
+              (version ,(assoc-ref opam-file "version"))
+              (source ,source)
+              (build-system ,(if use-dune?
+                                 'dune-build-system
+                                 'ocaml-build-system))
+              ,@(if (null? inputs)
+                  '()
+                  `((propagated-inputs (list ,@inputs))))
+              ,@(if (null? native-inputs)
+                  '()
+                  `((native-inputs (list ,@native-inputs))))
+              ,@(if (and name (equal? name (guix-name->opam-name (ocaml-name->guix-name name))))
+                  '()
+                  `((properties
+                      ,(list 'quasiquote `((upstream-name . ,name))))))
+              (home-page ,(metadata-ref opam-content "homepage"))
+              (synopsis ,(metadata-ref opam-content "synopsis"))
+              (description ,(beautify-description
+                             (metadata-ref opam-content "description")))
+              (license ,(spdx-string->license
+                         (metadata-ref opam-content "license"))))
+           (filter
+             (lambda (name)
+               (not (member name '("dune" "jbuilder"))))
+             dependencies)))))
 
-(define* (opam-recursive-import package-name #:key repo)
+(define* (opam-recursive-import package-name #:key repo file)
   (recursive-import package-name
                     #:repo->guix-package opam->guix-package
                     #:guix-name ocaml-name->guix-name
-                    #:repo repo))
+                    #:repo repo
+                    #:file file))
 
 (define (guix-name->opam-name name)
   (if (string-prefix? "ocaml-" name)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 1c3cfa3e0b..ab35b8a4fc 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -470,7 +470,7 @@ (define (topological-sort nodes
                    (set-insert (node-name head) visited))))))))
 
 (define* (recursive-import package-name
-                           #:key repo->guix-package guix-name version repo
+                           #:key repo->guix-package guix-name version repo file
                            #:allow-other-keys)
   "Return a list of package expressions for PACKAGE-NAME and all its
 dependencies, sorted in topological order.  For each package,
@@ -488,10 +488,15 @@ (define* (recursive-import package-name
   (define (exists? name version)
     (not (null? (find-packages-by-name (guix-name name) version))))
 
-  (define (lookup-node name version)
-    (let* ((package dependencies (repo->guix-package name
-                                                     #:version version
-                                                     #:repo repo))
+  (define* (lookup-node name version #:optional file)
+    (let* ((package dependencies (if file
+                                     (repo->guix-package name
+                                                       #:version version
+                                                       #:repo repo
+                                                       #:file file)
+                                     (repo->guix-package name
+                                                       #:version version
+                                                       #:repo repo)))
            (normalized-deps (map (match-lambda
                                    ((name version) (list name version))
                                    (name (list name #f))) dependencies)))
@@ -499,7 +504,7 @@ (define* (recursive-import package-name
 
   (filter-map
    node-package
-   (topological-sort (list (lookup-node package-name version))
+   (topological-sort (list (lookup-node package-name version file))
                      (lambda (node)
                        (map (lambda (name-version)
                               (apply lookup-node name-version))
diff --git a/guix/scripts/import/opam.scm b/guix/scripts/import/opam.scm
index 834ac34cb0..b58c6eab3d 100644
--- a/guix/scripts/import/opam.scm
+++ b/guix/scripts/import/opam.scm
@@ -50,6 +50,8 @@ (define (show-help)
       --repo             import packages from this opam repository (name, URL or local path)
                          can be used more than once"))
   (display (G_ "
+  -f, --file             import the package defined from a .opam file"))
+  (display (G_ "
   -V, --version          display version information and exit"))
   (newline)
   (show-bug-report-information))
@@ -66,6 +68,9 @@ (define %options
          (option '(#f "repo") #t #f
                  (lambda (opt name arg result)
                    (alist-cons 'repo arg result)))
+         (option '(#\f "file") #t #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'file arg result)))
          (option '(#\r "recursive") #f #f
                  (lambda (opt name arg result)
                    (alist-cons 'recursive #t result)))
@@ -100,9 +105,11 @@ (define (guix-import-opam . args)
                    `(define-public ,(string->symbol name)
                       ,pkg))
                   (_ #f))
-                (opam-recursive-import package-name #:repo repo))
+                (opam-recursive-import package-name #:repo repo
+                                       #:file (assoc-ref opts 'file)))
            ;; Single import
-           (let ((sexp (opam->guix-package package-name #:repo repo)))
+           (let ((sexp (opam->guix-package package-name #:repo repo
+                                           #:file (assoc-ref opts 'file))))
              (unless sexp
                (leave (G_ "failed to download meta-data for package '~a'~%")
                       package-name))
-- 
2.34.0


--MP_/GxuYmKHeuMF5J7IXm2T6L90--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Julien Lepiller <julien@HIDDEN>
Subject: bug#53828: Acknowledgement ([PATCH] guix: opam: Allow importing
 local files.)
Message-ID: <handler.53828.B.164418373724190.ack <at> debbugs.gnu.org>
References: <20220206224130.2220aae9@HIDDEN>
X-Gnu-PR-Message: ack 53828
X-Gnu-PR-Package: guix-patches
X-Gnu-PR-Keywords: patch
Reply-To: 53828 <at> debbugs.gnu.org
Date: Sun, 06 Feb 2022 21:43:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 guix-patches@HIDDEN

If you wish to submit further information on this problem, please
send it to 53828 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
53828: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D53828
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#53828] [PATCH] guix: opam: Allow importing local files.
Resent-From: Maxime Devos <maximedevos@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Sun, 06 Feb 2022 22:00:02 +0000
Resent-Message-ID: <handler.53828.B53828.164418474225922 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 53828
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: Julien Lepiller <julien@HIDDEN>, 53828 <at> debbugs.gnu.org
Received: via spool by 53828-submit <at> debbugs.gnu.org id=B53828.164418474225922
          (code B ref 53828); Sun, 06 Feb 2022 22:00:02 +0000
Received: (at 53828) by debbugs.gnu.org; 6 Feb 2022 21:59:02 +0000
Received: from localhost ([127.0.0.1]:40002 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1nGpYk-0006k2-9G
	for submit <at> debbugs.gnu.org; Sun, 06 Feb 2022 16:59:02 -0500
Received: from laurent.telenet-ops.be ([195.130.137.89]:34914)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <maximedevos@HIDDEN>) id 1nGpYh-0006jc-UA
 for 53828 <at> debbugs.gnu.org; Sun, 06 Feb 2022 16:59:00 -0500
Received: from [172.20.10.5] ([188.188.37.53])
 by laurent.telenet-ops.be with bizsmtp
 id rxyx2600K18o4tG01xyyek; Sun, 06 Feb 2022 22:58:58 +0100
Message-ID: <c7f328ba29b68bcf0f4555095a864738a63be2f3.camel@HIDDEN>
From: Maxime Devos <maximedevos@HIDDEN>
Date: Sun, 06 Feb 2022 22:58:52 +0100
In-Reply-To: <20220206224130.2220aae9@HIDDEN>
References: <20220206224130.2220aae9@HIDDEN>
Content-Type: multipart/signed; micalg="pgp-sha512";
 protocol="application/pgp-signature"; boundary="=-+coQc1aDVWtBPE70kDkl"
User-Agent: Evolution 3.38.3-1 
MIME-Version: 1.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22;
 t=1644184738; bh=a2e88jEihs1CmQgNBXRAsa+3UOQG5ipZtRDWmRg6Bro=;
 h=Subject:From:To:Date:In-Reply-To:References;
 b=eR9ONTjvqMks+yIYkLdbvVNXg8lhvfgKzlTOQPCNTrf9kIQ9g3FIE7XCr2mhDkYhz
 wOsLUon5G5OArBS4K9eKWFXutVOZeTjCodBDaio2iOsQ9d3WkSlrcffb9vpKBmn5/D
 RDhYHyWswTk63b1mEk9L1hzSgvRiEJPg68HWow4rIgTjidUTsn38gcUix1/efEpr/p
 wMvCD/j8qAqnMi5t9zfnqtZ73K1Nnvo14xbzzP2YuKr2xWdK0BV7YnvFOaCUAYCKU1
 W4IuEC34Y1Wx+UoJVB+wTV0GqkAzQBRGf6FP3D8ERXUWO7q4qZFhyDyLsgZ1lAccwc
 gcCzHhxmMAFeQ==
X-Spam-Score: -0.7 (/)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)


--=-+coQc1aDVWtBPE70kDkl
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Julien Lepiller schreef op zo 06-02-2022 om 22:41 [+0100]:
> Now, if you have an OCaml package sources that provides an opam file
> (usually called opam, or with the .opam extension), you can import
> the
> package, recursively or not with something like:
>=20
> guix import opam foo -f foo.opam -r
>=20
> instead of fetching foo from the repositories, it will fetch the data
> directly from the given file. WDYT?

I don't know OCaml at all, but that seems potentially useful.
Can we have some tests for this in tests/opam.scm?

Greetings,
Maxime.

--=-+coQc1aDVWtBPE70kDkl
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYgBEnBccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7knRAQCi2ZjhnPN1LWFPJDAfi9HCBN+h
uM+77YR+GNec2y6zYwD8CYIcFLIqXa2nDdLV2SPvBMu+jbaOSHQgLPeOb3s+OAU=
=xYaa
-----END PGP SIGNATURE-----

--=-+coQc1aDVWtBPE70kDkl--





Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#53828] [PATCH] guix: opam: Allow importing local files.
Resent-From: Xinglu Chen <public@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 07 Feb 2022 08:28:02 +0000
Resent-Message-ID: <handler.53828.B53828.164422247521897 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 53828
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: Julien Lepiller <julien@HIDDEN>, 53828 <at> debbugs.gnu.org
Received: via spool by 53828-submit <at> debbugs.gnu.org id=B53828.164422247521897
          (code B ref 53828); Mon, 07 Feb 2022 08:28:02 +0000
Received: (at 53828) by debbugs.gnu.org; 7 Feb 2022 08:27:55 +0000
Received: from localhost ([127.0.0.1]:40825 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1nGzNK-0005h3-Cn
	for submit <at> debbugs.gnu.org; Mon, 07 Feb 2022 03:27:55 -0500
Received: from h178-251-242-94.cust.a3fiber.se ([178.251.242.94]:54446
 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <public@HIDDEN>) id 1nGzNE-0005gd-Ds
 for 53828 <at> debbugs.gnu.org; Mon, 07 Feb 2022 03:27:52 -0500
From: Xinglu Chen <public@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoctocell.xyz;
 s=mail; t=1644222460;
 bh=qHPRTx3d9xugIG/M1mi0pRqjU0ZKV/Zd94Ts1hg6GAU=;
 h=From:To:Subject:In-Reply-To:References:Date;
 b=rDbsDfLhzRu3i62spNo/cCJhnvJWaNRGUu/vvbhcKWTuhguFu/acQ0uDDRuyKpuAF
 NJAl0CBT6lfkPZUAHAlK+YOqorEZQk34ZzyMvOOYkAylBPlwt2uyAU3NG2sNQyJZ7t
 5GihoWCmlFOtCUbMghN+yXHNqx1Uei4vA9P0RKTY=
In-Reply-To: <20220206224130.2220aae9@HIDDEN>
References: <20220206224130.2220aae9@HIDDEN>
Date: Mon, 07 Feb 2022 09:27:39 +0100
Message-ID: <87k0e713pg.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="=-=-=";
 micalg=pgp-sha256; protocol="application/pgp-signature"
X-Spam-Score: 2.5 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: Julien schrieb am Sonntag der 06. Februar 2022 um 22:41 +01:
 > Hi Guix! > > This patch lets you import opam packages from a local file.
 This is a > feature that was requested a few times, and there it is :) >
 > Now, if you have an OCaml package sources that pro [...] 
 Content analysis details:   (2.5 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 1.6 PDS_OTHER_BAD_TLD      Untrustworthy TLDs
 [URI: yoctocell.xyz (xyz)]
 0.4 RDNS_DYNAMIC           Delivered to internal network by host with
 dynamic-looking rDNS 0.5 FROM_SUSPICIOUS_NTLD   From abused NTLD
 -0.0 T_SCC_BODY_TEXT_LINE   No description available.
 0.0 PDS_RDNS_DYNAMIC_FP    RDNS_DYNAMIC with FP steps
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 2.5 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  Julien schrieb am Sonntag der 06. Februar 2022 um 22:41 +01:
    > Hi Guix! > > This patch lets you import opam packages from a local file.
    This is a > feature that was requested a few times, and there it is :) >
   > Now, if you have an OCaml package sources that pro [...] 
 
 Content analysis details:   (2.5 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
  1.6 PDS_OTHER_BAD_TLD      Untrustworthy TLDs
                             [URI: yoctocell.xyz (xyz)]
  0.4 RDNS_DYNAMIC           Delivered to internal network by host with
                             dynamic-looking rDNS
  1.0 BULK_RE_SUSP_NTLD      Precedence bulk and RE: from a suspicious TLD
  0.5 FROM_SUSPICIOUS_NTLD   From abused NTLD
 -0.0 T_SCC_BODY_TEXT_LINE   No description available.
 -1.0 MAILING_LIST_MULTI     Multiple indicators imply a widely-seen list
                             manager
  0.0 PDS_RDNS_DYNAMIC_FP    RDNS_DYNAMIC with FP steps

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Julien schrieb am Sonntag der 06. Februar 2022 um 22:41 +01:

> Hi Guix!
>
> This patch lets you import opam packages from a local file. This is a
> feature that was requested a few times, and there it is :)
>
> Now, if you have an OCaml package sources that provides an opam file
> (usually called opam, or with the .opam extension), you can import the
> package, recursively or not with something like:
>
> guix import opam foo -f foo.opam -r
>
> instead of fetching foo from the repositories, it will fetch the data
> directly from the given file. WDYT?

Why just limit it to local files?  What about accepting a tarball on the
internet or any VCS repository?  This could generally be useful for any
importer.

Also, since we already know the name of the package, maybe specifying
the directory that contains the OCaml project would be enough?

  guix import opam foo --type=3Dlocal /path/to/directory
  guix import opam foo --type=3Dtarball https://example.org/foo.tar.gz
  guix import opam foo --type=3Dgit https://git.example.org/foo
  =E2=80=A6

Or am I asking for too much?  :-)

> From b027391357eef4d6fa1bb8741528cf9650aef568 Mon Sep 17 00:00:00 2001
> Message-Id: <b027391357eef4d6fa1bb8741528cf9650aef568.1644183523.git.juli=
en@HIDDEN>
> From: Julien Lepiller <julien@HIDDEN>
> Date: Sun, 6 Feb 2022 22:35:14 +0100
> Subject: [PATCH] guix: opam: Allow importing local files.

It should be =E2=80=9Cimport: opam: =E2=80=A6=E2=80=9D.

> * guix/scripts/import/opam.scm (guix-import-opam): Support `--file` flag.
> * guix/import/utils.scm (recursive-import): Add optional file argument.
> Pass it to the first iteration when available.
> * guix/import/opam.scm (opam-fetch): Fetch from file when available.
> (opam->guix-source): Factorize source out of opam->guix-package.
> (opam->guix-package): Add file argument.  Ensure it does not fail when
> name, version and url are not available.
> ---
>  guix/import/opam.scm         | 101 +++++++++++++++++++----------------
>  guix/import/utils.scm        |  17 +++---
>  guix/scripts/import/opam.scm |  11 +++-
>  3 files changed, 75 insertions(+), 54 deletions(-)
>
> diff --git a/guix/import/opam.scm b/guix/import/opam.scm
> index a6f6fe8c9f..05f79110f8 100644
> --- a/guix/import/opam.scm
> +++ b/guix/import/opam.scm
> @@ -310,8 +310,11 @@ (define (dependency-list->inputs lst)
>    (map string->symbol
>         (ocaml-names->guix-names lst)))
>=20=20
> -(define* (opam-fetch name #:optional (repositories-specs '("opam")))
> -  (or (fold (lambda (repository others)
> +(define* (opam-fetch name #:optional (repositories-specs '("opam")) (fil=
e #f))
> +  (or (and file (let ((metadata (get-metadata file)))
> +                  `(("metadata" . ,metadata)
> +                    ("version" . #f))))
> +      (fold (lambda (repository others)
>                (match (find-latest-version name repository)
>                  ((_ version file) `(("metadata" ,@(get-metadata file))
>                                      ("version" . ,version)))
> @@ -320,17 +323,29 @@ (define* (opam-fetch name #:optional (repositories-=
specs '("opam")))
>              (filter-map get-opam-repository repositories-specs))
>        (warning (G_ "opam: package '~a' not found~%") name)))
>=20=20
> -(define* (opam->guix-package name #:key (repo 'opam) version)
> +(define (opam->guix-source url-dict)
> +  (let ((source-url (and url-dict
> +                         (or (metadata-ref url-dict "src")
> +                             (metadata-ref url-dict "archive")))))
> +    (if source-url
> +        (call-with-temporary-output-file
> +          (lambda (temp port)
> +            (and (url-fetch source-url temp)
> +                 `(origin
> +                    (method url-fetch)
> +                    (uri ,source-url)
> +                    (sha256 (base32 ,(guix-hash-url temp)))))))
> +        'no-source-information)))

I would use =E2=80=98and-let*=E2=80=99 instead of =E2=80=98let=E2=80=99, an=
d drop the =E2=80=98if=E2=80=99 form.

The ability to import from a local file seems to mostly be useful when
the package isn=E2=80=99t meant to be submitted to Guix, right?  Wouldn=E2=
=80=99t it
make more sense to make the source a =E2=80=98local-file=E2=80=99 object in=
stead of just
setting it to #f?

> +(define* (opam->guix-package name #:key (repo '("opam")) (file #f) versi=
on)
>    "Import OPAM package NAME from REPOSITORY (a directory name) or, if
> -REPOSITORY is #f, from the official OPAM repository.  Return a 'package'=
 sexp
> +REPOSITORY is #f, from the official OPAM repository.  When FILE is defin=
ed,
> +import the packaged defined in the opam FILE instead.  Return a 'package=
' sexp

s/packaged/package/

>    (and-let* ((with-opam (if (member "opam" repo) repo (cons "opam" repo)=
))
> -             (opam-file (opam-fetch name with-opam))
> -             (version (assoc-ref opam-file "version"))
> +             (opam-file (opam-fetch name with-opam file))
>               (opam-content (assoc-ref opam-file "metadata"))
> -             (url-dict (metadata-ref opam-content "url"))
> -             (source-url (or (metadata-ref url-dict "src")
> -                             (metadata-ref url-dict "archive")))
> +             (source (opam->guix-source (metadata-ref opam-content "url"=
)))
>               (requirements (metadata-ref opam-content "depends"))
>               (names (dependency-list->names requirements))
>               (dependencies (filter-dependencies names))
> @@ -344,47 +359,41 @@ (define* (opam->guix-package name #:key (repo 'opam=
) version)
>                                    (not (member name '("dune" "jbuilder")=
)))
>                                  native-dependencies))))
>          (let ((use-dune? (member "dune" names)))
> -          (call-with-temporary-output-file
> -            (lambda (temp port)
> -              (and (url-fetch source-url temp)
> -                   (values
> -                    `(package
> -                       (name ,(ocaml-name->guix-name name))
> -                       (version ,version)
> -                       (source
> -                         (origin
> -                           (method url-fetch)
> -                           (uri ,source-url)
> -                           (sha256 (base32 ,(guix-hash-url temp)))))
> -                       (build-system ,(if use-dune?
> -                                          'dune-build-system
> -                                          'ocaml-build-system))
> -                       ,@(if (null? inputs)
> -                           '()
> -                           `((propagated-inputs (list ,@inputs))))
> -                       ,@(if (null? native-inputs)
> -                           '()
> -                           `((native-inputs (list ,@native-inputs))))
> -                       ,@(if (equal? name (guix-name->opam-name (ocaml-n=
ame->guix-name name)))
> -                           '()
> -                           `((properties
> -                               ,(list 'quasiquote `((upstream-name . ,na=
me))))))
> -                       (home-page ,(metadata-ref opam-content "homepage"=
))
> -                       (synopsis ,(metadata-ref opam-content "synopsis"))
> -                       (description ,(beautify-description
> -                                      (metadata-ref opam-content "descri=
ption")))
> -                       (license ,(spdx-string->license
> -                                  (metadata-ref opam-content "license"))=
))
> -                    (filter
> -                      (lambda (name)
> -                        (not (member name '("dune" "jbuilder"))))
> -                      dependencies))))))))
> +          (values
> +           `(package
> +              (name ,(and name (ocaml-name->guix-name name)))
> +              (version ,(assoc-ref opam-file "version"))
> +              (source ,source)
> +              (build-system ,(if use-dune?
> +                                 'dune-build-system
> +                                 'ocaml-build-system))
> +              ,@(if (null? inputs)
> +                  '()
> +                  `((propagated-inputs (list ,@inputs))))
> +              ,@(if (null? native-inputs)
> +                  '()
> +                  `((native-inputs (list ,@native-inputs))))
> +              ,@(if (and name (equal? name (guix-name->opam-name (ocaml-=
name->guix-name name))))
> +                  '()
> +                  `((properties
> +                      ,(list 'quasiquote `((upstream-name . ,name))))))
> +              (home-page ,(metadata-ref opam-content "homepage"))
> +              (synopsis ,(metadata-ref opam-content "synopsis"))
> +              (description ,(beautify-description
> +                             (metadata-ref opam-content "description")))
> +              (license ,(spdx-string->license
> +                         (metadata-ref opam-content "license"))))
> +           (filter
> +             (lambda (name)
> +               (not (member name '("dune" "jbuilder"))))
> +             dependencies)))))
>=20=20
> -(define* (opam-recursive-import package-name #:key repo)
> +(define* (opam-recursive-import package-name #:key repo file)
>    (recursive-import package-name
>                      #:repo->guix-package opam->guix-package
>                      #:guix-name ocaml-name->guix-name
> -                    #:repo repo))
> +                    #:repo repo
> +                    #:file file))
>=20=20
>  (define (guix-name->opam-name name)
>    (if (string-prefix? "ocaml-" name)
> diff --git a/guix/import/utils.scm b/guix/import/utils.scm
> index 1c3cfa3e0b..ab35b8a4fc 100644
> --- a/guix/import/utils.scm
> +++ b/guix/import/utils.scm
> @@ -470,7 +470,7 @@ (define (topological-sort nodes
>                     (set-insert (node-name head) visited))))))))
>=20=20
>  (define* (recursive-import package-name
> -                           #:key repo->guix-package guix-name version re=
po
> +                           #:key repo->guix-package guix-name version re=
po file
>                             #:allow-other-keys)
>    "Return a list of package expressions for PACKAGE-NAME and all its
>  dependencies, sorted in topological order.  For each package,

The docstrings should also be updated.

--=-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQJJBAEBCAAzFiEEAVhh4yyK5+SEykIzrPUJmaL7XHkFAmIA1/sVHHB1YmxpY0B5
b2N0b2NlbGwueHl6AAoJEKz1CZmi+1x5i1oP/1TZbQVKhanj9SBwv1P4b1Fp6/0e
PQAVN2Koms7eSLsSmApR3Fw6k5HBPWMbBlwcY7UaRBg1eZai0Nbzc7IfEWG3WDNO
XjRTT5DNK3ek74Ibq5LZVv9HLyLg59/E3fjr91JVKHesdDCTvSJOz3Zi+u2FXd/7
TWfJfeZIP/L8Y5L819IKyKcnH6oQYocSgnhXUPrbVATWvvd6wk6a7clOZN30pPmK
rwruQyfSwe12gCIxYx9bDELeRLTUz7tVw7Lm0MA5xDnBy+RwS4xv0WLOobO+vL8K
qCTWloJL3hKRYSu56P24tALQgdfBRAzrXRIKi4dHeMVhRr9AwYLo6DOcNDm9Q6M3
g4KF9l8fqUwuiRCzeKj3V9gs6db76LhsugJPfxCBeaVNg3rX6oo09Q/mKENrR4a2
A/cso8cR7wgViwtD9vUqN9W/YQCuKHFnT8lwb7lRi93TOn59r7Q+Mr7dS8ZgPmL2
ZA2r3+OcVyMLioyPxhQ2OPfHiayY1zAmJl7M5C/pJ0xYy3aZdWqMrbHDePCvNy3K
uYTvUSQPWLox37kMAXqAWgN+ElQnQb/d7U72erGlgF3imh1JQTcH4boWgJSVSvZN
6IOEcqG+Vm4iJkKWoJafS8rmyS8FP19sZCQ4TYf6oPFCApw3cHpYlYHfnELNu4J7
mbsgpexm6KbIwJhC
=1m+M
-----END PGP SIGNATURE-----
--=-=-=--




Message sent to guix-patches@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: [bug#53828] [PATCH] guix: opam: Allow importing local files.
Resent-From: Julien Lepiller <julien@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: guix-patches@HIDDEN
Resent-Date: Mon, 07 Feb 2022 08:48:02 +0000
Resent-Message-ID: <handler.53828.B53828.164422362232653 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 53828
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: Xinglu Chen <public@HIDDEN>, 53828 <at> debbugs.gnu.org
Received: via spool by 53828-submit <at> debbugs.gnu.org id=B53828.164422362232653
          (code B ref 53828); Mon, 07 Feb 2022 08:48:02 +0000
Received: (at 53828) by debbugs.gnu.org; 7 Feb 2022 08:47:02 +0000
Received: from localhost ([127.0.0.1]:40880 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1nGzfp-0008UU-8o
	for submit <at> debbugs.gnu.org; Mon, 07 Feb 2022 03:47:01 -0500
Received: from lepiller.eu ([89.234.186.109]:46778)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <julien@HIDDEN>) id 1nGzfm-0008UK-Uo
 for 53828 <at> debbugs.gnu.org; Mon, 07 Feb 2022 03:47:00 -0500
Received: from lepiller.eu (localhost [127.0.0.1])
 by lepiller.eu (OpenSMTPD) with ESMTP id 6c8b50a5;
 Mon, 7 Feb 2022 08:46:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from
 :to:subject:in-reply-to:references:message-id:mime-version
 :content-type:content-transfer-encoding; s=dkim; bh=EoFFm+flW95U
 vQBoMMrG5zhLGbXongkby4wNpu7Id2E=; b=PGOkcOEkNQjYQxG6NOskrJJ+GuNm
 y2Up0/0eGAOPiRhVFNJdOVaSygd2BuA6deZdTKrgmKV8VPkN12D4SJPtzaXrbvER
 T+ImL4N7lAq+hQ9611lB27/PALnEEYdFrPwKFHai0pmnhKe+onCH9RM0hrKldIuZ
 thMX+/0izUIelQfQeC1NqCDVDtoAN0rXf7As7TIfb4Xi77R3hx19zmURngVTj890
 AwXdeRzR0yoSIjgXIiU8dUqudzjXplhmc9HWOPFi6aYMkMenhB6/LDoghU0MejZE
 VXZciEWyt4BC34vRW7KOQDxhGtOM4V0+1OWrHxf2wtLAC5+s3LK41hlQ2w==
Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id cbcb3ff2
 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); 
 Mon, 7 Feb 2022 08:46:55 +0000 (UTC)
Date: Mon, 07 Feb 2022 09:46:51 +0100
From: Julien Lepiller <julien@HIDDEN>
User-Agent: K-9 Mail for Android
In-Reply-To: <87k0e713pg.fsf@HIDDEN>
References: <20220206224130.2220aae9@HIDDEN>
 <87k0e713pg.fsf@HIDDEN>
Message-ID: <E7325AF8-C9EE-4A89-9AE5-390CBD49ABAA@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 1.6 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  On February 7, 2022 9:27:39 AM GMT+01:00,
 Xinglu Chen <public@HIDDEN>
 wrote: >Julien schrieb am Sonntag der 06. Februar 2022 um 22:41 +01: > >>
 Hi Guix! >> >> This patch lets you import opam pa [...] 
 Content analysis details:   (1.6 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 -0.0 SPF_PASS               SPF: sender matches SPF record
 1.6 PDS_OTHER_BAD_TLD      Untrustworthy TLDs
 [URI: yoctocell.xyz (xyz)]
 -0.0 T_SCC_BODY_TEXT_LINE   No description available.
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.6 (/)



On February 7, 2022 9:27:39 AM GMT+01:00, Xinglu Chen <public@yoctocell=2E=
xyz> wrote:
>Julien schrieb am Sonntag der 06=2E Februar 2022 um 22:41 +01:
>
>> Hi Guix!
>>
>> This patch lets you import opam packages from a local file=2E This is a
>> feature that was requested a few times, and there it is :)
>>
>> Now, if you have an OCaml package sources that provides an opam file
>> (usually called opam, or with the =2Eopam extension), you can import th=
e
>> package, recursively or not with something like:
>>
>> guix import opam foo -f foo=2Eopam -r
>>
>> instead of fetching foo from the repositories, it will fetch the data
>> directly from the given file=2E WDYT?
>
>Why just limit it to local files?  What about accepting a tarball on the
>internet or any VCS repository?  This could generally be useful for any
>importer=2E

That's a good idea, but I'm not sure how to recognize these cases=2E

>
>Also, since we already know the name of the package, maybe specifying
>the directory that contains the OCaml project would be enough?

Sure, that could be useful for your suggestion below to use the local dire=
ctory as the source=2E

>
>  guix import opam foo --type=3Dlocal /path/to/directory
>  guix import opam foo --type=3Dtarball https://example=2Eorg/foo=2Etar=
=2Egz
>  guix import opam foo --type=3Dgit https://git=2Eexample=2Eorg/foo
>  =E2=80=A6
>
>Or am I asking for too much?  :-)
>
>> From b027391357eef4d6fa1bb8741528cf9650aef568 Mon Sep 17 00:00:00 2001
>> Message-Id: <b027391357eef4d6fa1bb8741528cf9650aef568=2E1644183523=2Egi=
t=2Ejulien@lepiller=2Eeu>
>> From: Julien Lepiller <julien@lepiller=2Eeu>
>> Date: Sun, 6 Feb 2022 22:35:14 +0100
>> Subject: [PATCH] guix: opam: Allow importing local files=2E
>
>It should be =E2=80=9Cimport: opam: =E2=80=A6=E2=80=9D=2E
>
>> * guix/scripts/import/opam=2Escm (guix-import-opam): Support `--file` f=
lag=2E
>> * guix/import/utils=2Escm (recursive-import): Add optional file argumen=
t=2E
>> Pass it to the first iteration when available=2E
>> * guix/import/opam=2Escm (opam-fetch): Fetch from file when available=
=2E
>> (opam->guix-source): Factorize source out of opam->guix-package=2E
>> (opam->guix-package): Add file argument=2E  Ensure it does not fail whe=
n
>> name, version and url are not available=2E
>> ---
>>  guix/import/opam=2Escm         | 101 +++++++++++++++++++--------------=
--
>>  guix/import/utils=2Escm        |  17 +++---
>>  guix/scripts/import/opam=2Escm |  11 +++-
>>  3 files changed, 75 insertions(+), 54 deletions(-)
>>
>> diff --git a/guix/import/opam=2Escm b/guix/import/opam=2Escm
>> index a6f6fe8c9f=2E=2E05f79110f8 100644
>> --- a/guix/import/opam=2Escm
>> +++ b/guix/import/opam=2Escm
>> @@ -310,8 +310,11 @@ (define (dependency-list->inputs lst)
>>    (map string->symbol
>>         (ocaml-names->guix-names lst)))
>> =20
>> -(define* (opam-fetch name #:optional (repositories-specs '("opam")))
>> -  (or (fold (lambda (repository others)
>> +(define* (opam-fetch name #:optional (repositories-specs '("opam")) (f=
ile #f))
>> +  (or (and file (let ((metadata (get-metadata file)))
>> +                  `(("metadata" =2E ,metadata)
>> +                    ("version" =2E #f))))
>> +      (fold (lambda (repository others)
>>                (match (find-latest-version name repository)
>>                  ((_ version file) `(("metadata" ,@(get-metadata file))
>>                                      ("version" =2E ,version)))
>> @@ -320,17 +323,29 @@ (define* (opam-fetch name #:optional (repositorie=
s-specs '("opam")))
>>              (filter-map get-opam-repository repositories-specs))
>>        (warning (G_ "opam: package '~a' not found~%") name)))
>> =20
>> -(define* (opam->guix-package name #:key (repo 'opam) version)
>> +(define (opam->guix-source url-dict)
>> +  (let ((source-url (and url-dict
>> +                         (or (metadata-ref url-dict "src")
>> +                             (metadata-ref url-dict "archive")))))
>> +    (if source-url
>> +        (call-with-temporary-output-file
>> +          (lambda (temp port)
>> +            (and (url-fetch source-url temp)
>> +                 `(origin
>> +                    (method url-fetch)
>> +                    (uri ,source-url)
>> +                    (sha256 (base32 ,(guix-hash-url temp)))))))
>> +        'no-source-information)))
>
>I would use =E2=80=98and-let*=E2=80=99 instead of =E2=80=98let=E2=80=99, =
and drop the =E2=80=98if=E2=80=99 form=2E

That would return #f and make the ocher and-let* in opam->guix-package fai=
l=2E

>
>The ability to import from a local file seems to mostly be useful when
>the package isn=E2=80=99t meant to be submitted to Guix, right?  Wouldn=
=E2=80=99t it
>make more sense to make the source a =E2=80=98local-file=E2=80=99 object =
instead of just
>setting it to #f?

Excellent idea=2E

>
>> +(define* (opam->guix-package name #:key (repo '("opam")) (file #f) ver=
sion)
>>    "Import OPAM package NAME from REPOSITORY (a directory name) or, if
>> -REPOSITORY is #f, from the official OPAM repository=2E  Return a 'pack=
age' sexp
>> +REPOSITORY is #f, from the official OPAM repository=2E  When FILE is d=
efined,
>> +import the packaged defined in the opam FILE instead=2E  Return a 'pac=
kage' sexp
>
>s/packaged/package/
>
>>    (and-let* ((with-opam (if (member "opam" repo) repo (cons "opam" rep=
o)))
>> -             (opam-file (opam-fetch name with-opam))
>> -             (version (assoc-ref opam-file "version"))
>> +             (opam-file (opam-fetch name with-opam file))
>>               (opam-content (assoc-ref opam-file "metadata"))
>> -             (url-dict (metadata-ref opam-content "url"))
>> -             (source-url (or (metadata-ref url-dict "src")
>> -                             (metadata-ref url-dict "archive")))
>> +             (source (opam->guix-source (metadata-ref opam-content "ur=
l")))
>>               (requirements (metadata-ref opam-content "depends"))
>>               (names (dependency-list->names requirements))
>>               (dependencies (filter-dependencies names))
>> @@ -344,47 +359,41 @@ (define* (opam->guix-package name #:key (repo 'op=
am) version)
>>                                    (not (member name '("dune" "jbuilder=
"))))
>>                                  native-dependencies))))
>>          (let ((use-dune? (member "dune" names)))
>> -          (call-with-temporary-output-file
>> -            (lambda (temp port)
>> -              (and (url-fetch source-url temp)
>> -                   (values
>> -                    `(package
>> -                       (name ,(ocaml-name->guix-name name))
>> -                       (version ,version)
>> -                       (source
>> -                         (origin
>> -                           (method url-fetch)
>> -                           (uri ,source-url)
>> -                           (sha256 (base32 ,(guix-hash-url temp)))))
>> -                       (build-system ,(if use-dune?
>> -                                          'dune-build-system
>> -                                          'ocaml-build-system))
>> -                       ,@(if (null? inputs)
>> -                           '()
>> -                           `((propagated-inputs (list ,@inputs))))
>> -                       ,@(if (null? native-inputs)
>> -                           '()
>> -                           `((native-inputs (list ,@native-inputs))))
>> -                       ,@(if (equal? name (guix-name->opam-name (ocaml=
-name->guix-name name)))
>> -                           '()
>> -                           `((properties
>> -                               ,(list 'quasiquote `((upstream-name =2E=
 ,name))))))
>> -                       (home-page ,(metadata-ref opam-content "homepag=
e"))
>> -                       (synopsis ,(metadata-ref opam-content "synopsis=
"))
>> -                       (description ,(beautify-description
>> -                                      (metadata-ref opam-content "desc=
ription")))
>> -                       (license ,(spdx-string->license
>> -                                  (metadata-ref opam-content "license"=
))))
>> -                    (filter
>> -                      (lambda (name)
>> -                        (not (member name '("dune" "jbuilder"))))
>> -                      dependencies))))))))
>> +          (values
>> +           `(package
>> +              (name ,(and name (ocaml-name->guix-name name)))
>> +              (version ,(assoc-ref opam-file "version"))
>> +              (source ,source)
>> +              (build-system ,(if use-dune?
>> +                                 'dune-build-system
>> +                                 'ocaml-build-system))
>> +              ,@(if (null? inputs)
>> +                  '()
>> +                  `((propagated-inputs (list ,@inputs))))
>> +              ,@(if (null? native-inputs)
>> +                  '()
>> +                  `((native-inputs (list ,@native-inputs))))
>> +              ,@(if (and name (equal? name (guix-name->opam-name (ocam=
l-name->guix-name name))))
>> +                  '()
>> +                  `((properties
>> +                      ,(list 'quasiquote `((upstream-name =2E ,name)))=
)))
>> +              (home-page ,(metadata-ref opam-content "homepage"))
>> +              (synopsis ,(metadata-ref opam-content "synopsis"))
>> +              (description ,(beautify-description
>> +                             (metadata-ref opam-content "description")=
))
>> +              (license ,(spdx-string->license
>> +                         (metadata-ref opam-content "license"))))
>> +           (filter
>> +             (lambda (name)
>> +               (not (member name '("dune" "jbuilder"))))
>> +             dependencies)))))
>> =20
>> -(define* (opam-recursive-import package-name #:key repo)
>> +(define* (opam-recursive-import package-name #:key repo file)
>>    (recursive-import package-name
>>                      #:repo->guix-package opam->guix-package
>>                      #:guix-name ocaml-name->guix-name
>> -                    #:repo repo))
>> +                    #:repo repo
>> +                    #:file file))
>> =20
>>  (define (guix-name->opam-name name)
>>    (if (string-prefix? "ocaml-" name)
>> diff --git a/guix/import/utils=2Escm b/guix/import/utils=2Escm
>> index 1c3cfa3e0b=2E=2Eab35b8a4fc 100644
>> --- a/guix/import/utils=2Escm
>> +++ b/guix/import/utils=2Escm
>> @@ -470,7 +470,7 @@ (define (topological-sort nodes
>>                     (set-insert (node-name head) visited))))))))
>> =20
>>  (define* (recursive-import package-name
>> -                           #:key repo->guix-package guix-name version =
repo
>> +                           #:key repo->guix-package guix-name version =
repo file
>>                             #:allow-other-keys)
>>    "Return a list of package expressions for PACKAGE-NAME and all its
>>  dependencies, sorted in topological order=2E  For each package,
>
>The docstrings should also be updated=2E





Last modified: Mon, 7 Feb 2022 09:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.