summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2026-01-21 00:27:21 +0100
committerAndreas Enge <andreas@enge.fr>2026-02-07 12:28:37 +0100
commite9ddab869d19454c939dd94ea71cb6d334d95469 (patch)
treee88d07b02cea6245cc69ac65c8c9d51c4773e9cc
parent5e22e9b3aa26f6e62746c7d8c17c1c2786c11e93 (diff)
build-system/pyproject: Add phase 'set-version.
Rationale: When gradually moving sources to git-fetch, a lot of 'set-version phases have been added within the python packages. To support moving to git source even more, add a 'set-version phase that does this work automatically. * guix/build/pyproject-build-system.scm (set-version): New variable. (%standard-phases): Record 'set-version phase.
-rw-r--r--guix/build/pyproject-build-system.scm36
1 files changed, 36 insertions, 0 deletions
diff --git a/guix/build/pyproject-build-system.scm b/guix/build/pyproject-build-system.scm
index 4230908ac8a..2ba225fd1c5 100644
--- a/guix/build/pyproject-build-system.scm
+++ b/guix/build/pyproject-build-system.scm
@@ -28,6 +28,7 @@
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-2)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
@@ -152,6 +153,40 @@ by Cython."
(format #t "Possible Cythonized file found: ~a~%" generated-file))))
(find-files "." "\\.pyx$")))
+(define* (set-version #:key name inputs #:allow-other-keys)
+ "Set the expect package version environment variable in Semantic Versioning
+format when python-setuptools-scm or python-pbr is present."
+
+ (define (extract-version name)
+ "Extract version from a name-version string."
+ ;; Note: This fails if the package-name contains a dot.
+ (and-let* ((first-dot (or (string-index name #\.)
+ (string-length name)))
+ (prev-hyphen (string-rindex name #\- 0 first-dot)))
+ (substring name (+ prev-hyphen 1))))
+
+ (let ((package (and=> (any (cute assoc <> inputs)
+ (list "python-setuptools-scm"
+ "python-setuptools-scm-bootstrap"
+ "python-pbr"))
+ car)))
+ ;; Both git and hg use -checkout suffixes.
+ (if (and package (string-suffix? "-checkout" (assoc-ref inputs "source")))
+ (and-let* ((version (extract-version name))
+ ;; version here can be semver-revision-commit.
+ (version (first (string-split version #\-))))
+ (match package
+ ((or "python-setuptools-scm" "python-setuptools-scm-bootstrap")
+ (setenv "SETUPTOOLS_SCM_PRETEND_VERSION" version))
+ ("python-pbr"
+ (setenv "PBR_VERSION" version))
+ (_ ;should never happen.
+ #f)))
+ ;; Otherwise, it is probably from a wheel and doesn't require
+ ;; the phase in the first place.
+ (format #t "The source doesn't seem to use version control, \
+python-setuptools-scm is likely unnecessary as a native-input.~%"))))
+
(define* (build #:key outputs build-backend backend-path configure-flags #:allow-other-keys)
"Build a given Python package."
@@ -501,6 +536,7 @@ installed with setuptools."
enable-bytecode-determinism)
(add-after 'enable-bytecode-determinism 'ensure-no-cythonized-files
ensure-no-cythonized-files)
+ (add-after 'ensure-no-cythonized-files 'set-version set-version)
(delete 'bootstrap)
(replace 'set-SOURCE-DATE-EPOCH set-SOURCE-DATE-EPOCH*)
(delete 'configure) ;not needed