* Version from file in a package
@ 2023-09-22 12:20 Reza Housseini
2023-09-22 13:11 ` paul
2023-09-23 12:22 ` Attila Lendvai
0 siblings, 2 replies; 3+ messages in thread
From: Reza Housseini @ 2023-09-22 12:20 UTC (permalink / raw)
To: guix-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 1308 bytes --]
Hi List
Following the excellent blog post from Ludo [1] to guixify my python
project, I wanted to include a version string from file to have a single
source for the guix files and also for the python pyproject.toml file.
Something along this:
(define-public my-package
(let* ((vcs-file? (or (git-predicate %source-dir) (const #t)))
(version-file "VERSION")
(version-from-file (call-with-input-file version-file get-string-all)))
(package
(name "my-package")
(version version-from-file)
(source (local-file "../.." "my-package-checkout"
#:recursive? #t
#:select? vcs-file?))
(build-system pyproject-build-system)
...
this seems to work when I build locally but throws an error when I build
after a guix pull:
(exception system-error (value "open-file") (value "~A: ~S") (value ("No
such file or directory" "VERSION")) (value (2)))
How can I achieve this?
Thanks for your input!
Best,
Reza
[1]
https://guix.gnu.org/en/blog/2023/from-development-environments-to-continuous-integrationthe-ultimate-guide-to-software-development-with-guix/
--
Reza Housseini
This message is signed with my GnuPG key:
C0F3 0812 9AF2 80F4 0830 C2C1 C375 C6AF 0512 5C52
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 15557 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Version from file in a package
2023-09-22 12:20 Version from file in a package Reza Housseini
@ 2023-09-22 13:11 ` paul
2023-09-23 12:22 ` Attila Lendvai
1 sibling, 0 replies; 3+ messages in thread
From: paul @ 2023-09-22 13:11 UTC (permalink / raw)
To: Reza Housseini, guix-devel
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
Hi Reza,
I believe local-file should import (guix utils) and use
current-source-directory. Something like:
(define %cwd (current-source-directory))
(let ([...]
(version-file (string-append %cwd "/VERSION"))
[...]
(source (local-file (string-append %cwd "/../..") "my-package-checkout"
[...]
The current directory may not be where the VERSION file is.
giacomo
[-- Attachment #2: Type: text/html, Size: 596 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Version from file in a package
2023-09-22 12:20 Version from file in a package Reza Housseini
2023-09-22 13:11 ` paul
@ 2023-09-23 12:22 ` Attila Lendvai
1 sibling, 0 replies; 3+ messages in thread
From: Attila Lendvai @ 2023-09-23 12:22 UTC (permalink / raw)
To: Reza Housseini; +Cc: guix-devel
this may be related (also see the discussion):
(current-filename) is #f when guix pull'ing
https://issues.guix.gnu.org/55464
i haven't yet double-checked Ludo's recommendation to use INCLUDE, which should work, but it didn't for me. my current solution is this:
(define (%read-module-relative-file module filename)
(with-input-from-file
(or (search-path %load-path
(string-append (dirname (module-filename module))
"/" filename))
(error "%read-module-relative-file failed for" filename))
(lambda _
(values (read) ; version
(read))))) ; hashes
(define-syntax read-hashes-file
(lambda (syn)
(syntax-case syn ()
((_ filename)
(with-syntax
;; Reads the file at compile time and macroexpands to the first form in it.
((form (call-with-values
(lambda _
(%read-module-relative-file (current-module)
(string-append "hashes/"
(syntax->datum #'filename)
".hashes")))
(lambda (version hashes)
#`(values '#,version '#,hashes)))))
#'form)))))
HTH,
--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Never argue with someone whose TV is bigger than their bookshelf.”
— Emilia Clarke
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-23 12:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 12:20 Version from file in a package Reza Housseini
2023-09-22 13:11 ` paul
2023-09-23 12:22 ` Attila Lendvai
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.