diff mbox series

[bug#58020] import/utils: alist->package: Include properties.

Message ID 87mtaqilj6.fsf@localhost
State Accepted
Headers show
Series [bug#58020] import/utils: alist->package: Include properties. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git-branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

itd Sept. 23, 2022, 7:42 a.m. UTC
* guix/import/utils.scm (alist->package): Process properties field in input
data and include it in the generated package.
* tests/import-utils.scm ("alist->package with properties"): New test.
---
Hi,

this patch enables the JSON importer to include package properties in its
output and a test to check that the modified function's result is consumable by
functions that use these properties.
Please consider applying it.  Thanks!

Regards
itd

 guix/import/utils.scm  |  9 +++++++++
 tests/import-utils.scm | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+)


base-commit: 04cad8e29ed85be838921c7fa05f7c5bce94b6d1

Comments

Ludovic Courtès Sept. 29, 2022, 8:31 p.m. UTC | #1
Hi,

itd <itd@net.in.tum.de> skribis:

> * guix/import/utils.scm (alist->package): Process properties field in input
> data and include it in the generated package.
> * tests/import-utils.scm ("alist->package with properties"): New test.

[...]

> +  (define (process-properties properties)
> +    (append-map (match-lambda
> +                  ((key . value)
> +                   (acons (string->symbol key) value '())))
> +                properties))

I applied the patch and simplified this one.

> * guix/import/print.scm (package->code): Quasiquote properties.
> * tests/print.scm (pkg-with-properties, pkg-with-properties-source):
>     New variables.
>     ("package with properties"): New test

Applied, thanks!

Ludo’.
diff mbox series

Patch

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 7e7d116d1d..8ae04e3cfb 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -428,10 +428,19 @@  (define* (alist->package meta #:optional (known-inputs '()))
                   ((key . value)
                    (list (symbol->keyword (string->symbol key)) value)))
                 arguments))
+  (define (process-properties properties)
+    (append-map (match-lambda
+                  ((key . value)
+                   (acons (string->symbol key) value '())))
+                properties))
   (package
     (name (assoc-ref meta "name"))
     (version (assoc-ref meta "version"))
     (source (source-spec->object (assoc-ref meta "source")))
+    (properties
+     (or (and=> (assoc-ref meta "properties")
+                process-properties)
+         '()))
     (build-system
       (lookup-build-system-by-name
        (string->symbol (assoc-ref meta "build-system"))))
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 7c6c782917..c47348fc60 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -203,4 +203,23 @@  (define-module (test-import-utils)
                  ("license" . #f))))
     (package-native-inputs (alist->package meta))))
 
+(test-assert "alist->package with properties"
+  (let* ((meta '(("name" . "hello")
+                 ("version" . "2.10")
+                 ("source" .
+                  ;; Use a 'file://' URI so that we don't cause a download.
+                  ,(string-append "file://"
+                                  (search-path %load-path "guix.scm")))
+                 ("build-system" . "gnu")
+                 ("properties" . (("hidden?" . #t)
+                                  ("upstream-name" . "hello-upstream")))
+                 ("home-page" . "https://gnu.org")
+                 ("synopsis" . "Say hi")
+                 ("description" . "This package says hi.")
+                 ("license" . "GPL-3.0+")))
+         (pkg (alist->package meta)))
+    (and (package? pkg)
+         (equal? (package-upstream-name pkg) "hello-upstream")
+         (hidden-package? pkg))))
+
 (test-end "import-utils")