summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Davis <phdavis1027@gmail.com>2026-03-18 17:40:55 -0400
committerNguyễn Gia Phong <cnx@loang.net>2026-05-26 00:08:11 +0900
commitabbf03a2efb4a8f3863ba5860e25657a557ea743 (patch)
treeae314615e45a03cb0c5de9c35d54c3f40a46c36b
parent5bad9d084c195c46407d123e8e71a316d743445d (diff)
import: gem: Fix null at home-page.
The RubyGems API returns "homepage_uri": null for gems with no homepage. guile-json parses JSON null as the Guile symbol 'null', which passes through into the generated package sexp as (home-page null)—an unbound variable error at evaluation time. * tests/import/gem.scm (test-no-homepage-json): New fixture. ("gem->guix-package, bald homepage_uri"): New test. * guix/import/gem.scm (non-empty-string-or-false): New procedure. (<gem>)[home-page]: Use it. * guix/import/utils.scm (non-empty-string-or-false): New exported procedure, moved to here... * guix/import/gem.scm (non-empty-string-or-false): ...from here... * guix/import/pypi.scm (non-empty-string-or-false): ...and here. Change-Id: If8f2ca32834d762c753797067ef87937503ff9f9 Reviewed-by: Carlo Zancanaro <carlo@zancanaro.id.au> Signed-off-by: Nguyễn Gia Phong <cnx@loang.net>
-rw-r--r--guix/import/gem.scm3
-rw-r--r--guix/import/pypi.scm6
-rw-r--r--guix/import/utils.scm7
-rw-r--r--tests/import/gem.scm40
4 files changed, 49 insertions, 7 deletions
diff --git a/guix/import/gem.scm b/guix/import/gem.scm
index 6acea107171..d7a61788462 100644
--- a/guix/import/gem.scm
+++ b/guix/import/gem.scm
@@ -63,7 +63,8 @@
63 (info gem-info) 63 (info gem-info)
64 (sha256 gem-sha256 "sha" ;bytevector 64 (sha256 gem-sha256 "sha" ;bytevector
65 base16-string->bytevector) 65 base16-string->bytevector)
66 (home-page gem-home-page "homepage_uri") ;string 66 (home-page gem-home-page "homepage_uri" ;string | #f
67 non-empty-string-or-false)
67 (dependencies gem-dependencies "dependencies" ;<gem-dependencies> 68 (dependencies gem-dependencies "dependencies" ;<gem-dependencies>
68 json->gem-dependencies)) 69 json->gem-dependencies))
69 70
diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm
index cb3b90368c0..419662ec87d 100644
--- a/guix/import/pypi.scm
+++ b/guix/import/pypi.scm
@@ -98,12 +98,6 @@
98 "pytest-isort" "pytest-flake8" "pytest-cov" "pytest-black" ; variants 98 "pytest-isort" "pytest-flake8" "pytest-cov" "pytest-black" ; variants
99 "pytest-pep8" "pytest-mypy" "pytest-pep8" "pre-commit")) ; 99 "pytest-pep8" "pytest-mypy" "pytest-pep8" "pre-commit")) ;
100 100
101(define non-empty-string-or-false
102 (match-lambda
103 ("" #f)
104 ((? string? str) str)
105 ((or 'null #f) #f)))
106
107;; PyPI project. 101;; PyPI project.
108(define-json-mapping <pypi-project> make-pypi-project pypi-project? 102(define-json-mapping <pypi-project> make-pypi-project pypi-project?
109 json->pypi-project 103 json->pypi-project
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index c435981ca99..a9ff90f0ee1 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -97,6 +97,7 @@
97 spdx-string->license 97 spdx-string->license
98 license->symbol 98 license->symbol
99 99
100 non-empty-string-or-false
100 snake-case 101 snake-case
101 beautify-description 102 beautify-description
102 beautify-synopsis 103 beautify-synopsis
@@ -470,6 +471,12 @@ object is bound to in the (guix licenses) module, such as 'license:gpl3+, or
470 (resolve-interface '(guix licenses) #:prefix 'license:))) 471 (resolve-interface '(guix licenses) #:prefix 'license:)))
471 (assoc-ref licenses license)) 472 (assoc-ref licenses license))
472 473
474(define non-empty-string-or-false
475 (match-lambda
476 ("" #f)
477 ((? string? str) str)
478 ((or 'null #f) #f)))
479
473(define (snake-case str) 480(define (snake-case str)
474 "Return a downcased version of the string STR where underscores and periods 481 "Return a downcased version of the string STR where underscores and periods
475are replaced with dashes." 482are replaced with dashes."
diff --git a/tests/import/gem.scm b/tests/import/gem.scm
index beee1508756..dfa33d40366 100644
--- a/tests/import/gem.scm
+++ b/tests/import/gem.scm
@@ -112,6 +112,19 @@
112 \"licenses\": [\"MIT\"] 112 \"licenses\": [\"MIT\"]
113}") 113}")
114 114
115(define test-no-homepage-json
116 "{
117 \"name\": \"no-homepage\",
118 \"version\": \"1.0.0\",
119 \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\",
120 \"info\": \"A gem with no homepage\",
121 \"homepage_uri\": null,
122 \"dependencies\": {
123 \"runtime\": []
124 },
125 \"licenses\": [\"MIT\"]
126}")
127
115(test-begin "gem") 128(test-begin "gem")
116 129
117(test-assert "gem->guix-package" 130(test-assert "gem->guix-package"
@@ -306,4 +319,31 @@
306 (list (upstream-source-urls source) 319 (list (upstream-source-urls source)
307 (upstream-source-inputs source))))) 320 (upstream-source-inputs source)))))
308 321
322(test-assert "gem->guix-package, bald homepage_uri"
323 (mock ((guix http-client) http-fetch
324 (lambda (url . rest)
325 (match url
326 ("https://rubygems.org/api/v1/gems/no-homepage.json"
327 (values (open-input-string test-no-homepage-json)
328 (string-length test-no-homepage-json)))
329 (_ (error "Unexpected URL: " url)))))
330 (match (gem->guix-package "no-homepage")
331 (`(package
332 (name "ruby-no-homepage")
333 (version "1.0.0")
334 (source (origin
335 (method url-fetch)
336 (uri (rubygems-uri "no-homepage" version))
337 (sha256
338 (base32
339 "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk"))))
340 (build-system ruby-build-system)
341 (synopsis "A gem with no homepage")
342 (description "This package provides a gem with no homepage.")
343 (home-page #f)
344 (license license:expat))
345 #t)
346 (x
347 (pk 'fail x #f)))))
348
309(test-end "gem") 349(test-end "gem")